private static void initInternal(final Vertx vertx, final String name) { vertxRef = vertx; Fn.pool(CONFIGS, name, () -> Infix.init(Plugins.Infix.JOOQ, (config) -> { // Initialized client final Configuration configuration = new DefaultConfiguration(); configuration.set(SQLDialect.MYSQL_8_0); final ConnectionProvider provider = new DefaultConnectionProvider(HikariCpPool.getConnection( config.getJsonObject("provider") )); // Initialized default configuration configuration.set(provider); return configuration; }, JooqInfix.class)); }
public DslContextConfiguration(JooqProperties properties, ConnectionProvider connectionProvider, ObjectProvider<TransactionProvider> transactionProviderProvider, ObjectProvider<RecordMapperProvider> recordMapperProviderProvider, ObjectProvider<Settings> settingsProvider, ObjectProvider<RecordListenerProvider[]> recordListenerProvidersProvider, ExecuteListenerProvider[] executeListenerProviders, ObjectProvider<VisitListenerProvider[]> visitListenerProvidersProvider) { this.properties = properties; this.connectionProvider = connectionProvider; this.transactionProvider = transactionProviderProvider.getIfAvailable(); this.recordMapperProvider = recordMapperProviderProvider.getIfAvailable(); this.settings = settingsProvider.getIfAvailable(); this.recordListenerProviders = recordListenerProvidersProvider .getIfAvailable(); this.executeListenerProviders = executeListenerProviders; this.visitListenerProviders = visitListenerProvidersProvider.getIfAvailable(); }
@Override protected void configure() { bind(credentials).to(TwitterCredentials[].class); bind(alignments).to(DataSource.class); bind(sparqlLocation).named("SPARQLEndpoint").to(String.class); bind(ngramsEndpoint).named("NgramsEndpoint").to(String.class); bind(wikimachineEndpoint).named("WikimachineEndpoint").to(String.class); bind(lsaFilename).named("lsaFilename").to(String.class); bind(scaler).to(Scaler.class); bind(modelEndpoint).to(ModelEndpoint.class); bindFactory(TwitterFactory.class).to(Twitter[].class); bindFactory(ConnectionFactory.class).to(ConnectionProvider.class).in(Singleton.class); bind(AlignmentsService.class).to(AlignmentsService.class); bind(TwitterService.class).to(TwitterService.class); bind(KBAccessService.class).to(KBAccessService.class).in(Singleton.class); bind(WikimachineService.class).to(WikimachineService.class).in(Singleton.class); bind(AnnotationService.class).to(AnnotationService.class).in(Singleton.class); bind(MLService.class).to(MLService.class).in(Singleton.class); bind(ResourcesService.class).to(ResourcesService.class).in(Singleton.class); bind(NGramsService.class).to(NGramsService.class).in(Singleton.class); bind(OnlineAlignmentsService.class).to(OnlineAlignmentsService.class).in(Singleton.class); }
@Override protected void configure() { // bind default Configuration to DSLContext bindFactory(new DSLContextFactory(configurationMap.values().stream().findFirst().orElse(null))) .to(DSLContext.class) .in(RequestScoped.class); // bind multiple instances of Configuration and ConnectionProvider for Named DSLContext(s) for (final Configuration configuration : configurationMap.values()) { bind(configuration).to(Configuration.class); bind(configuration.connectionProvider()) .to(ConnectionProvider.class); } // bind a ValueFactoryProvider for Named DSLContext(s) bind(new DSLContextValueFactoryProvider(configurationMap)) .to(ValueFactoryProvider.class); }
@Override public void configure(final Env env, final Config conf, final Binder binder) { Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name)); HikariDataSource ds = (HikariDataSource) env.get(dskey) .orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey)); Configuration jooqconf = new DefaultConfiguration(); ConnectionProvider dscp = new DataSourceConnectionProvider(ds); jooqconf.set(JDBCUtils.dialect(ds.getDataSourceProperties().getProperty("url"))); jooqconf.set(dscp); jooqconf.set(new DefaultTransactionProvider(dscp)); if (callback != null) { callback.accept(jooqconf, conf); } ServiceKey serviceKey = env.serviceKey(); serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(jooqconf)); Provider<DSLContext> dsl = () -> DSL.using(jooqconf); serviceKey.generate(DSLContext.class, name, k -> binder.bind(k).toProvider(dsl)); }
@Bean public DSLContext getDSLContext() { HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setJdbcUrl(environment.getProperty("spring.datasource.url")); hikariDataSource.setUsername(environment.getProperty("spring.datasource.username")); hikariDataSource.setPassword(environment.getProperty("spring.datasource.password")); ConnectionProvider connectionProvider = new DataSourceConnectionProvider(hikariDataSource); org.jooq.Configuration configuration = new DefaultConfiguration().set(connectionProvider).set(SQLDialect.MYSQL); return DSL.using(configuration); }
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; }
@Produces @ApplicationScoped public ConnectionProvider produceConnectionProvider() { JooqConnectionProvider.log.info("Producing a connection provider"); return new DataSourceConnectionProvider(ds); }
@Produces @ApplicationScoped public ConnectionProvider produceConnectionProvider() { log.info("Producing a connection provider"); return new DataSourceConnectionProvider(ds); }
@Override public ConnectionProvider provide() { return provider; }
@Override public void dispose(ConnectionProvider instance) { }
public ConnectionProvider getConnectionProvider() { return connectionProvider; }
public void setConnectionProvider(ConnectionProvider connectionProvider) { this.connectionProvider = connectionProvider; }