Search in sources :

Example 6 with NoQuirks

use of org.sql2o.quirks.NoQuirks in project sql2o by aaberg.

the class ConnectionTransactionTest method beginTransaction.

@Test
public void beginTransaction() throws Exception {
    final DataSource dataSource = mock(DataSource.class);
    final java.sql.Connection connectionMock = mock(Connection.class);
    // mocked behaviour
    when(dataSource.getConnection()).thenReturn(connectionMock);
    when(connectionMock.getAutoCommit()).thenReturn(true);
    when(connectionMock.isClosed()).thenReturn(false);
    final Sql2o sql2o = new Sql2o(dataSource, new NoQuirks());
    final org.sql2o.Connection sql2oConnection = sql2o.beginTransaction();
    sql2oConnection.close();
    // Verifications
    verify(dataSource).getConnection();
    verify(connectionMock, atLeastOnce()).getAutoCommit();
    // called on beginTransaction
    verify(connectionMock, times(1)).setAutoCommit(eq(false));
    // called on closeConnection to reset autocommit state
    verify(connectionMock, times(1)).setAutoCommit(eq(true));
    verify(connectionMock, atLeastOnce()).setTransactionIsolation(anyInt());
    verify(connectionMock, times(1)).isClosed();
    verify(connectionMock, times(1)).close();
    verifyNoMoreInteractions(connectionMock, dataSource);
}
Also used : Connection(java.sql.Connection) NoQuirks(org.sql2o.quirks.NoQuirks) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 7 with NoQuirks

use of org.sql2o.quirks.NoQuirks in project sql2o by aaberg.

the class BidirectionalConverterTest method setUp.

@Before
public void setUp() {
    Quirks quirks = new NoQuirks() {

        {
            this.converters.put(UUID.class, new CustomUUIDConverter());
        }
    };
    this.sql2o = new Sql2o("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "", quirks);
    this.wrappers = randomWrappers();
    this.createAndFillTable(this.wrappers);
}
Also used : NoQuirks(org.sql2o.quirks.NoQuirks) Quirks(org.sql2o.quirks.Quirks) NoQuirks(org.sql2o.quirks.NoQuirks) Before(org.junit.Before)

Example 8 with NoQuirks

use of org.sql2o.quirks.NoQuirks in project runelite by runelite.

the class SpringBootWebApplicationTest method cacheSql2o.

@Bean("Runelite Cache SQL2O")
Sql2o cacheSql2o() throws NamingException {
    Map<Class, Converter> converters = new HashMap<>();
    converters.put(Instant.class, new InstantConverter());
    return new Sql2o("jdbc:mysql://192.168.1.2/cache", "runelite", "runelite", 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) Bean(org.springframework.context.annotation.Bean)

Example 9 with NoQuirks

use of org.sql2o.quirks.NoQuirks in project runelite by runelite.

the class SpringBootWebApplicationTest method xpSql2o.

@Bean("Runelite XP Tracker SQL2O")
Sql2o xpSql2o() throws NamingException {
    Map<Class, Converter> converters = new HashMap<>();
    converters.put(Instant.class, new InstantConverter());
    return new Sql2o("jdbc:mysql://192.168.1.2/xptracker", "runelite", "runelite", 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) Bean(org.springframework.context.annotation.Bean)

Example 10 with NoQuirks

use of org.sql2o.quirks.NoQuirks in project runelite by runelite.

the class SpringBootWebApplicationTest method sql2o.

@Bean("Runelite SQL2O")
Sql2o sql2o() {
    Map<Class, Converter> converters = new HashMap<>();
    converters.put(Instant.class, new InstantConverter());
    return new Sql2o("jdbc:mysql://192.168.1.2/runelite", "runelite", "runelite", 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) Bean(org.springframework.context.annotation.Bean)

Aggregations

NoQuirks (org.sql2o.quirks.NoQuirks)12 HashMap (java.util.HashMap)8 Sql2o (org.sql2o.Sql2o)8 Bean (org.springframework.context.annotation.Bean)7 Converter (org.sql2o.converters.Converter)7 DataSource (javax.sql.DataSource)6 InstantConverter (net.runelite.http.service.util.InstantConverter)6 Connection (java.sql.Connection)3 Test (org.junit.Test)2 Before (org.junit.Before)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 Connection (org.sql2o.Connection)1 DateTimeConverter (org.sql2o.converters.joda.DateTimeConverter)1 Quirks (org.sql2o.quirks.Quirks)1