org.quartz.utils.DBConnectionManager Java Examples

The following examples show how to use org.quartz.utils.DBConnectionManager. 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: JobStoreCMT.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void shutdown() {

    super.shutdown();
    
    try {
        DBConnectionManager.getInstance().shutdown(getNonManagedTXDataSource());
    } catch (SQLException sqle) {
        getLog().warn("Database connection shutdown unsuccessful.", sqle);
    }
}
 
Example #2
Source File: JobStoreCMT.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
public void shutdown() {

        super.shutdown();
        
        try {
            DBConnectionManager.getInstance().shutdown(getNonManagedTXDataSource());
        } catch (SQLException sqle) {
            getLog().warn("Database connection shutdown unsuccessful.", sqle);
        }
    }
 
Example #3
Source File: JobStoreJdbcProvider.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private JobStore createJobStore() {
  try {
    connectionProvider.initialize();
    DBConnectionManager.getInstance().addConnectionProvider(QUARTZ_DS, connectionProvider);
    JobStoreTX delegate = new JobStoreTX();
    delegate.setDataSource(QUARTZ_DS);
    delegate.setDriverDelegateClass(getDriverDelegateClass());
    return delegate;
  }
  catch (Exception e) {
    log.error("Unable create job store", e);
    return null;
  }
}
 
Example #4
Source File: OrientQuartzJdbcIT.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void before() throws Exception {
  try (ODatabaseDocumentTx db = database.getInstance().acquire()) {
    OrientQuartzSchema.register(db);
    dbUrl = db.getURL();
  }
  SimpleThreadPool threadPool = new SimpleThreadPool(3, Thread.NORM_PRIORITY);
  threadPool.initialize();
  OrientConnectionProvider connProvider = new OrientConnectionProvider();
  connProvider.setConnectionString(dbUrl);
  connProvider.setUser("admin");
  connProvider.setPassword("admin");
  connProvider.setUsePool(true);
  connProvider.setPoolMin(3);
  connProvider.setPoolMax(3);
  connProvider.initialize();
  DBConnectionManager.getInstance().addConnectionProvider("orientDS", connProvider);
  DBConnectionManager.getInstance().getConnection("orientDS");
  JobStoreTX jobStore = new JobStoreTX();
  jobStore.setDataSource("orientDS");
  jobStore.setDriverDelegateClass(OrientDelegate.class.getName());
  DirectSchedulerFactory.getInstance().createScheduler("nexus", "1", threadPool, jobStore);
  scheduler = DirectSchedulerFactory.getInstance().getScheduler("nexus");
  scheduler.clear();

  scheduler.start();
}
 
Example #5
Source File: LocalDataSourceJobStore.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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");
		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);

}
 
Example #6
Source File: LocalDataSourceJobStore.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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");
		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);

}
 
Example #7
Source File: LocalDataSourceJobStore.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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);

}
 
Example #8
Source File: LocalDataSourceJobStore.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@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);

}