Search in sources :

Example 1 with SfmResultSetHandlerFactoryBuilder

use of org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder in project mapping-benchmark by arnaudroger.

the class Sql2OSfmBenchmark method main.

public static void main(String[] args) throws SQLException, NamingException {
    ConnectionParam connParam = new ConnectionParam();
    connParam.db = DbTarget.H2;
    connParam.init();
    Sql2o sql2o = new Sql2o(connParam.dataSource);
    org.sql2o.Connection conn = sql2o.open();
    Map<String, String> columnMappings = new HashMap<>();
    columnMappings.put("YEAR_STARTED", "yearStarted");
    SfmResultSetHandlerFactoryBuilder builder = new SfmResultSetHandlerFactoryBuilder();
    builder.setColumnMappings(columnMappings);
    ResultSetHandlerFactory<MappedObject16> factory16 = builder.newFactory(MappedObject16.class);
    try {
        ResultSetIterable<MappedObject16> resultSetIterable = conn.createQuery(Sql2OBenchmark.SELECT_OBJECT16).addParameter("limit", 2).executeAndFetchLazy(factory16);
        for (MappedObject16 o : resultSetIterable) {
            System.out.println("o = " + o);
        }
    } finally {
        conn.close();
    }
}
Also used : MappedObject16(org.simpleflatmapper.beans.MappedObject16) HashMap(java.util.HashMap) ConnectionParam(org.simpleflatmapper.db.ConnectionParam) SfmResultSetHandlerFactoryBuilder(org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder) Sql2o(org.sql2o.Sql2o)

Example 2 with SfmResultSetHandlerFactoryBuilder

use of org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder in project SimpleFlatMapper by arnaudroger.

the class Sql2oIntegrationTest method testSql2O.

@Test
public void testSql2O() throws SQLException, ParseException {
    Connection connection = DbHelper.objectDb();
    try {
        SingleConnectionDataSource scds = new SingleConnectionDataSource(connection, true);
        Sql2o sql2o = new Sql2o(scds);
        Query query = sql2o.open().createQuery(DbHelper.TEST_DB_OBJECT_QUERY);
        query.setAutoDeriveColumnNames(true);
        query.setResultSetHandlerFactoryBuilder(new SfmResultSetHandlerFactoryBuilder());
        List<DbObject> dbObjects = query.executeAndFetch(DbObject.class);
        assertEquals(1, dbObjects.size());
        DbHelper.assertDbObjectMapping(dbObjects.get(0));
    } finally {
        connection.close();
    }
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) Query(org.sql2o.Query) DbObject(org.simpleflatmapper.test.beans.DbObject) Connection(java.sql.Connection) SfmResultSetHandlerFactoryBuilder(org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder) Sql2o(org.sql2o.Sql2o) Test(org.junit.Test)

Aggregations

SfmResultSetHandlerFactoryBuilder (org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder)2 Sql2o (org.sql2o.Sql2o)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 MappedObject16 (org.simpleflatmapper.beans.MappedObject16)1 ConnectionParam (org.simpleflatmapper.db.ConnectionParam)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1 SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)1 Query (org.sql2o.Query)1