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); }
private <T> void processIdAnnotation(Field f, Id anno, CFMappingDef<T> cfMapDef, Map<String, PropertyDescriptor> pdMap) throws InstantiationException, IllegalAccessException { // TODO lookup JPA 2 spec for class-level ids PropertyMappingDefinition md = new PropertyMappingDefinition(pdMap.get(f.getName()), null, DefaultConverter.class); if (null == md.getPropDesc() || null == md.getPropDesc().getReadMethod() || null == md.getPropDesc().getWriteMethod()) { throw new HectorObjectMapperException("@" + Id.class.getSimpleName() + " is defined on property, " + f.getName() + ", but its missing proper setter/getter"); } cfMapDef.getKeyDef().addIdPropertyMap(md); }
private <T> void processIdCustomAnnotation(Field f, me.prettyprint.hom.annotations.Id anno, CFMappingDef<T> cfMapDef, Map<String, PropertyDescriptor> pdMap) throws InstantiationException, IllegalAccessException { // TODO lookup JPA 2 spec for class-level ids PropertyMappingDefinition md = new PropertyMappingDefinition(pdMap.get(f.getName()), null, anno.converter()); if (null == md.getPropDesc() || null == md.getPropDesc().getReadMethod() || null == md.getPropDesc().getWriteMethod()) { throw new HectorObjectMapperException("@" + Id.class.getSimpleName() + " is defined on property, " + f.getName() + ", but its missing proper setter/getter"); } cfMapDef.getKeyDef().addIdPropertyMap(md); }
private void processColumnCustomAnnotation(Field f, me.prettyprint.hom.annotations.Column anno, PropertyDescriptor pd, CFMappingDef<?> cfMapDef) throws InstantiationException, IllegalAccessException { PropertyMappingDefinition md = new PropertyMappingDefinition(pd, anno.name(), anno.converter()); // if collection type and default converter then make note of collection type for later use Class<?> type = pd.getPropertyType(); if (Collection.class.isAssignableFrom(type) && md.isDefaultConverter()) { md.setCollectionType(type); } cfMapDef.addPropertyDefinition(md); } }
@Test(expected=HectorObjectMapperException.class) public void testStringFromCassNotWork() throws Exception { conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("str1", TestClass.class), "foo", VariableIntegerConverter.class), new String("123").getBytes()); }
@Test(expected=HectorObjectMapperException.class) public void testStringToCassNotWork() throws Exception { byte[] ba; String s1 = new String("123"); ba = conv.convertObjTypeToCassType(s1); assertEquals(s1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("str1", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }
@Test public void testByte() throws Exception { byte[] ba; byte b1 = 123; ba = conv.convertObjTypeToCassType(b1); assertEquals(b1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("b1", TestClass.class), "foo", VariableIntegerConverter.class), ba)); Byte b2 = 1; ba = conv.convertObjTypeToCassType(b2); assertEquals(b2, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("b2", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }
@Test public void testShort() throws Exception { byte[] ba; short s1 = 123; ba = conv.convertObjTypeToCassType(s1); assertEquals(s1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("s1", TestClass.class), "foo", VariableIntegerConverter.class), ba)); Short s2 = 1; ba = conv.convertObjTypeToCassType(s2); assertEquals(s2, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("s2", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }
@Test public void testInteger() throws Exception { byte[] ba; int i1 = 123; ba = conv.convertObjTypeToCassType(i1); assertEquals(i1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("i1", TestClass.class), "foo", VariableIntegerConverter.class), ba)); Integer i2 = 1; ba = conv.convertObjTypeToCassType(i2); assertEquals(i2, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("i2", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }
@Test public void testBigInteger() throws Exception { byte[] ba; BigInteger b1 = BigInteger.valueOf(123); ba = conv.convertObjTypeToCassType(b1); assertEquals(b1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("bigInt", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }
@Test public void testLong() throws Exception { byte[] ba; long l1 = 123; ba = conv.convertObjTypeToCassType(l1); assertEquals(l1, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("l1", TestClass.class), "foo", VariableIntegerConverter.class), ba)); Long l2 = 1L; ba = conv.convertObjTypeToCassType(l2); assertEquals(l2, conv.convertCassTypeToObjType(new PropertyMappingDefinition( new PropertyDescriptor("l2", TestClass.class), "foo", VariableIntegerConverter.class), ba)); }