public boolean isAnyCollections() { if (null == getAllProperties()) { return false; } for (PropertyMappingDefinition md : getAllProperties()) { if (md.isCollectionType()) { return true; } } return false; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public Collection<PropertyMappingDefinition> getAllProperties() { if (null == allMappedProps) { Set<PropertyMappingDefinition> propSet = new HashSet<PropertyMappingDefinition>(); for (PropertyMappingDefinition propMapDef : propertyCacheByColName.values()) { propSet.add(propMapDef); } if (null == cfSuperMapDef) { allMappedProps = propSet; } else { allMappedProps = Sets.union(propSet, (Set) cfSuperMapDef.getAllProperties()); } } return allMappedProps; }
public Collection<PropertyMappingDefinition> getCollectionProperties() { Set<PropertyMappingDefinition> collSet = new HashSet<PropertyMappingDefinition>(); for (PropertyMappingDefinition md : getAllProperties()) { if (md.isCollectionType()) { collSet.add(md); } } return collSet; }
private void generateColumnSliceIfNeeded(CFMappingDef<?> cfMapDef) { if (cfMapDef.isColumnSliceRequired()) { Collection<PropertyMappingDefinition> propColl = cfMapDef.getAllProperties(); String[] columnNames = new String[cfMapDef.isPersistableEntity() ? propColl.size() : propColl.size() + 1]; Iterator<PropertyMappingDefinition> iter = propColl.iterator(); int pos = 0; while (iter.hasNext()) { columnNames[pos++] = iter.next().getColName(); } // if an inheritance hierarchy exists we need to add in the discriminator // column if (!cfMapDef.isPersistableEntity()) { columnNames[pos] = cfMapDef.getDiscColumn(); } cfMapDef.setSliceColumnNameArr(columnNames); } }
try { Map<String, HColumn<String, byte[]>> colSet = new HashMap<String, HColumn<String, byte[]>>(); Collection<PropertyMappingDefinition> coll = cfMapDef.getAllProperties(); for (PropertyMappingDefinition md : coll) { Collection<HColumn<String, byte[]>> colColl = createColumnsFromProperty(obj, md);
@Test public void testInheritanceOfNonEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyPurpleTestBean> cfMapDef = cacheMgr.initializeCacheForClass(MyPurpleTestBean.class); assertEquals(2, cfMapDef.getAllProperties().size()); assertNull(cfMapDef.getCfBaseMapDef()); assertEquals(MyPurpleTestBean.class, cfMapDef.getEffectiveClass()); }
@Test public void testCustomConvertedCollectionIsOneColumn() { MyConvertedCollectionBean b1 = new MyConvertedCollectionBean(); int first = 111; int second = 0; int third = -1; b1.addToList(first).addToList(second).addToList(third); Map<String, HColumn<String, byte[]>> colMap = new HectorObjectMapper(cacheMgr).createColumnMap(b1); CFMappingDef<MyConvertedCollectionBean> cfMapping = cacheMgr.getCfMapDef( MyConvertedCollectionBean.class, false); assertEquals( "collections with custom converters should be skipped by default collection mapping", colMap.size(), cfMapping.getAllProperties().size()); }
@Test public void testInheritanceWithMultiLevels() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<Desk> cfMapDef = cacheMgr.initializeCacheForClass(Desk.class); CFMappingDef<Furniture> cfBaseMapDef = cacheMgr.getCfMapDef(Furniture.class, true); assertEquals(7, cfMapDef.getAllProperties().size()); assertNotNull(cfMapDef.getCfSuperMapDef()); assertNotNull(cfMapDef.getCfBaseMapDef()); assertEquals(Desk.class.getSuperclass(), cfMapDef.getCfSuperMapDef().getEffectiveClass()); assertEquals(Desk.class.getSuperclass().getSuperclass(), cfMapDef.getCfSuperMapDef() .getCfSuperMapDef() .getEffectiveClass()); assertEquals(cfBaseMapDef.getEffectiveColFamName(), cfMapDef.getEffectiveColFamName()); assertEquals("type", cfMapDef.getDiscColumn()); assertEquals("table_desk", cfMapDef.getDiscValue()); assertEquals(DiscriminatorType.STRING, cfMapDef.getDiscType()); assertEquals("id", cfMapDef.getKeyDef().getIdPropertyMap().values().iterator().next() .getPropDesc().getName()); }
@Test public void testInheritanceOfEntity() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<MyRedTestBean> cfMapDef = cacheMgr.initializeCacheForClass(MyRedTestBean.class); // 13 is valid when custom conversion of enumerations works again // don't like hard coding numbers into JUnits, but took easy way for now assertEquals(14, cfMapDef.getAllProperties().size()); assertNotNull(cfMapDef.getCfBaseMapDef()); assertEquals(MyRedTestBean.class, cfMapDef.getEffectiveClass()); assertEquals("TestBeanColumnFamily", cfMapDef.getEffectiveColFamName()); assertEquals("myType", cfMapDef.getDiscColumn()); assertEquals(DiscriminatorType.STRING, cfMapDef.getDiscType()); assertEquals("baseId", cfMapDef.getKeyDef().getIdPropertyMap().values().iterator().next() .getPropDesc().getName()); // check super class settings assertEquals( MyRedTestBean.class.getSuperclass(), cfMapDef.getCfSuperMapDef().getRealClass()); assertFalse( cfMapDef.getCfSuperMapDef().isColumnSliceRequired()); }