Search in sources :

Example 71 with DSLContext

use of org.jooq.DSLContext in project spring-boot by spring-projects.

the class JooqAutoConfigurationTests method jooqWithoutTx.

@Test
public void jooqWithoutTx() throws Exception {
    registerAndRefresh(JooqDataSourceConfiguration.class, JooqAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    assertThat(getBeanNames(PlatformTransactionManager.class)).isEqualTo(NO_BEANS);
    assertThat(getBeanNames(SpringTransactionProvider.class)).isEqualTo(NO_BEANS);
    DSLContext dsl = this.context.getBean(DSLContext.class);
    dsl.execute("create table jooqtest (name varchar(255) primary key);");
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest;", "0"));
    dsl.transaction(new ExecuteSql(dsl, "insert into jooqtest (name) values ('foo');"));
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest;", "1"));
    try {
        dsl.transaction(new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');", "insert into jooqtest (name) values ('foo');"));
        fail("An DataIntegrityViolationException should have been thrown.");
    } catch (DataIntegrityViolationException ex) {
    // Ignore
    }
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest;", "2"));
}
Also used : DSLContext(org.jooq.DSLContext) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 72 with DSLContext

use of org.jooq.DSLContext in project spring-boot by spring-projects.

the class JooqAutoConfigurationTests method jooqWithTx.

@Test
public void jooqWithTx() throws Exception {
    registerAndRefresh(JooqDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class, TxManagerConfiguration.class, JooqAutoConfiguration.class);
    this.context.getBean(PlatformTransactionManager.class);
    DSLContext dsl = this.context.getBean(DSLContext.class);
    assertThat(dsl.configuration().dialect()).isEqualTo(SQLDialect.H2);
    dsl.execute("create table jooqtest_tx (name varchar(255) primary key);");
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "0"));
    dsl.transaction(new ExecuteSql(dsl, "insert into jooqtest_tx (name) values ('foo');"));
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "1"));
    try {
        dsl.transaction(new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');", "insert into jooqtest (name) values ('foo');"));
        fail("A DataIntegrityViolationException should have been thrown.");
    } catch (DataIntegrityViolationException ex) {
    // Ignore
    }
    dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "1"));
}
Also used : DSLContext(org.jooq.DSLContext) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 73 with DSLContext

use of org.jooq.DSLContext in project OpenAttestation by OpenAttestation.

the class TagJdbi method jooq.

/**
     * CODE QUALITY: All usage of this method should be in the following form:
     * <pre>
     * try(JooqContainer jc = TagJdbi.jooq()) {
     * DSLContext jooq = jc.getDslContext();
     * // code
     * }
     * </pre>
     *
     * This ensures the jooq database connection is automatically released
     * at the end of the block (either closed or returned to the pool)
     * 
     * @return
     * @throws SQLException
     * @throws IOException
     */
public static JooqContainer jooq() throws SQLException, IOException {
    // omits the schema name from generated sql ; when we connect to the database we already specify a schema so this settings avoid 
    // redundancy in the sql and allows the administrator to change the database name without breaking the application
    Settings settings = new Settings().withRenderSchema(false).withRenderNameStyle(RenderNameStyle.LOWER);
    SQLDialect dbDialect = getSqlDialect();
    // throws SQLException; Note that the DSLContext doesn't close the connection. We'll have to do that ourselves.
    Connection connection = TagJdbi.getDataSource().getConnection();
    DSLContext jooq = DSL.using(connection, dbDialect, settings);
    return new JooqContainer(jooq, connection);
}
Also used : JooqContainer(com.intel.mtwilson.jooq.util.JooqContainer) SQLDialect(org.jooq.SQLDialect) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) Settings(org.jooq.conf.Settings)

Example 74 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class ServerSideWorldRegistar method register.

public void register(String name) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        Timestamp createdTime = new Timestamp(System.currentTimeMillis());
        create.insertInto(WORLDS).columns(WORLDS.NAME, WORLDS.CREATED_AT).values(name, createdTime).onDuplicateKeyUpdate().set(WORLDS.CREATED_AT, createdTime).execute();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) Timestamp(java.sql.Timestamp)

Example 75 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class WorldServiceImpl method onPlayerJoin.

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        Player player = event.getTargetEntity();
        UUID uuid = player.getUniqueId();
        World world = player.getWorld();
        Record1<Timestamp> result = create.select(WORLDS.CREATED_AT).from(WORLDS).where(WORLDS.NAME.equal(world.getName())).fetchOne();
        Timestamp worldCreationTimestamp = result.getValue(WORLDS.CREATED_AT);
        long worldCreationTime = 0;
        if (worldCreationTimestamp != null) {
            worldCreationTime = worldCreationTimestamp.getTime();
        }
        if (worldCreationTime > lastPlayerLogin.remove(uuid)) {
            Location<World> spawn = getEffectWrapper(MainWorldWrapper.class).get().getPrimaryWorld().getSpawnLocation();
            player.setLocation(spawn);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) Player(org.spongepowered.api.entity.living.player.Player) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) World(org.spongepowered.api.world.World) Timestamp(java.sql.Timestamp) Listener(org.spongepowered.api.event.Listener)

Aggregations

DSLContext (org.jooq.DSLContext)109 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)55 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 List (java.util.List)17 DIConfiguration (com.khartec.waltz.service.DIConfiguration)14 Collectors (java.util.stream.Collectors)14 EntityKind (com.khartec.waltz.model.EntityKind)11 ArrayList (java.util.ArrayList)9 DSL (org.jooq.impl.DSL)9 EntityReference (com.khartec.waltz.model.EntityReference)8 Timestamp (java.sql.Timestamp)8 Random (java.util.Random)8 IntStream (java.util.stream.IntStream)8 Application (com.khartec.waltz.model.application.Application)7 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)6 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)6 Field (org.jooq.Field)6 Record1 (org.jooq.Record1)6 Test (org.junit.Test)6