ObjectStoreSummary { public Properties toProperties() { Properties properties = new Properties(); properties.put(MAX_FIELD_VALUES, "" + maxValues); for (Map.Entry<String, Integer> entry: classCountsMap.entrySet()) { String key = entry.getKey(); Integer value = entry.getValue(); properties.put(key + CLASS_COUNTS_SUFFIX, value.toString()); } for (Map.Entry<String, List<Object>> entry: fieldValuesMap.entrySet()) { String key = entry.getKey(); List<Object> value = entry.getValue(); StringBuffer sb = new StringBuffer(); for (Iterator<Object> j = value.iterator(); j.hasNext();) { String s = (String) j.next(); if (s == null) { sb.append(NULL_MARKER); } else { sb.append(s); } if (j.hasNext()) { sb.append(FIELD_DELIM); } } properties.put(key + FIELDS_SUFFIX, sb.toString()); } writeEmptyMapToProperties(properties, NULL_FIELDS_SUFFIX, emptyFieldsMap); writeEmptyMapToProperties(properties, EMPTY_ATTRIBUTES_SUFFIX, emptyAttributesMap); return properties; } ObjectStoreSummary(ObjectStore os, Properties configuration);  ObjectStoreSummary(Properties properties); int getMaxValues(); int getClassCount(String className); List<Object> getFieldValues(String className, String fieldName); Set<String> getNullReferencesAndCollections(String className); Map<String, Set<String>> getAllNullReferencesAndCollections(); Set<String> getNullAttributes(String className); Map<String, Set<String>> getAllNullAttributes(); Properties toProperties(); static final int DEFAULT_MAX_VALUES; }
@Test public void testEmptyAttributes() throws Exception { Query q = new Query(); QueryClass qcEmployee = new QueryClass(Employee.class); q.addFrom(qcEmployee); q.addToSelect(qcEmployee); ObjectStore os = ObjectStoreFactory.getObjectStore("os.unittest"); ObjectStoreWriter osw = os.getNewWriter(); SingletonResults res = os.executeSingleton(q); osw.beginTransaction(); for (Object o : res){ Employee employee = (Employee) o; employee.setName(null); osw.store(employee); } osw.commitTransaction(); osw.close(); ObjectStoreSummary oss = new ObjectStoreSummary(os, new Properties()); Map<String, Set<String>> expectedEmptyAttributes = new HashMap<String, Set<String>>(); HashSet<String> nameSet = new HashSet<String>(Arrays.asList(new String[] {"name"})); expectedEmptyAttributes.put(Employee.class.getName(), nameSet); expectedEmptyAttributes.put(Manager.class.getName(), nameSet); expectedEmptyAttributes.put(CEO.class.getName(), nameSet); expectedEmptyAttributes.put(Types.class.getName(), new HashSet<String>(Arrays.asList(new String[] {"clobObjType"}))); Assert.assertEquals(expectedEmptyAttributes, oss.emptyAttributesMap); Properties ossProps = oss.toProperties(); ObjectStoreSummary ossFromProps = new ObjectStoreSummary(ossProps); Assert.assertEquals(expectedEmptyAttributes, ossFromProps.emptyAttributesMap); }
@Test public void testPropertiesRoundTrip() throws Exception { Properties config = new Properties(); config.put("max.field.values", "10"); ObjectStore os = ObjectStoreFactory.getObjectStore("os.unittest"); ObjectStoreSummary oss = new ObjectStoreSummary(os, config); Properties out = oss.toProperties(); ObjectStoreSummary ossFromProps = new ObjectStoreSummary(out); Assert.assertEquals(out, ossFromProps.toProperties()); Assert.assertEquals(10, oss.maxValues); Assert.assertEquals(10, ossFromProps.maxValues); }