Search in sources :

Example 1 with ReflectionService

use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.

the class AbstractMapperFactoryTest method testAsmSettings.

@Test
public void testAsmSettings() {
    ReflectionService reflectionService = new MapperFactory().useAsm(false).getReflectionService();
    assertFalse(reflectionService.isAsmActivated());
    MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = new MapperFactory().asmMapperNbFieldsLimit(33).failOnAsm(true).maxMethodSize(13).mapperConfig();
    assertEquals(33, mapperConfig.asmMapperNbFieldsLimit());
    assertEquals(13, mapperConfig.maxMethodSize());
    assertEquals(true, mapperConfig.failOnAsm());
    reflectionService = new ReflectionService(null);
    assertSame(reflectionService, new MapperFactory().reflectionService(reflectionService).getReflectionService());
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) AbstractMapperFactory(org.simpleflatmapper.map.mapper.AbstractMapperFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) ReflectionService(org.simpleflatmapper.reflect.ReflectionService) Test(org.junit.Test)

Example 2 with ReflectionService

use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.

the class ReflectionServiceTest method testSelfReferringClass.

@Test
public void testSelfReferringClass() {
    final ReflectionService reflectionService = ReflectionService.newInstance();
    ClassMeta<Node> cm = reflectionService.getClassMeta(Node.class);
    final PropertyMeta<Node, Object> propertyMeta = cm.newPropertyFinder(isValidPropertyMeta).findProperty(DefaultPropertyNameMatcher.of("parent_parent_parent"), new Object[0]);
    assertNotNull(propertyMeta);
    assertNotNull(cm);
}
Also used : DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) ReflectionService(org.simpleflatmapper.reflect.ReflectionService) Test(org.junit.Test)

Example 3 with ReflectionService

use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.

the class ObjectClassMetaTest method testAliasProvider.

@Test
public void testAliasProvider() {
    ReflectionService reflectionService = ReflectionService.newInstance().withAliasProvider(new AliasProvider() {

        @Override
        public String getAliasForMethod(Method method) {
            if ("getName".equals(method.getName())) {
                return "myname";
            }
            return null;
        }

        @Override
        public String getAliasForField(Field field) {
            if ("id".equals(field.getName())) {
                return "myid";
            }
            return null;
        }

        @Override
        public Table getTable(Class<?> target) {
            return null;
        }
    });
    ClassMeta<DbObject> classMeta = reflectionService.getClassMeta(DbObject.class);
    PropertyFinder<DbObject> propertyFinder1 = classMeta.newPropertyFinder(propertyFilter);
    // force non direct mode
    propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
    assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
    assertNotNull(propertyFinder1.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
    classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
    PropertyFinder<DbObject> propertyFinder2 = classMeta.newPropertyFinder(propertyFilter);
    // force non direct mode
    propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("email"), new Object[0]);
    assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myid"), new Object[0]));
    assertNull(propertyFinder2.findProperty(DefaultPropertyNameMatcher.of("myname"), new Object[0]));
}
Also used : Field(java.lang.reflect.Field) DbObject(org.simpleflatmapper.test.beans.DbObject) DbObject(org.simpleflatmapper.test.beans.DbObject) DbPartialFinalObject(org.simpleflatmapper.test.beans.DbPartialFinalObject) DbFinalObject(org.simpleflatmapper.test.beans.DbFinalObject) ReflectionService(org.simpleflatmapper.reflect.ReflectionService) Method(java.lang.reflect.Method) KeyTest(org.simpleflatmapper.reflect.test.KeyTest) Test(org.junit.Test)

Example 4 with ReflectionService

use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.

the class TupleClassMetaTest method testRespecify.

@Test
public void testRespecify() throws ClassNotFoundException, MalformedURLException {
    ClassLoader cl = new URLClassLoader(new URL[] { LibrarySetsClassLoader.findUrl(Tuple2.class, getClass().getClassLoader()) }, null) {

        @Override
        public InputStream getResourceAsStream(String name) {
            return null;
        }
    };
    ReflectionService reflectionService = new ReflectionService(null) {
    };
    Class<?> tuple2Class = cl.loadClass(Tuple2.class.getName());
    TupleClassMeta classMeta = new TupleClassMeta(tuple2Class, reflectionService);
    List<InstantiatorDefinition> instantiatorDefinitions = classMeta.getInstantiatorDefinitions();
    assertEquals(1, instantiatorDefinitions.size());
    assertEquals("element0", instantiatorDefinitions.get(0).getParameters()[0].getName());
}
Also used : InstantiatorDefinition(org.simpleflatmapper.reflect.InstantiatorDefinition) Tuple2(org.simpleflatmapper.tuple.Tuple2) URLClassLoader(java.net.URLClassLoader) LibrarySetsClassLoader(org.simpleflatmapper.test.junit.LibrarySetsClassLoader) URLClassLoader(java.net.URLClassLoader) ReflectionService(org.simpleflatmapper.reflect.ReflectionService) Test(org.junit.Test)

Example 5 with ReflectionService

use of org.simpleflatmapper.reflect.ReflectionService in project SimpleFlatMapper by arnaudroger.

the class DataTypeTest method getSetter.

public static <N> Setter<SettableByIndexData, N> getSetter(Class<N> target, DataType dataType) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
    MapperConfig<DatastaxColumnKey, FieldMapperColumnDefinition<DatastaxColumnKey>> mapperConfig = MapperConfig.<DatastaxColumnKey>fieldMapperConfig();
    ReflectionService reflectionService = ReflectionService.newInstance();
    SettableDataSetterFactory factory = new SettableDataSetterFactory(mapperConfig, reflectionService);
    DatastaxColumnKey columnKey = new DatastaxColumnKey("col", 1, dataType);
    return factory.getSetter(newPM(target, dataType, columnKey));
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) DatastaxColumnKey(org.simpleflatmapper.datastax.DatastaxColumnKey) SettableDataSetterFactory(org.simpleflatmapper.datastax.impl.SettableDataSetterFactory) ReflectionService(org.simpleflatmapper.reflect.ReflectionService)

Aggregations

ReflectionService (org.simpleflatmapper.reflect.ReflectionService)6 Test (org.junit.Test)5 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)2 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)2 Tuple2 (org.simpleflatmapper.tuple.Tuple2)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 URLClassLoader (java.net.URLClassLoader)1 DatastaxColumnKey (org.simpleflatmapper.datastax.DatastaxColumnKey)1 SettableDataSetterFactory (org.simpleflatmapper.datastax.impl.SettableDataSetterFactory)1 AbstractMapperFactory (org.simpleflatmapper.map.mapper.AbstractMapperFactory)1 InstantiatorDefinition (org.simpleflatmapper.reflect.InstantiatorDefinition)1 KeyTest (org.simpleflatmapper.reflect.test.KeyTest)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1 DbPartialFinalObject (org.simpleflatmapper.test.beans.DbPartialFinalObject)1 LibrarySetsClassLoader (org.simpleflatmapper.test.junit.LibrarySetsClassLoader)1 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)1