javax.annotation.sql.DataSourceDefinition Java Examples

The following examples show how to use javax.annotation.sql.DataSourceDefinition. 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: HammockDataSource.java    From hammock with Apache License 2.0 6 votes vote down vote up
private DataSource createDelegate(DataSourceDefinition dataSourceDefinition) {
    HikariConfig config = new HikariConfig();
    if (dataSourceDefinition.url() != null) {
        config.setJdbcUrl(dataSourceDefinition.url());
    }
    if (dataSourceDefinition.user() != null) {
        config.setUsername(dataSourceDefinition.user());
        config.setPassword(dataSourceDefinition.password());
    }
    if (dataSourceDefinition.maxPoolSize() > 0) {
        config.setMaximumPoolSize(dataSourceDefinition.maxPoolSize());
    }
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    return wrap(new HikariDataSource(config));
}
 
Example #2
Source File: DataSourceExtension.java    From hammock with Apache License 2.0 6 votes vote down vote up
public void registerDataSources(@Observes AfterBeanDiscovery afterBeanDiscovery) {
    DataSourceDefinition defaultDataSource = dataSourceDefinitions.stream()
            .filter(dsd -> dsd.name().equals(EntityManagerFactoryProvider.DEFAULT_EMF))
            .findFirst()
            .orElse(null);
    Bean<ws.ament.hammock.jpa.DataSourceDefinition> defaultBean = beanDelegates
            .stream()
            .filter(b -> b.getName().equals(EntityManagerFactoryProvider.DEFAULT_EMF))
            .findFirst()
            .orElse(null);
    dataSourceDefinitions.stream().map(dataSourceDefinitionDataSourceDefinitionFunction)
            .map(dataSourceDefinition ->  new DataSourceDelegateBean(dataSourceDefinition.getName(),
                    () -> dataSourceDefinition))
            .forEach(afterBeanDiscovery::addBean);
    beanDelegates.stream().map(bean -> new DataSourceDelegateBean(bean.getName(), () -> bean.create(null)))
            .forEach(afterBeanDiscovery::addBean);
    databaseProducers.stream().map(producer -> new DataSourceDelegateBean(producer, create(producer)))
            .forEach(afterBeanDiscovery::addBean);
    if (defaultBean == null && defaultDataSource == null) {
        afterBeanDiscovery.addBean(new DefaultDataSourceBean());
    }
}
 
Example #3
Source File: HammockDataSource.java    From hammock with Apache License 2.0 4 votes vote down vote up
public HammockDataSource(DataSourceDefinition dataSourceDefinition) {
    this.name = dataSourceDefinition.name();
    this.delegate = createDelegate(dataSourceDefinition);
}
 
Example #4
Source File: DataSourceExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
public void findDataSourceDefinition(@Observes @WithAnnotations(DataSourceDefinition.class) ProcessAnnotatedType<?> pat) {
    DataSourceDefinition annotation = pat.getAnnotatedType().getJavaClass().getAnnotation(DataSourceDefinition.class);
    dataSourceDefinitions.add(annotation);
}
 
Example #5
Source File: DataSourceExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
public void findDataSourceDefinitionBeans(@Observes ProcessBean<ws.ament.hammock.jpa.DataSourceDefinition> processBean) {
    beanDelegates.add(processBean.getBean());
}
 
Example #6
Source File: DataSourceExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
public void findDataSourceProducers(@Observes ProcessProducer<?, ws.ament.hammock.jpa.DataSourceDefinition> processProducer) {
    Database database = processProducer.getAnnotatedMember().getAnnotation(Database.class);
    databaseProducers.add(database.value());
}
 
Example #7
Source File: DataSourceExtension.java    From hammock with Apache License 2.0 4 votes vote down vote up
private Supplier<ws.ament.hammock.jpa.DataSourceDefinition> create(String name) {
    return () -> CDI.current().select(ws.ament.hammock.jpa.DataSourceDefinition.class)
            .select(database(name))
            .get();
}
 
Example #8
Source File: FlywayExtension.java    From tutorials with MIT License 4 votes vote down vote up
public void detectDataSourceDefinition(@Observes @WithAnnotations(DataSourceDefinition.class) ProcessAnnotatedType<?> patEvent) {
    AnnotatedType at = patEvent.getAnnotatedType();
    dataSourceDefinition = at.getAnnotation(DataSourceDefinition.class);
}