use of org.jooq.impl.DefaultConfiguration in project mapping-benchmark by arnaudroger.
the class JooqRecordBenchmark method main.
public static void main(String[] args) throws SQLException, NamingException {
ConnectionParam cp = new ConnectionParam();
cp.db = DbTarget.H2;
cp.init();
DSLContext dsl = DSL.using(new DefaultConfiguration().set(cp.dataSource).set(SQLDialect.H2));
dsl.selectFrom(TestSmallBenchmarkObject.TEST_SMALL_BENCHMARK_OBJECT).limit(2).forEach(System.out::println);
}
use of org.jooq.impl.DefaultConfiguration in project unipop by unipop-graph.
the class ContextManager method reloadContexts.
private void reloadContexts() throws IOException {
SQLDialect dialect = SQLDialect.valueOf(this.conf.getString("sqlDialect"));
BasicDataSource ds = new BasicDataSource();
ds.setUrl(new ObjectMapper().readValue(conf.getJSONArray("address").toString(), List.class).get(0).toString());
ds.setDriverClassName(conf.getString("driver"));
String user = conf.optString("user");
String password = conf.optString("password");
if (!user.isEmpty())
ds.setUsername(user);
if (!password.isEmpty())
ds.setPassword(password);
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
Configuration conf = new DefaultConfiguration().set(ds).set(dialect).set(settings).set(new DefaultExecuteListenerProvider(new TimingExecuterListener()));
this.context = DSL.using(conf);
}
use of org.jooq.impl.DefaultConfiguration in project tutorials by eugenp.
the class InitialConfiguration method configuration.
public DefaultConfiguration configuration() {
DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
jooqConfiguration.set(connectionProvider());
jooqConfiguration.set(new DefaultExecuteListenerProvider(new ExceptionTranslator()));
return jooqConfiguration;
}
use of org.jooq.impl.DefaultConfiguration in project jOOQ by jOOQ.
the class Setup method run.
// This class sets up an EntityManager and configures the jOOQ DSLContext
// ----------------------------------------------------------------------
static void run(BiConsumer<EntityManager, DSLContext> consumer) throws Exception {
Connection connection = null;
EntityManagerFactory emf = null;
EntityManager em = null;
try {
// Bootstrapping JDBC:
Class.forName("org.h2.Driver");
connection = new LoggingConnection(DriverManager.getConnection("jdbc:h2:mem:jooq-jpa-example", "sa", ""));
final Connection c = connection;
// Creating an in-memory H2 database from our entities
MetadataSources metadata = new MetadataSources(new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect").applySetting("javax.persistence.schema-generation-connection", connection).applySetting("javax.persistence.create-database-schemas", true).applySetting(AvailableSettings.CONNECTION_PROVIDER, new ConnectionProvider() {
@SuppressWarnings("rawtypes")
@Override
public boolean isUnwrappableAs(Class unwrapType) {
return false;
}
@Override
public <T> T unwrap(Class<T> unwrapType) {
return null;
}
@Override
public Connection getConnection() {
return c;
}
@Override
public void closeConnection(Connection conn) throws SQLException {
}
@Override
public boolean supportsAggressiveRelease() {
return true;
}
}).build());
metadata.addAnnotatedClass(Actor.class);
metadata.addAnnotatedClass(Film.class);
metadata.addAnnotatedClass(Language.class);
SchemaExport export = new SchemaExport();
export.create(EnumSet.of(TargetType.DATABASE), metadata.buildMetadata());
Map<Object, Object> props = new HashMap<>();
DataSource ds = new SingleConnectionDataSource(connection);
props.put("hibernate.connection.datasource", ds);
props.put("hibernate.archive.autodetection", "");
emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory(pui(ds), props);
em = emf.createEntityManager();
final EntityManager e = em;
// Run some Hibernate / jOOQ logic inside of a transaction
em.getTransaction().begin();
data(em);
consumer.accept(em, new DefaultConfiguration().set(connection).set(onStart(ctx -> e.flush())).dsl());
em.getTransaction().commit();
} finally {
if (em != null)
em.close();
if (emf != null)
emf.close();
if (connection != null)
connection.close();
}
}
use of org.jooq.impl.DefaultConfiguration in project jOOQ by jOOQ.
the class SakilaReportService method initDB.
private static void initDB() throws Exception {
final Properties properties = new Properties();
properties.load(SakilaReportService.class.getResourceAsStream("/config.properties"));
Class.forName(properties.getProperty("db.driver"));
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(properties.getProperty("db.url"));
ds.setUsername(properties.getProperty("db.username"));
ds.setPassword(properties.getProperty("db.password"));
// Some nice debug logging of formatted queries and the first 5 rows in each result set.
dsl = DSL.using(new DefaultConfiguration().set(ds).set(SQLDialect.POSTGRES).set(DefaultExecuteListenerProvider.providers(new DefaultExecuteListener() {
@Override
public void executeEnd(ExecuteContext ctx) {
Configuration config = ctx.configuration().derive();
config.settings().setRenderFormatted(true);
log.info("\n" + config.dsl().renderInlined(ctx.query()));
}
@Override
public void fetchEnd(ExecuteContext ctx) {
log.info("\n" + ctx.result().format(5));
}
})));
}
Aggregations