001
014
015 package com.liferay.portal.scheduler.quartz;
016
017 import com.liferay.portal.kernel.dao.db.DB;
018 import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021
022 import org.quartz.impl.jdbcjobstore.DB2v8Delegate;
023 import org.quartz.impl.jdbcjobstore.DriverDelegate;
024 import org.quartz.impl.jdbcjobstore.HSQLDBDelegate;
025 import org.quartz.impl.jdbcjobstore.JobStoreTX;
026 import org.quartz.impl.jdbcjobstore.MSSQLDelegate;
027 import org.quartz.impl.jdbcjobstore.NoSuchDelegateException;
028 import org.quartz.impl.jdbcjobstore.PostgreSQLDelegate;
029 import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
030 import org.quartz.impl.jdbcjobstore.SybaseDelegate;
031
032
035 public class PortalJobStore extends JobStoreTX {
036
037 @Override
038 protected DriverDelegate getDelegate() throws NoSuchDelegateException {
039 if (_driverDelegate != null) {
040 return _driverDelegate;
041 }
042
043 try {
044 Class<?> driverDelegateClass = StdJDBCDelegate.class;
045
046 DB db = DBFactoryUtil.getDB();
047
048 String dbType = db.getType();
049
050 if (dbType.equals(DB.TYPE_DB2)) {
051 driverDelegateClass = DB2v8Delegate.class;
052 }
053 else if (dbType.equals(DB.TYPE_HYPERSONIC)) {
054 driverDelegateClass = HSQLDBDelegate.class;
055 }
056 else if (dbType.equals(DB.TYPE_POSTGRESQL)) {
057 driverDelegateClass = PostgreSQLDelegate.class;
058 }
059 else if (dbType.equals(DB.TYPE_SQLSERVER)) {
060 driverDelegateClass = MSSQLDelegate.class;
061 }
062 else if (dbType.equals(DB.TYPE_SYBASE)) {
063 driverDelegateClass = SybaseDelegate.class;
064 }
065
066 if (_log.isDebugEnabled()) {
067 _log.debug("Instantiating " + driverDelegateClass);
068 }
069
070 setDriverDelegateClass(driverDelegateClass.getName());
071
072 _driverDelegate = super.getDelegate();
073
074 if (_log.isInfoEnabled()) {
075 _log.info(
076 "Using driver delegate " +
077 _driverDelegate.getClass().getName());
078 }
079
080 return _driverDelegate;
081 }
082 catch (NoSuchDelegateException nsde) {
083 throw nsde;
084 }
085 catch (Exception e) {
086 throw new NoSuchDelegateException(e.getMessage());
087 }
088 }
089
090 private static Log _log = LogFactoryUtil.getLog(PortalJobStore.class);
091
092 private DriverDelegate _driverDelegate;
093
094 }