Search in sources :

Example 6 with Sql2o

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);
}
Also used : ConnectionParam(org.simpleflatmapper.db.ConnectionParam) Sql2o(org.sql2o.Sql2o)

Example 7 with Sql2o

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();
    }
}
Also used : Table(org.sql2o.data.Table) Query(org.sql2o.Query) Connection(org.sql2o.Connection) UUID(java.util.UUID) Sql2o(org.sql2o.Sql2o) Test(org.junit.Test)

Example 8 with Sql2o

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);
}
Also used : Sql2o(org.sql2o.Sql2o) Issue1Pojo(org.sql2o.issues.pojos.Issue1Pojo) Test(org.junit.Test)

Example 9 with Sql2o

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);
}
Also used : Sql2o(org.sql2o.Sql2o) Before(org.junit.Before)

Example 10 with Sql2o

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

Sql2o (org.sql2o.Sql2o)16 HashMap (java.util.HashMap)9 NoQuirks (org.sql2o.quirks.NoQuirks)8 Bean (org.springframework.context.annotation.Bean)7 Converter (org.sql2o.converters.Converter)7 InstantConverter (net.runelite.http.service.util.InstantConverter)6 Test (org.junit.Test)5 DataSource (javax.sql.DataSource)4 ConnectionParam (org.simpleflatmapper.db.ConnectionParam)3 SfmResultSetHandlerFactoryBuilder (org.simpleflatmapper.sql2o.SfmResultSetHandlerFactoryBuilder)2 Connection (org.sql2o.Connection)2 Query (org.sql2o.Query)2 Connection (java.sql.Connection)1 UUID (java.util.UUID)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 Before (org.junit.Before)1 MappedObject16 (org.simpleflatmapper.beans.MappedObject16)1 DbObject (org.simpleflatmapper.test.beans.DbObject)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)1