当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionProvider类代码示例

本文整理汇总了Java中org.quartz.utils.ConnectionProvider的典型用法代码示例。如果您正苦于以下问题:Java ConnectionProvider类的具体用法?Java ConnectionProvider怎么用?Java ConnectionProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionProvider类属于org.quartz.utils包,在下文中一共展示了ConnectionProvider类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import org.quartz.utils.ConnectionProvider; //导入依赖的package包/类
@Override
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler)
		throws SchedulerConfigException {

	// Absolutely needs thread-bound DataSource to initialize.
	this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();
	if (this.dataSource == null) {
		throw new SchedulerConfigException(
			"No local DataSource found for configuration - " +
			"'dataSource' property must be set on SchedulerFactoryBean");
	}

	// Configure transactional connection settings for Quartz.
	setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName());
	setDontSetAutoCommitFalse(true);

	// Register transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Return a transactional Connection, if any.
					return DataSourceUtils.doGetConnection(dataSource);
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// Non-transactional DataSource is optional: fall back to default
	// DataSource if not explicitly specified.
	DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource();
	final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource);

	// Configure non-transactional connection settings for Quartz.
	setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName());

	// Register non-transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			NON_TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				@Override
				public Connection getConnection() throws SQLException {
					// Always return a non-transactional Connection.
					return nonTxDataSourceToUse.getConnection();
				}
				@Override
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// No, if HSQL is the platform, we really don't want to use locks...
	try {
		String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString();
		productName = JdbcUtils.commonDatabaseName(productName);
		if (productName != null && productName.toLowerCase().contains("hsql")) {
			setUseDBLocks(false);
			setLockHandler(new SimpleSemaphore());
		}
	}
	catch (MetaDataAccessException ex) {
		logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
	}

	super.initialize(loadHelper, signaler);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:81,代码来源:LocalDataSourceJobStore.java

示例2: initialize

import org.quartz.utils.ConnectionProvider; //导入依赖的package包/类
@Override
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler)
		throws SchedulerConfigException {

	// Absolutely needs thread-bound DataSource to initialize.
	this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();
	if (this.dataSource == null) {
		throw new SchedulerConfigException(
			"No local DataSource found for configuration - " +
			"'dataSource' property must be set on SchedulerFactoryBean");
	}

	// Configure transactional connection settings for Quartz.
	setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName());
	setDontSetAutoCommitFalse(true);

	// Register transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				public Connection getConnection() throws SQLException {
					// Return a transactional Connection, if any.
					return DataSourceUtils.doGetConnection(dataSource);
				}
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// Non-transactional DataSource is optional: fall back to default
	// DataSource if not explicitly specified.
	DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource();
	final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource);

	// Configure non-transactional connection settings for Quartz.
	setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName());

	// Register non-transactional ConnectionProvider for Quartz.
	DBConnectionManager.getInstance().addConnectionProvider(
			NON_TX_DATA_SOURCE_PREFIX + getInstanceName(),
			new ConnectionProvider() {
				public Connection getConnection() throws SQLException {
					// Always return a non-transactional Connection.
					return nonTxDataSourceToUse.getConnection();
				}
				public void shutdown() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
				/* Quartz 2.2 initialize method */
				public void initialize() {
					// Do nothing - a Spring-managed DataSource has its own lifecycle.
				}
			}
	);

	// No, if HSQL is the platform, we really don't want to use locks...
	try {
		String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString();
		productName = JdbcUtils.commonDatabaseName(productName);
		if (productName != null && productName.toLowerCase().contains("hsql")) {
			setUseDBLocks(false);
			setLockHandler(new SimpleSemaphore());
		}
	}
	catch (MetaDataAccessException ex) {
		logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken.");
	}

	super.initialize(loadHelper, signaler);

}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:77,代码来源:LocalDataSourceJobStore.java


注:本文中的org.quartz.utils.ConnectionProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。