Search in sources :

Example 6 with JdbcMapperFactory

use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.

the class TestMapFooBar method mapFooBarNoBuilderLink.

@Test
public void mapFooBarNoBuilderLink() throws NoSuchMethodException {
    final JdbcMapperFactory mapperFactory = JdbcMapperFactory.newInstance();
    final ClassMeta<FoobarValueNoBuilderLink> meta = mapperFactory.getClassMetaWithExtraInstantiator(FoobarValueNoBuilderLink.class, ImmutableFoobarValueNoBuilderLink.class.getMethod("builder"));
    final JdbcMapperBuilder<FoobarValueNoBuilderLink> builder = mapperFactory.newBuilder(meta);
    assertNotNull(builder.addKey("foo").addKey("bar").addKey("crux").mapper());
}
Also used : JdbcMapperFactory(org.simpleflatmapper.jdbc.JdbcMapperFactory) Test(org.junit.Test)

Example 7 with JdbcMapperFactory

use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.

the class JdbcTemplateCrudDSL method to.

public JdbcTemplateCrud<T, K> to(JdbcOperations jdbcOperations, final String table) {
    final JdbcMapperFactory factory = JdbcMapperFactory.newInstance(jdbcTemplateMapperFactory);
    Crud<T, K> crud = jdbcOperations.execute(new ConnectionCallback<Crud<T, K>>() {

        @Override
        public Crud<T, K> doInConnection(Connection connection) throws SQLException, DataAccessException {
            return factory.<T, K>crud(target, keyTarget).table(connection, table);
        }
    });
    return new JdbcTemplateCrud<T, K>(jdbcOperations, crud);
}
Also used : JdbcMapperFactory(org.simpleflatmapper.jdbc.JdbcMapperFactory) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Crud(org.simpleflatmapper.jdbc.Crud) DataAccessException(org.springframework.dao.DataAccessException)

Example 8 with JdbcMapperFactory

use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.

the class JdbcTemplateCrudDSL method lazilyTo.

public JdbcTemplateCrud<T, K> lazilyTo(JdbcOperations jdbcOperations) {
    final JdbcMapperFactory factory = JdbcMapperFactory.newInstance(jdbcTemplateMapperFactory);
    Crud<T, K> crud = factory.<T, K>crud(target, keyTarget).crud();
    return new JdbcTemplateCrud<T, K>(jdbcOperations, crud);
}
Also used : JdbcMapperFactory(org.simpleflatmapper.jdbc.JdbcMapperFactory)

Example 9 with JdbcMapperFactory

use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.

the class JdbcTemplateCrudDSL method lazilyTo.

public JdbcTemplateCrud<T, K> lazilyTo(JdbcOperations jdbcOperations, final String table) {
    final JdbcMapperFactory factory = JdbcMapperFactory.newInstance(jdbcTemplateMapperFactory);
    Crud<T, K> crud = factory.<T, K>crud(target, keyTarget).table(table);
    return new JdbcTemplateCrud<T, K>(jdbcOperations, crud);
}
Also used : JdbcMapperFactory(org.simpleflatmapper.jdbc.JdbcMapperFactory)

Example 10 with JdbcMapperFactory

use of org.simpleflatmapper.jdbc.JdbcMapperFactory in project SimpleFlatMapper by arnaudroger.

the class JdbcMapperCustomMappingTest method testColumnAliasStatic.

@Test
public void testColumnAliasStatic() throws Exception {
    JdbcMapperFactory mapperFactory = JdbcMapperFactoryHelper.asm();
    mapperFactory.addAlias("not_id_column", "id");
    final JdbcMapper<DbObject> mapper = JdbcMapperDbObjectTest.addColumn(mapperFactory.newBuilder(DbObject.class)).mapper();
    DbHelper.testQuery(new TestRowHandler<PreparedStatement>() {

        @Override
        public void handle(PreparedStatement t) throws Exception {
            ResultSet r = t.executeQuery();
            r.next();
            DbHelper.assertDbObjectMapping(mapper.map(r));
        }
    }, DbHelper.TEST_DB_OBJECT_QUERY.replace("id,", "id as not_id_column,"));
}
Also used : JdbcMapperFactory(org.simpleflatmapper.jdbc.JdbcMapperFactory) DbObject(org.simpleflatmapper.test.beans.DbObject) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MappingException(org.simpleflatmapper.map.MappingException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

JdbcMapperFactory (org.simpleflatmapper.jdbc.JdbcMapperFactory)14 Test (org.junit.Test)9 SQLException (java.sql.SQLException)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 MappingException (org.simpleflatmapper.map.MappingException)6 DbObject (org.simpleflatmapper.test.beans.DbObject)6 Connection (java.sql.Connection)4 Crud (org.simpleflatmapper.jdbc.Crud)2 DataAccessException (org.springframework.dao.DataAccessException)2 DynamicJdbcMapper (org.simpleflatmapper.jdbc.DynamicJdbcMapper)1 IndexedSetterProperty (org.simpleflatmapper.jdbc.property.IndexedSetterProperty)1 DefaultPropertyNameMatcherFactory (org.simpleflatmapper.map.mapper.DefaultPropertyNameMatcherFactory)1 GetterProperty (org.simpleflatmapper.map.property.GetterProperty)1 Getter (org.simpleflatmapper.reflect.Getter)1 IndexedSetter (org.simpleflatmapper.reflect.IndexedSetter)1 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)1