private <T> void setIdIfCan(CFMappingDef<T> cfMapDef, T obj, Object pkObj) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { if (cfMapDef.getKeyDef().isComplexKey()) { setComplexId(cfMapDef, obj, pkObj); } else { setSimpleId(cfMapDef, obj, pkObj); } }
public boolean isAnyCollections() { if (null == getAllProperties()) { return false; } for (PropertyMappingDefinition md : getAllProperties()) { if (md.isCollectionType()) { return true; } } return false; }
public KeyDefinition getKeyDef() { if (null == cfBaseMapDef) { return keyDef; } else { return cfBaseMapDef.getKeyDef(); } }
@Test public void testCollectionWithCustomConverterPropertyHandling() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<CustomConvertedCollectionBean> cfMapDef = cacheMgr.initializeCacheForClass(CustomConvertedCollectionBean.class); PropertyMappingDefinition md = cfMapDef.getPropMapByPropName("mySet"); assertEquals( null, md.getCollectionType() ); assertEquals( "mySet", md.getColName()); assertNotNull( "should be using slice query with custom converted collection", cfMapDef.getSliceColumnNameArr()); } }
private byte[] generateColumnFamilyKeyFromPojo(Object obj, CFMappingDef<?> cfMapDef) { List<byte[]> segmentList = new ArrayList<byte[]>(cfMapDef.getKeyDef().getIdPropertyMap().size()); for (PropertyMappingDefinition md : cfMapDef.getKeyDef().getIdPropertyMap().values()) { Method meth = md.getPropDesc().getReadMethod(); segmentList.add(callMethodAndConvertToCassandraType(obj, meth, md.getConverter())); } return keyConcatStrategy.concat(segmentList); }
@Override public EntityManagerFactory createEntityManagerFactory(final String emName, final Map map) { final Keyspace keyspace = keyspace((String) map.get(HOST_PROP), (String) map.get(CLUSTER_PROP), (String) map.get(KEYSPACE_PROP), (String) map.get(CONSISTENCY_PROP)); final AnnotationScanner scanner = createScanner(value(SCANNER, map, null)); return new EntityManagerFactoryImpl(new LightPersistenceUnitInfo((String) map.get(PACKAGES_TO_SCAN)), keyspace, scanner); }
public EntityManagerImpl(Keyspace keyspace, String[] classpathPrefix, ClassCacheMgr cacheMgr, HectorObjectMapper objMapper, AnnotationScanner scanner) { this.keyspace = keyspace; if (null != cacheMgr) { this.cacheMgr = cacheMgr; } else { this.cacheMgr = new ClassCacheMgr(); } if (null != objMapper) { this.objMapper = objMapper; } else { this.objMapper = new HectorObjectMapper(this.cacheMgr); } initialize(scanner, classpathPrefix); }
private byte[] createBytesFromPropertyValue(Object obj, PropertyMappingDefinition md) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Object retVal = reflectionHelper.invokeGetter(obj, md); // if no value, then signal with null bytes if (null == retVal) { return null; } @SuppressWarnings("unchecked") byte[] bytes = md.getConverter().convertObjTypeToCassType(retVal); return bytes; }
private <T> void processColumnAnnotation(Field f, Column anno, PropertyDescriptor pd, CFMappingDef<T> cfMapDef) throws InstantiationException, IllegalAccessException { PropertyMappingDefinition md = new PropertyMappingDefinition(pd, anno.name(), DefaultConverter.class); cfMapDef.addPropertyDefinition(md); }
public String getDiscColumn() { if (null == cfBaseMapDef) { return discColumn; } else { return cfBaseMapDef.getDiscColumn(); } }
/** * Determines if the key is complex (IdClass, Embedded, etc) or a simple one field type. * * @return true if complex, false otherwise */ public boolean isComplexKey() { return null != getPkClazz(); }
public EntityManagerImpl(Keyspace keyspace, EntityManagerFactory emf, Class<?>... classes) { this(keyspace, null, null, null); for (Class<?> clazz : classes) { cacheMgr.initializeCacheForClass(clazz); } this.emf = emf; }
public DiscriminatorType getDiscType() { if (null == cfBaseMapDef) { return discType; } else { return cfBaseMapDef.getDiscType(); } }
public Method getAnonymousPropertyGetHandler() { if (null != anonymousPropertyGetHandler) { return anonymousPropertyGetHandler; } else if (null != cfSuperMapDef) { return cfSuperMapDef.getAnonymousPropertyGetHandler(); } else { return null; } }
public Method getAnonymousPropertyAddHandler() { if (null != anonymousPropertyAddHandler) { return anonymousPropertyAddHandler; } else if (null != cfSuperMapDef) { return cfSuperMapDef.getAnonymousPropertyAddHandler(); } else { return null; } }
public Class<?> getAnonymousValueType() { if (null != anonymousValueType) { return anonymousValueType; } else if (null != cfSuperMapDef) { return cfSuperMapDef.getAnonymousValueType(); } else { return null; } }
@SuppressWarnings("rawtypes") public Serializer getAnonymousValueSerializer() { if (null != anonymousValueSerializer) { return anonymousValueSerializer; } else if (null != cfSuperMapDef) { return cfSuperMapDef.getAnonymousValueSerializer(); } else { return null; } }
@Override public void refresh(Object entity, LockModeType lockMode) { refresh(entity); }
@Test public void testCollectionPropertyHandling() { ClassCacheMgr cacheMgr = new ClassCacheMgr(); CFMappingDef<CollectionBean> cfMapDef = cacheMgr.initializeCacheForClass(CollectionBean.class); PropertyMappingDefinition md = cfMapDef.getPropMapByPropName("mySet"); assertEquals( Set.class, md.getCollectionType() ); assertEquals( "mySet", md.getColName()); assertNull( "should not be using slice query with List collection", cfMapDef.getSliceColumnNameArr()); }
@Override public EntityManagerFactory createContainerEntityManagerFactory(final PersistenceUnitInfo info, final Map map) { final String keyspaceName = value(KEYSPACE_PROP, map, info.getProperties()); final String host = value(HOST_PROP, map, info.getProperties()); final String clusterName = value(CLUSTER_PROP, map, info.getProperties()); final String consistency = value(CONSISTENCY_PROP, map, info.getProperties()); final Keyspace keyspace = keyspace(host, clusterName, keyspaceName, consistency); final AnnotationScanner scanner = createScanner(value(SCANNER, map, info.getProperties())); return new EntityManagerFactoryImpl(info, keyspace, scanner); }