net.ttddyy.dsproxy.support.ProxyDataSourceBuilder Java Examples

The following examples show how to use net.ttddyy.dsproxy.support.ProxyDataSourceBuilder. 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: ProxyDataSourceDecorator.java    From spring-boot-data-source-decorator with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource decorate(String beanName, DataSource dataSource) {
    ProxyDataSourceBuilder proxyDataSourceBuilder = ProxyDataSourceBuilder.create();
    DataSourceProxyProperties datasourceProxy = dataSourceDecoratorProperties.getDatasourceProxy();
    proxyDataSourceBuilderConfigurer.configure(proxyDataSourceBuilder, datasourceProxy);
    String dataSourceName = dataSourceNameResolver.resolveDataSourceName(dataSource);
    return proxyDataSourceBuilder.dataSource(dataSource).name(dataSourceName).build();
}
 
Example #2
Source File: ResourceLocalReleaseAfterStatementConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #3
Source File: JPATransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #4
Source File: JTATransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
@DependsOn(value = {"btmConfig", "actualDataSource"})
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #5
Source File: HibernateTransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #6
Source File: BehaviorDrivenInheritanceConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #7
Source File: DataSourceProxyConnectionProvider.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(Map configValues) {
    super.configure(configValues);
    DataSource dataSource = ProxyDataSourceBuilder
            .create(getDataSource())
            .name(getClass().getSimpleName())
            .listener(new SLF4JQueryLoggingListener())
            .build();
    super.setDataSource(dataSource);
}
 
Example #8
Source File: AbstractJPAConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
private DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
        .create(actualDataSource())
        .name(DATA_SOURCE_PROXY_NAME)
        .listener(loggingListener)
        .build();
}
 
Example #9
Source File: AbstractJTATransactionManagerConfiguration.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@DependsOn(value = {"btmConfig", "actualDataSource"})
public DataSource dataSource() {
    SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
    loggingListener.setQueryLogEntryCreator(new InlineQueryLogEntryCreator());
    return ProxyDataSourceBuilder
            .create(actualDataSource())
            .name(DATA_SOURCE_PROXY_NAME)
            .listener(loggingListener)
            .build();
}
 
Example #10
Source File: DataSourceTracer.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@CheckReturnValue
public DataSource trace(final DataSource dataSource) {
    return ProxyDataSourceBuilder.create(dataSource)
            .listener(new TracingQueryExecutionListener(
                    tracer, operationName, lifecycle, activation, decorator))
            .build();
}
 
Example #11
Source File: AbstractTest.java    From hibernate-master-class with Apache License 2.0 5 votes vote down vote up
protected DataSource newDataSource() {
    if (proxyDataSource()) {
        ChainListener listener = new ChainListener();
        SLF4JQueryLoggingListener loggingListener = new SLF4JQueryLoggingListener();
        loggingListener.setQueryLogEntryCreator(new AbstractTest.InlineQueryLogEntryCreator());
        listener.addListener(loggingListener);
        return ProxyDataSourceBuilder
                .create(getDataSourceProvider().dataSource())
                .name(getClass().getName())
                .listener(listener)
                .build();
    } else {
        return getDataSourceProvider().dataSource();
    }
}
 
Example #12
Source File: DatasourceProxyBeanPostProcessor.java    From tutorials with MIT License 5 votes vote down vote up
public ProxyDataSourceInterceptor(final DataSource dataSource) {
    this.dataSource = ProxyDataSourceBuilder.create(dataSource)
            .name("MyDS")
            .multiline()
            .logQueryBySlf4j(SLF4JLogLevel.INFO)
            .listener(new DataSourceQueryCountListener())
            .build();
}
 
