這篇文章將為大家詳細講解有關(guān)Hibernate 中Quartz的作用是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對外擴展宣傳的重要窗口,一個合格的網(wǎng)站不僅僅能為公司帶來巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺,創(chuàng)新互聯(lián)公司面向各種領(lǐng)域:混凝土泵車等成都網(wǎng)站設(shè)計、成都全網(wǎng)營銷解決方案、網(wǎng)站設(shè)計等建站排名服務(wù)。
首先實現(xiàn)一個Quartz中ConnectionProvider子類HibernateConnectionProvider
public class HibernateConnectionProvider implements ConnectionProvider { private Connection con = null; protected static ThreadLocal hibernateHolder = new ThreadLocal(); public Connection getConnection() throws SQLException { con = null; SessionFactoryImpl sessionFactory = null; sessionFactory = (SessionFactoryImpl) Global.getSessionFacotry(); con = sessionFactory.getConnectionProvider().getConnection(); return con; } public void shutdown() throws SQLException { // FIXME Auto-generated method stub } }
然后修改StdSchedulerFactory,在不破壞其本來的邏輯和可配置性下進行了相應(yīng)的修改.修改的是private Scheduler instantiate() throws SchedulerException方法,找到//Set up any DataSources段進行修改,代碼如下:
String[] dsNames = cfg.getPropertyGroups(PROP_DATASOURCE_PREFIX);
for (int i = 0; i < dsNames.length; i++) {
PropertiesParser pp = new PropertiesParser
(cfg.getPropertyGroup(PROP_DATASOURCE_PREFIX + "." + dsNames[i], true));
String dsDriver = pp.getStringProperty(PROP_DATASOURCE_DRIVER, null);
String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null);
boolean dsAlwaysLookup = pp.getBooleanProperty
(PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false);String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, "");
String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, "");
int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 3);
String providerClass = pp.getStringProperty
(PROP_DATASOURCE_PROVIDER_CLASS, null);String dsJndi = pp.getStringProperty(PROP_DATASOURCE_JNDI_URL, null);
String dsJndiInitial = pp.getStringProperty(PROP_DATASOURCE_JNDI_INITIAL, null);
String dsJndiProvider = pp.getStringProperty(PROP_DATASOURCE_JNDI_PROVDER, null);
String dsJndiPrincipal = pp.getStringProperty(PROP_DATASOURCE_JNDI_PRINCIPAL, null);
String dsJndiCredentials = pp.getStringProperty
(PROP_DATASOURCE_JNDI_CREDENTIALS, null);String dsValidation = pp.getStringProperty(PROP_DATASOURCE_VALIDATION_QUERY, null);
if (providerClass == null
|| providerClass.equals("")
|| providerClass.equals("org.quartz.utils.PoolingConnectionProvider")) {
if (dsDriver == null) {
initException = new SchedulerException
("Driver not specified for DataSource: "+ dsNames[i]);throw initException;
}
if (dsURL == null) {
initException = new SchedulerException
("DB URL not specified for DataSource: "+ dsNames[i]);throw initException;
}
try {
PoolingConnectionProvider cp = new PoolingConnectionProvider
(dsDriver, dsURL, dsUser, dsPass, dsCnt,dsValidation);dbMgr = DBConnectionManager.getInstance();
dbMgr.addConnectionProvider(dsNames[i], cp);
}
catch (SQLException sqle) {
initException = new SchedulerException
("Could not initialize DataSource: " + dsNames[i],sqle);throw initException;
}
}
else if (providerClass.equals("org.quartz.utils.JNDIConnectionProvider")) {
Properties props = null;
if (null != dsJndiInitial || null != dsJndiProvider
|| null != dsJndiPrincipal || null != dsJndiCredentials) {
props = new Properties();
if (dsJndiInitial != null)props.put(PROP_DATASOURCE_JNDI_INITIAL, dsJndiInitial);
if (dsJndiProvider != null)props.put(PROP_DATASOURCE_JNDI_PROVDER, dsJndiProvider);
if (dsJndiPrincipal != null)props.put(PROP_DATASOURCE_JNDI_PRINCIPAL,dsJndiPrincipal);
if (dsJndiCredentials != null)props.put
(PROP_DATASOURCE_JNDI_CREDENTIALS,dsJndiCredentials);}
JNDIConnectionProvider cp = new JNDIConnectionProvider(dsJndi,props, dsAlwaysLookup);
dbMgr = DBConnectionManager.getInstance();
dbMgr.addConnectionProvider(dsNames[i], cp);
}
else if (providerClass
.equals("org.quartz.utils.HibernateConnectionProvider")) {
HibernateConnectionProvider cp = new HibernateConnectionProvider();
dbMgr = DBConnectionManager.getInstance();
dbMgr.addConnectionProvider(dsNames[i], cp);
}
else {
initException = new SchedulerException
("Provider_Class not Supported: " + providerClass);throw initException;
}
}
關(guān)于Hibernate 中Quartz的作用是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。