use of org.sql2o.Sql2o in project mapping-benchmark by arnaudroger.
the class Sql2OSfmBenchmark method init.
@Setup
public void init() throws Exception {
ConnectionParam connParam = new ConnectionParam();
connParam.db = db;
connParam.init();
sql2o = new Sql2o(connParam.dataSource);
}
use of org.sql2o.Sql2o in project sql2o by aaberg.
the class H2Tests method testUUID.
/**
* Ref issue #73
*/
@Test
public void testUUID() {
try (Connection connection = new Sql2o(ds).beginTransaction()) {
connection.createQuery("create table uuidtest(id uuid primary key, val uuid null)").executeUpdate();
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
UUID uuid3 = UUID.randomUUID();
UUID uuid4 = null;
Query insQuery = connection.createQuery("insert into uuidtest(id, val) values (:id, :val)");
insQuery.addParameter("id", uuid1).addParameter("val", uuid2).executeUpdate();
insQuery.addParameter("id", uuid3).addParameter("val", uuid4).executeUpdate();
Table table = connection.createQuery("select * from uuidtest").executeAndFetchTable();
assertThat((UUID) table.rows().get(0).getObject("id"), is(equalTo(uuid1)));
assertThat((UUID) table.rows().get(0).getObject("val"), is(equalTo(uuid2)));
assertThat((UUID) table.rows().get(1).getObject("id"), is(equalTo(uuid3)));
assertThat(table.rows().get(1).getObject("val"), is(nullValue()));
connection.rollback();
}
}
use of org.sql2o.Sql2o in project sql2o by aaberg.
the class IssuesTest method testSetterPriority.
/**
* Tests for issue #1 https://github.com/aaberg/sql2o/issues/1
*
* Issue:
* I have a case where I need to override/modify the value loaded from db.
* I want to do this in a setter but the current version of sql2o modifies the property directly.
*
* Comment:
* The priority was wrong. Sql2o would try to set the field first, and afterwards the setter. The priority should be
* the setter first and the field after.
*/
@Test
public void testSetterPriority() {
Sql2o sql2o = new Sql2o(url, user, pass);
Issue1Pojo pojo = sql2o.createQuery("select 1 val from (values(0))").executeAndFetchFirst(Issue1Pojo.class);
assertEquals(2, pojo.val);
}
use of org.sql2o.Sql2o in project sql2o by aaberg.
the class PojoPerformanceTest method setup.
@Before
public void setup() {
Logger.getLogger("org.hibernate").setLevel(Level.OFF);
sql2o = new Sql2o(DB_URL, DB_USER, DB_PASSWORD);
createPostTable();
// turn off oracle because ResultSetUtils slows down with oracle
setOracleAvailable(false);
}
use of org.sql2o.Sql2o 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