Search in sources :

Example 6 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class DefaultPropertyNameMatcherTest method testFullMatchCaseSensitive.

@Test
public void testFullMatchCaseSensitive() {
    PropertyNameMatcher matcher = new DefaultPropertyNameMatcher("my_col", 0, false, true);
    assertTrue(matcher.matches("myCol"));
    assertFalse(matcher.matches("mycol"));
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) PropertyNameMatcher(org.simpleflatmapper.reflect.meta.PropertyNameMatcher) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Test(org.junit.Test)

Example 7 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class JoolTupleTest method testMetaDataOnJoolTuple.

@Test
public void testMetaDataOnJoolTuple() throws Exception {
    // creates a new tuple allocated on the JVM heap
    System.out.println("super " + Tuple3.class.toString());
    for (Class<?> clazz : Tuple3.class.getInterfaces()) {
        System.out.println("I " + clazz.toString());
    }
    ClassMeta<Tuple3<Long, Integer, Short>> cm = ReflectionService.newInstance().getClassMeta(new TypeReference<Tuple3<Long, Integer, Short>>() {
    }.getType());
    final PropertyFinder<Tuple3<Long, Integer, Short>> propertyFinder = cm.newPropertyFinder(isValidPropertyMeta);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt2", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt3", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    Tuple3<Long, Integer, Short> tuple = new Tuple3<Long, Integer, Short>(6l, 7, (short) 3);
    assertTrue(fieldA instanceof ConstructorPropertyMeta);
    assertTrue(fieldB instanceof ConstructorPropertyMeta);
    assertTrue(fieldC instanceof ConstructorPropertyMeta);
    Assert.assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    Assert.assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    Assert.assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Tuple3(org.jooq.lambda.tuple.Tuple3) TypeReference(org.simpleflatmapper.util.TypeReference) ConstructorPropertyMeta(org.simpleflatmapper.reflect.meta.ConstructorPropertyMeta) Test(org.junit.Test)

Example 8 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceMapperBuilderTest method testIssue495.

@Test
public void testIssue495() throws Exception {
    TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> typeReference = new TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>>() {
    };
    ClassMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
    Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {

        @Override
        public boolean test(PropertyMeta<?, ?> propertyMeta) {
            return true;
        }
    };
    PropertyFinder<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
    PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
    PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
    System.out.println("p1.getPath() = " + p1.getPath());
    System.out.println("p2.getPath() = " + p2.getPath());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Predicate(org.simpleflatmapper.util.Predicate) Tuple2(org.simpleflatmapper.tuple.Tuple2) Tuple3(org.simpleflatmapper.tuple.Tuple3) List(java.util.List) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 9 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class FastTupleTest method testMetaDataOnFastTuple.

@Test
public void testMetaDataOnFastTuple() throws Exception {
    // creates a new tuple allocated on the JVM heap
    @SuppressWarnings("unchecked") ClassMeta<FastTuple> cm = ReflectionService.newInstance().getClassMeta((Class<FastTuple>) tuple.getClass());
    final PropertyFinder<FastTuple> propertyFinder = cm.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    final PropertyMeta<FastTuple, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldA", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldB", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldC", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldD", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    fieldA.getSetter().set(tuple, 6l);
    assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    fieldB.getSetter().set(tuple, 7);
    assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    fieldC.getSetter().set(tuple, (short) 3);
    assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : FastTuple(com.boundary.tuple.FastTuple) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Test(org.junit.Test)

Example 10 with DefaultPropertyNameMatcher

use of org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher in project SimpleFlatMapper by arnaudroger.

the class FastTupleTest method testMetaDataOnFastTupleDirectMemory.

@Test
public void testMetaDataOnFastTupleDirectMemory() throws Exception {
    final TupleSchema tupleSchema = TupleSchema.builder().addField("fieldA", Long.TYPE).addField("fieldB", Integer.TYPE).addField("fieldC", Short.TYPE).directMemory().build();
    final FastTuple tuple = tupleSchema.createTuple();
    // creates a new tuple allocated on the JVM heap
    @SuppressWarnings("unchecked") ClassMeta<FastTuple> cm = ReflectionService.newInstance().getClassMeta((Class<FastTuple>) tuple.getClass());
    final PropertyFinder<FastTuple> propertyFinder = cm.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
    final PropertyMeta<FastTuple, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldA", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldB", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldC", 0, true, true), new Object[0]);
    final PropertyMeta<FastTuple, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("fieldD", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    fieldA.getSetter().set(tuple, 6l);
    assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    fieldB.getSetter().set(tuple, 7);
    assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    fieldC.getSetter().set(tuple, (short) 3);
    assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) TupleSchema(com.boundary.tuple.TupleSchema) FastTuple(com.boundary.tuple.FastTuple) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 DefaultPropertyNameMatcher (org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher)16 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)4 PropertyNameMatcher (org.simpleflatmapper.reflect.meta.PropertyNameMatcher)4 Predicate (org.simpleflatmapper.util.Predicate)3 TypeReference (org.simpleflatmapper.util.TypeReference)3 FastTuple (com.boundary.tuple.FastTuple)2 List (java.util.List)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2 Tuple3 (org.simpleflatmapper.tuple.Tuple3)2 TupleSchema (com.boundary.tuple.TupleSchema)1 ResultSet (java.sql.ResultSet)1 Tuple3 (org.jooq.lambda.tuple.Tuple3)1 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)1 LongFieldMapper (org.simpleflatmapper.map.fieldmapper.LongFieldMapper)1 PropertyMapping (org.simpleflatmapper.map.mapper.PropertyMapping)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1 IdentityGetter (org.simpleflatmapper.reflect.getter.IdentityGetter)1 ConstructorPropertyMeta (org.simpleflatmapper.reflect.meta.ConstructorPropertyMeta)1 SelfPropertyMeta (org.simpleflatmapper.reflect.meta.SelfPropertyMeta)1