Skip to content

Sfm integration in Jooq And Sql2o for performance

Arnaud Roger edited this page Jan 26, 2015 · 2 revisions

If you use sfm to fetch the record for Jooq - not as a mapper but directly from the fetchResultSet() - or using it as the mapper in sql2o you can observe the following gain on java 8 mysql.

JooqAndSql2oPerformanceGain

Jooq

private JdbcMapper<SmallBenchmarkObject> mapper = JdbcMapperFactory.newInstance().newMapper(SmallBenchmarkObject.class);
...

ResultSet resultSet = dslSfmMapping.select().from("test_small_benchmark_object").limit(limit.limit).fetchResultSet();
try {
    mapper.forEach(resultSet, this:doSomething);
} finally {
    resultSet.close();
}

sql2o

private final ResultSetHandlerFactory<SmallBenchmarkObject> factory = new SfmResultSetHandlerFactoryBuilder().newFactory(SmallBenchmarkObject.class);

...

try (org.sql2o.Connection conn = sql2o.open()) {
	List<?> list = conn.createQuery("SELECT id, name, email, year_started FROM test_small_benchmark_object LIMIT :limit")
			.addColumnMapping("YEAR_STARTED", "yearStarted")
			.addParameter("limit", limit.limit)
			.executeAndFetch(factory);
	for(Object o : list) {
		blackhole.consume(o);
	}
}
Clone this wiki locally