Search in sources :

Example 1 with DefaultPropertyNameMatcher

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

the class ConstantSourceMapperBuilderTest method testIssue495Simple.

@Test
public void testIssue495Simple() throws Exception {
    TypeReference<List<Tuple3<Foo, Foo, Foo>>> typeReference = new TypeReference<List<Tuple3<Foo, Foo, Foo>>>() {
    };
    ClassMeta<List<Tuple3<Foo, Foo, Foo>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
    Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {

        @Override
        public boolean test(PropertyMeta<?, ?> propertyMeta) {
            return true;
        }
    };
    PropertyFinder<?> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
    PropertyMeta<?, ?> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
    PropertyMeta<?, ?> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
    assertEquals("[0].element0.bar", p1.getPath());
    assertEquals("[0].element1.bar", p2.getPath());
    propertyFinder = classMeta.newPropertyFinder(propertyFilter);
    p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0_elt0_bar", 0, false, false), new Object[0]);
    p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1_elt0_bar", 0, false, false), new Object[0]);
    assertEquals("[0].element0.bar", p1.getPath());
    assertEquals("[1].element0.bar", p2.getPath());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Predicate(org.simpleflatmapper.util.Predicate) 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 2 with DefaultPropertyNameMatcher

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

the class ResultSetFieldMapperFactoryTest method testPrimitiveField.

@Test
public void testPrimitiveField() {
    ClassMeta<DbObject> classMeta = ReflectionService.newInstance(false).getClassMeta(DbObject.class);
    PropertyMeta<DbObject, Long> id = classMeta.newPropertyFinder(ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).<Long>findProperty(new DefaultPropertyNameMatcher("id", 0, false, false), new Object[0]);
    FieldMapperColumnDefinition<JdbcColumnKey> identity = FieldMapperColumnDefinition.identity();
    PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 1), identity);
    FieldMapper<ResultSet, DbObject> fieldMapper = factory.newFieldMapper(propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE);
    assertTrue(fieldMapper instanceof LongFieldMapper);
    PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>> propertyMapping1 = new PropertyMapping<DbObject, Long, JdbcColumnKey, FieldMapperColumnDefinition<JdbcColumnKey>>(id, new JdbcColumnKey("id", 0), identity);
    fieldMapper = factory.newFieldMapper(propertyMapping1, null, RethrowMapperBuilderErrorHandler.INSTANCE);
    assertTrue(fieldMapper instanceof LongFieldMapper);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) LongFieldMapper(org.simpleflatmapper.map.fieldmapper.LongFieldMapper) DbObject(org.simpleflatmapper.test.beans.DbObject) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) JdbcColumnKey(org.simpleflatmapper.jdbc.JdbcColumnKey) PropertyMapping(org.simpleflatmapper.map.mapper.PropertyMapping) ResultSet(java.sql.ResultSet) PropertyMeta(org.simpleflatmapper.reflect.meta.PropertyMeta) Test(org.junit.Test)

Example 3 with DefaultPropertyNameMatcher

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

the class ConstructorPropertyMetaTest method testToString.

@Test
public void testToString() {
    PropertyMeta<CObject, Object> property = classMeta.newPropertyFinder(isValidPropertyMeta).findProperty(new DefaultPropertyNameMatcher("p1", 0, false, false), new Object[0]);
    assertTrue(property.toString().startsWith("ConstructorPropertyMeta"));
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Test(org.junit.Test)

Example 4 with DefaultPropertyNameMatcher

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

the class ConstructorPropertyMetaTest method testGetValueIfGetterAvailable.

@Test
public void testGetValueIfGetterAvailable() throws Exception {
    PropertyMeta<CObject, Object> property = classMeta.newPropertyFinder(isValidPropertyMeta).findProperty(new DefaultPropertyNameMatcher("p1", 0, false, false), new Object[0]);
    assertEquals("v1", property.getGetter().get(cObject));
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Test(org.junit.Test)

Example 5 with DefaultPropertyNameMatcher

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

the class DefaultPropertyNameMatcherTest method testStartOf.

@Test
public void testStartOf() {
    PropertyNameMatcher matcher = new DefaultPropertyNameMatcher("my_Col_top_bottom", 0, false, false);
    assertTrue(matcher.partialMatch("myCol").getLeftOverMatcher().partialMatch("top").getLeftOverMatcher().matches("bottom"));
    assertTrue(matcher.partialMatch("my_Col").getLeftOverMatcher().partialMatch("tOp").getLeftOverMatcher().matches("bottom"));
    assertTrue(matcher.partialMatch("my Col").getLeftOverMatcher().partialMatch("tOp").getLeftOverMatcher().matches("bottom"));
    assertNull(matcher.partialMatch("my__Col"));
    assertNull(matcher.partialMatch("myCol2"));
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) PropertyNameMatcher(org.simpleflatmapper.reflect.meta.PropertyNameMatcher) DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) 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