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