Hibernate中Quartz的作用是什么
这篇文章将为大家详细讲解有关Hibernate 中Quartz的作用是什么,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,创新互联公司面向各种领域:混凝土泵车等成都网站设计、成都全网营销解决方案、网站设计等建站排名服务。
首先实现一个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,在不破坏其本来的逻辑和可配置性下进行了相应的修改.修改的是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;
}
}
关于Hibernate 中Quartz的作用是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
网站题目:Hibernate中Quartz的作用是什么
分享路径:http://scyanting.com/article/jejpsi.html