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();
}
}
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();
}
}
Aggregations