org.jooq.conf.Settings Java Examples
The following examples show how to use
org.jooq.conf.Settings.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseModule.java From curiostack with MIT License | 6 votes |
@Provides @Singleton static DSLContext dbContext( DataSource dataSource, DatabaseConfig config, @ForDatabase ListeningExecutorService dbExecutor) { Configuration configuration = new DefaultConfiguration() .set(dbExecutor) .set(SQLDialect.MYSQL) .set(new Settings().withRenderSchema(false)) .set(new DataSourceConnectionProvider(dataSource)) .set(DatabaseUtil.sfmRecordMapperProvider()); if (config.getLogQueries()) { configuration.set(new QueryLogger()); } DSLContext ctx = DSL.using(configuration); // Eagerly trigger JOOQ classinit for better startup performance. ctx.select().from("curio_server_framework_init").getSQL(); return ctx; }
Example #2
Source File: JooqFactory.java From droptools with Apache License 2.0 | 6 votes |
private Settings buildSettings() { final Settings settings = new Settings(); settings.setRenderSchema(renderSchema); settings.setRenderNameStyle(renderNameStyle); settings.setRenderKeywordStyle(renderKeywordStyle); settings.setRenderFormatted(renderFormatted); settings.setParamType(paramType); settings.setStatementType(statementType); settings.setExecuteLogging(executeLogging); settings.setExecuteWithOptimisticLocking(executeWithOptimisticLocking); settings.setAttachRecords(attachRecords); settings.setUpdatablePrimaryKeys(updatablePrimaryKeys); settings.setFetchWarnings(fetchWarnings); return settings; }
Example #3
Source File: AbstractJOOQIntegrationTest.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
protected void doInJOOQ(DSLContextVoidCallable callable, Settings settings) { Session session = null; Transaction txn = null; try { session = sessionFactory().openSession(); txn = session.beginTransaction(); session.doWork(connection -> { DSLContext sql = settings != null ? DSL.using(connection, sqlDialect(), settings) : DSL.using(connection, sqlDialect()); callable.execute(sql); }); txn.commit(); } catch (Throwable e) { if ( txn != null ) txn.rollback(); throw e; } finally { if (session != null) { session.close(); } } }
Example #4
Source File: AbstractJOOQIntegrationTest.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
protected <T> T doInJOOQ(DSLContextCallable<T> callable, Settings settings) { Session session = null; Transaction txn = null; try { session = sessionFactory().openSession(); txn = session.beginTransaction(); T result = session.doReturningWork(connection -> { DSLContext sql = settings != null ? DSL.using(connection, sqlDialect(), settings) : DSL.using(connection, sqlDialect()); return callable.execute(sql); }); txn.commit(); return result; } catch (Throwable e) { if ( txn != null ) txn.rollback(); throw e; } finally { if (session != null) { session.close(); } } }
Example #5
Source File: DbTestsApplication.java From java-persistence-frameworks-comparison with MIT License | 5 votes |
@Bean @Primary public Settings jooqSettings() { Settings ret = new Settings(); ret.withRenderSchema(false); ret.setRenderFormatted(true); ret.setRenderNameStyle(RenderNameStyle.AS_IS); return ret; }
Example #6
Source File: JooqFactory.java From droptools with Apache License 2.0 | 5 votes |
public Configuration build(Environment environment, PooledDataSourceFactory factory, String name) throws ClassNotFoundException { final Settings settings = buildSettings(); final ManagedDataSource dataSource = factory.build(environment.metrics(), name); final SQLDialect dialect = determineDialect(factory, dataSource); final ConnectionProvider connectionProvider = new DataSourceConnectionProvider(dataSource); final Configuration config = new DefaultConfiguration() .set(settings) .set(dialect) .set(connectionProvider); environment.lifecycle().manage(dataSource); return config; }
Example #7
Source File: DatabaseAccess.java From hmftools with GNU General Public License v3.0 | 5 votes |
@Nullable private static Settings settings(@NotNull String catalog) { return !catalog.equals(DEV_CATALOG) ? new Settings().withRenderMapping(new RenderMapping().withSchemata(new MappedSchema().withInput(DEV_CATALOG) .withOutput(catalog))) : null; }
Example #8
Source File: ViccDAO.java From hmftools with GNU General Public License v3.0 | 5 votes |
@Nullable private static Settings settings(@NotNull String catalog) { if (catalog.equals(DEV_CATALOG)) { return null; } return new Settings().withRenderMapping(new RenderMapping().withSchemata(new MappedSchema().withInput(DEV_CATALOG) .withOutput(catalog))); }
Example #9
Source File: AbstractSQLEntityStoreAssembler.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public void assemble( ModuleAssembly module ) { super.assemble( module ); SQLDialect dialect = getSQLDialect(); if( dialect == null ) { throw new AssemblyException( "SQLDialect must not be null" ); } Settings settings = getSettings(); if( settings == null ) { throw new AssemblyException( "Settings must not be null" ); } String identity = ( hasIdentity() ? identity() : DEFAULT_ENTITYSTORE_IDENTITY ).toString(); LiquibaseAssembler liquibase = new LiquibaseAssembler().identifiedBy( identity + "-liquibase" ); if( hasConfig() ) { liquibase.withConfig( configModule(), configVisibility() ); LiquibaseConfiguration liquibaseconfig = configModule().forMixin( LiquibaseConfiguration.class ) .declareDefaults(); liquibaseconfig.changeLog().set( changelogPath ); } liquibase.assemble( module ); module.services( SQLEntityStoreService.class ) .identifiedBy( identity ) .visibleIn( visibility() ) .setMetaInfo( dialect ) .setMetaInfo( settings ); if( hasConfig() ) { configModule().entities( SQLEntityStoreConfiguration.class ).visibleIn( configVisibility() ); } }
Example #10
Source File: SQLEntityStoreMixin.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public void activateService() throws Exception { configuration.refresh(); SQLEntityStoreConfiguration config = configuration.get(); // Prepare jooq DSL SQLDialect dialect = descriptor.metaInfo( SQLDialect.class ); Settings settings = descriptor.metaInfo( Settings.class ); String schemaName = config.schemaName().get(); String tableName = config.entityTableName().get(); schema = DSL.schema( DSL.name( schemaName ) ); table = DSL.table( dialect.equals( SQLDialect.SQLITE ) ? DSL.name( tableName ) : DSL.name( schema.getName(), tableName ) ); identityColumn = DSL.field( DSL.name( IDENTITY_COLUMN_NAME ), String.class ); versionColumn = DSL.field( DSL.name( VERSION_COLUMN_NAME ), String.class ); stateColumn = DSL.field( DSL.name( STATE_COLUMN_NAME ), String.class ); dsl = DSL.using( dataSource, dialect, settings ); // Eventually create schema and apply Liquibase changelog if( config.createIfMissing().get() ) { if( !dialect.equals( SQLDialect.SQLITE ) && dsl.meta().getSchemas().stream().noneMatch( s -> schema.getName().equalsIgnoreCase( s.getName() ) ) ) { dsl.createSchema( schema ).execute(); } applyLiquibaseChangelog( dialect ); } }
Example #11
Source File: DIBaseConfiguration.java From waltz with Apache License 2.0 | 5 votes |
@Bean @Autowired public DSLContext dsl(DataSource dataSource) { try { SQLDialect.valueOf(dialect); } catch (IllegalArgumentException iae) { System.err.println("Cannot parse sql dialect: "+dialect); throw iae; } // TODO: remove sql server setting, see #4553 Settings dslSettings = new Settings() .withRenderOutputForSQLServerReturningClause(false); if ("true".equals(System.getProperty(JOOQ_DEBUG_PROPERTY))) { dslSettings .withRenderFormatted(true) .withExecuteLogging(true); } org.jooq.Configuration configuration = new DefaultConfiguration() .set(dataSource) .set(SQLDialect.valueOf(dialect)) .set(dslSettings) .set(new SlowQueryListener(databasePerformanceQuerySlowThreshold)); return DSL.using(configuration); }
Example #12
Source File: SlowQueryListener.java From waltz with Apache License 2.0 | 5 votes |
@Override public void executeEnd(ExecuteContext ctx) { super.executeEnd(ctx); long split = stopWatch.split(); if (split > slowQueryThresholdInNanos) { DSLContext context = DSL.using(ctx.dialect(), // ... and the flag for pretty-printing new Settings().withRenderFormatted(true)); LOG.warn(String.format("Slow SQL executed in %d seconds", TimeUnit.NANOSECONDS.toSeconds(split)), new SQLPerformanceWarning(context.renderInlined(ctx.query()))); } }
Example #13
Source File: DSLContexts.java From keywhiz with Apache License 2.0 | 5 votes |
public static DSLContext databaseAgnostic(DataSource dataSource) throws SQLException { SQLDialect dialect; try (Connection conn = dataSource.getConnection()) { dialect = dialect(conn); // See https://github.com/jOOQ/jOOQ/issues/4730 if (conn.getMetaData().getURL().startsWith("jdbc:pgsql:")) { dialect = POSTGRES; } } return DSL.using(dataSource, dialect, new Settings() .withRenderSchema(false) .withRenderNameStyle(RenderNameStyle.AS_IS)); }
Example #14
Source File: SQLBasedIndexerConfig.java From samantha with MIT License | 5 votes |
public Indexer getIndexer(RequestContext requestContext) { SamanthaConfigService configService = injector.instanceOf(SamanthaConfigService.class); Settings settings = new Settings() .withStatementType(StatementType.STATIC_STATEMENT); DSLContext create = DSL.using(DB.getDataSource(db), SQLDialect.DEFAULT, settings); return new SQLBasedIndexer(configService, daoConfigs, create, tableKey, table, injector, daoConfigKey, fields, fieldTypes, matchFields, matchFieldTypes, retrieverName, setCursorKey, daoNameKey, daoName, cacheJsonFile, filePathKey, separatorKey, config, 128, requestContext); }
Example #15
Source File: SQLBasedRetrieverConfig.java From samantha with MIT License | 5 votes |
public Retriever getRetriever(RequestContext requestContext) { Settings settings = new Settings() .withStatementType(StatementType.STATIC_STATEMENT); DSLContext create = DSL.using(DB.getDataSource(db), SQLDialect.DEFAULT, settings); return new SQLBasedRetriever(config, setCursorKey, limit, offset, selectSqlKey, matchFields, greaterFields, lessFields, matchFieldTypes, greaterFieldTypes, lessFieldTypes, create, selectFields, table, orderByFields, renameMap, requestContext, injector); }
Example #16
Source File: SQLBasedJoinExpander.java From samantha with MIT License | 5 votes |
public static EntityExpander getExpander(Configuration expanderConfig, Injector injector, RequestContext requestContext) { Settings settings = new Settings() .withStatementType(StatementType.STATIC_STATEMENT); DSLContext create = DSL.using(DB.getDataSource(expanderConfig.getString("db")), SQLDialect.DEFAULT, settings); return new SQLBasedJoinExpander(expanderConfig.getConfigList("expandFields"), create); }
Example #17
Source File: DbTestsApplication.java From java-persistence-frameworks-comparison with MIT License | 5 votes |
@Bean @Qualifier("static-statement-jooq-settings") public Settings jooqStaticStatementSettings() { Settings ret = jooqSettings(); ret.withStatementType(StatementType.STATIC_STATEMENT); return ret; }
Example #18
Source File: AbstractSQLEntityStoreAssembler.java From attic-polygene-java with Apache License 2.0 | 4 votes |
protected Settings getSettings() { return new Settings().withRenderNameStyle( RenderNameStyle.QUOTED ); }
Example #19
Source File: SettingsModule.java From guice-persist-jooq with Apache License 2.0 | 4 votes |
protected void configure() { Settings settings= new Settings(); settings.setBackslashEscaping(ESCAPING); binder().bind(Settings.class).toInstance(settings); }
Example #20
Source File: JooqDataRepositoryImpl.java From java-persistence-frameworks-comparison with MIT License | 4 votes |
@SuppressWarnings("SpringJavaAutowiringInspection") @Autowired public JooqDataRepositoryImpl(DSLContext create, @Qualifier("static-statement-jooq-settings") Settings staticStatementSettings) { this.create = create; this.staticStatementSettings = staticStatementSettings; }
Example #21
Source File: JooqConfigurationFactory.java From micronaut-sql with Apache License 2.0 | 4 votes |
/** * Creates jOOQ {@link Configuration}. * It will configure it with available jOOQ provider beans with the same qualifier. * * @param name The data source name * @param dataSource The {@link DataSource} * @param transactionProvider The transaction provider * @param settings The settings * @param executorProvider The executor provider * @param recordMapperProvider The record mapper provider * @param recordUnmapperProvider The record unmapper provider * @param metaProvider The metadata provider * @param ctx The {@link ApplicationContext} * @return A {@link Configuration} */ @EachBean(DataSource.class) public Configuration jooqConfiguration( @Parameter String name, DataSource dataSource, @Parameter @Nullable TransactionProvider transactionProvider, @Parameter @Nullable Settings settings, @Parameter @Nullable ExecutorProvider executorProvider, @Parameter @Nullable RecordMapperProvider recordMapperProvider, @Parameter @Nullable RecordUnmapperProvider recordUnmapperProvider, @Parameter @Nullable MetaProvider metaProvider, ApplicationContext ctx ) { DefaultConfiguration configuration = new DefaultConfiguration(); JooqConfigurationProperties properties = ctx.findBean(JooqConfigurationProperties.class, Qualifiers.byName(name)) .orElseGet(JooqConfigurationProperties::new); DataSourceResolver dataSourceResolver = ctx.findBean(DataSourceResolver.class).orElse(DataSourceResolver.DEFAULT); configuration.setSQLDialect(properties.determineSqlDialect(dataSourceResolver.resolve(dataSource))); configuration.setDataSource(dataSource); if (transactionProvider != null) { configuration.setTransactionProvider(transactionProvider); } if (settings != null) { configuration.setSettings(settings); } if (executorProvider != null) { configuration.setExecutorProvider(executorProvider); } if (recordMapperProvider != null) { configuration.setRecordMapperProvider(recordMapperProvider); } if (recordUnmapperProvider != null) { configuration.setRecordUnmapperProvider(recordUnmapperProvider); } if (metaProvider != null) { configuration.setMetaProvider(metaProvider); } configuration.setExecuteListenerProvider(ctx.getBeansOfType(ExecuteListenerProvider.class, Qualifiers.byName(name)) .toArray(new ExecuteListenerProvider[0])); configuration.setRecordListenerProvider(ctx.getBeansOfType(RecordListenerProvider.class, Qualifiers.byName(name)) .toArray(new RecordListenerProvider[0])); configuration.setVisitListenerProvider(ctx.getBeansOfType(VisitListenerProvider.class, Qualifiers.byName(name)) .toArray(new VisitListenerProvider[0])); configuration.setTransactionListenerProvider(ctx.getBeansOfType(TransactionListenerProvider.class, Qualifiers.byName(name)) .toArray(new TransactionListenerProvider[0])); configuration.setDiagnosticsListenerProvider(ctx.getBeansOfType(DiagnosticsListenerProvider.class, Qualifiers.byName(name)) .toArray(new DiagnosticsListenerProvider[0])); return configuration; }