Search in sources :

Example 1 with Sql2o

use of org.sql2o.Sql2o in project sql2o by aaberg.

the class H2Tests method testIssue155.

@Test
public void testIssue155() {
    Sql2o sql2o = new Sql2o(ds, new NoQuirks(new HashMap<Class, Converter>() {

        {
            put(DateTime.class, new DateTimeConverter(DateTimeZone.getDefault()));
        }
    }));
    assertThat(sql2o.getQuirks(), is(instanceOf(NoQuirks.class)));
    try (Connection connection = sql2o.open()) {
        int val = connection.createQuery("select 42").executeScalar(Integer.class);
        assertThat(val, is(equalTo(42)));
    }
}
Also used : HashMap(java.util.HashMap) Connection(org.sql2o.Connection) DateTimeConverter(org.sql2o.converters.joda.DateTimeConverter) NoQuirks(org.sql2o.quirks.NoQuirks) Sql2o(org.sql2o.Sql2o) Test(org.junit.Test)

Example 2 with Sql2o

use of org.sql2o.Sql2o in project sql2o by aaberg.

the class H2Tests method testIssue172NPEWhenCreatingBasicDataSourceInline.

@Test
public void testIssue172NPEWhenCreatingBasicDataSourceInline() {
    DataSource ds = new JdbcDataSource() {

        {
            setURL(url);
            setUser(user);
            setPassword(pass);
        }
    };
    Sql2o sql2o = new Sql2o(ds);
    assertThat(sql2o.getQuirks(), is(instanceOf(H2Quirks.class)));
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Sql2o(org.sql2o.Sql2o) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with Sql2o

use of org.sql2o.Sql2o in project runelite by runelite.

the class SpringBootWebApplication method cacheSql2o.

@Bean("Runelite Cache SQL2O")
Sql2o cacheSql2o() throws NamingException {
    DataSource dataSource = (DataSource) getContext().lookup("jdbc/runelite-cache2");
    Map<Class, Converter> converters = new HashMap<>();
    converters.put(Instant.class, new InstantConverter());
    return new Sql2o(dataSource, new NoQuirks(converters));
}
Also used : HashMap(java.util.HashMap) InstantConverter(net.runelite.http.service.util.InstantConverter) Converter(org.sql2o.converters.Converter) InstantConverter(net.runelite.http.service.util.InstantConverter) NoQuirks(org.sql2o.quirks.NoQuirks) Sql2o(org.sql2o.Sql2o) DataSource(javax.sql.DataSource) Bean(org.springframework.context.annotation.Bean)

Example 4 with Sql2o

use of org.sql2o.Sql2o in project runelite by runelite.

the class SpringBootWebApplication method trackerSql2o.

@Bean("Runelite XP Tracker SQL2O")
Sql2o trackerSql2o() throws NamingException {
    DataSource dataSource = (DataSource) getContext().lookup("jdbc/runelite-tracker");
    Map<Class, Converter> converters = new HashMap<>();
    converters.put(Instant.class, new InstantConverter());
    return new Sql2o(dataSource, new NoQuirks(converters));
}
Also used : HashMap(java.util.HashMap) InstantConverter(net.runelite.http.service.util.InstantConverter) Converter(org.sql2o.converters.Converter) InstantConverter(net.runelite.http.service.util.InstantConverter) NoQuirks(org.sql2o.quirks.NoQuirks) Sql2o(org.sql2o.Sql2o) DataSource(javax.sql.DataSource) Bean(org.springframework.context.annotation.Bean)

Example 5 with Sql2o

use of org.sql2o.Sql2o 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)

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