Example #13
Source File: ProxyDataSourceBuilderConfigurer.java    From spring-boot-data-source-decorator with Apache License 2.0 4 votes vote down vote up
public void configure(ProxyDataSourceBuilder proxyDataSourceBuilder, DataSourceProxyProperties datasourceProxy) {
    switch (datasourceProxy.getLogging()) {
        case SLF4J: {
            if (datasourceProxy.getQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logQueryBySlf4j(toSlf4JLogLevel(datasourceProxy.getQuery().getLogLevel()), datasourceProxy.getQuery().getLoggerName());
            }
            if (datasourceProxy.getSlowQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logSlowQueryBySlf4j(datasourceProxy.getSlowQuery().getThreshold(), TimeUnit.SECONDS,
                        toSlf4JLogLevel(datasourceProxy.getSlowQuery().getLogLevel()), datasourceProxy.getSlowQuery().getLoggerName());
            }
            break;
        }
        case JUL: {
            if (datasourceProxy.getQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logQueryByJUL(toJULLogLevel(datasourceProxy.getQuery().getLogLevel()), datasourceProxy.getQuery().getLoggerName());
            }
            if (datasourceProxy.getSlowQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logSlowQueryByJUL(datasourceProxy.getSlowQuery().getThreshold(), TimeUnit.SECONDS,
                        toJULLogLevel(datasourceProxy.getSlowQuery().getLogLevel()), datasourceProxy.getSlowQuery().getLoggerName());
            }
            break;
        }
        case COMMONS: {
            if (datasourceProxy.getQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logQueryByCommons(toCommonsLogLevel(datasourceProxy.getQuery().getLogLevel()), datasourceProxy.getQuery().getLoggerName());
            }
            if (datasourceProxy.getSlowQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logSlowQueryByCommons(datasourceProxy.getSlowQuery().getThreshold(), TimeUnit.SECONDS,
                        toCommonsLogLevel(datasourceProxy.getSlowQuery().getLogLevel()), datasourceProxy.getSlowQuery().getLoggerName());
            }
            break;
        }
        case SYSOUT: {
            if (datasourceProxy.getQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logQueryToSysOut();
            }
            if (datasourceProxy.getSlowQuery().isEnableLogging()) {
                proxyDataSourceBuilder.logSlowQueryToSysOut(datasourceProxy.getSlowQuery().getThreshold(), TimeUnit.SECONDS);
            }
            break;
        }
    }
    if (datasourceProxy.isMultiline() && datasourceProxy.isJsonFormat()) {
        log.warn("Found opposite multiline and json format, multiline will be used (may depend on library version)");
    }
    if (datasourceProxy.isMultiline()) {
        proxyDataSourceBuilder.multiline();
    }
    if (datasourceProxy.isJsonFormat()) {
        proxyDataSourceBuilder.asJson();
    }
    if (datasourceProxy.isCountQuery()) {
        proxyDataSourceBuilder.countQuery(queryCountStrategy);
    }
    if (listeners != null) {
        listeners.forEach(proxyDataSourceBuilder::listener);
    }
    if (methodExecutionListeners != null) {
        methodExecutionListeners.forEach(proxyDataSourceBuilder::methodListener);
    }
    if (parameterTransformer != null) {
        proxyDataSourceBuilder.parameterTransformer(parameterTransformer);
    }
    if (queryTransformer != null) {
        proxyDataSourceBuilder.queryTransformer(queryTransformer);
    }
    if (resultSetProxyLogicFactory != null) {
        proxyDataSourceBuilder.proxyResultSet(resultSetProxyLogicFactory);
    }
    if (connectionIdManagerProvider != null) {
        proxyDataSourceBuilder.connectionIdManager(connectionIdManagerProvider.get());
    }
}
 
Example #14
Source File: DataSourceProxyBeanPostProcessor.java    From POC with Apache License 2.0 4 votes vote down vote up
ProxyDataSourceInterceptor(final DataSource dataSource) {
	super();
	this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("DATA_SOURCE_PROXY")
			.logQueryBySlf4j(SLF4JLogLevel.INFO).multiline().countQuery()
			.logSlowQueryBySlf4j(5, TimeUnit.SECONDS).build();
}
 
Example #15
Source File: DatasourceProxyBeanPostProcessor.java    From tutorials with MIT License 4 votes vote down vote up
public ProxyDataSourceInterceptor(final DataSource dataSource) {
    this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build();
}