001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.scheduler.quartz;
016    
017    import com.liferay.portal.dao.db.DB2DB;
018    import com.liferay.portal.dao.db.HypersonicDB;
019    import com.liferay.portal.dao.db.PostgreSQLDB;
020    import com.liferay.portal.dao.db.SQLServerDB;
021    import com.liferay.portal.dao.db.SybaseDB;
022    import com.liferay.portal.kernel.dao.db.DB;
023    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
024    import com.liferay.portal.kernel.log.Log;
025    import com.liferay.portal.kernel.log.LogFactoryUtil;
026    
027    import org.quartz.impl.jdbcjobstore.DB2v8Delegate;
028    import org.quartz.impl.jdbcjobstore.DriverDelegate;
029    import org.quartz.impl.jdbcjobstore.HSQLDBDelegate;
030    import org.quartz.impl.jdbcjobstore.JobStoreTX;
031    import org.quartz.impl.jdbcjobstore.MSSQLDelegate;
032    import org.quartz.impl.jdbcjobstore.NoSuchDelegateException;
033    import org.quartz.impl.jdbcjobstore.PostgreSQLDelegate;
034    import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
035    
036    /**
037     * @author Brian Wing Shun Chan
038     */
039    public class PortalJobStore extends JobStoreTX {
040    
041            protected DriverDelegate getDelegate() throws NoSuchDelegateException {
042                    if (_driverDelegate != null) {
043                            return _driverDelegate;
044                    }
045    
046                    try {
047                            Class<?> driverDelegateClass = StdJDBCDelegate.class;
048    
049                            DB db = DBFactoryUtil.getDB();
050    
051                            if (db instanceof DB2DB) {
052                                    driverDelegateClass = DB2v8Delegate.class;
053                            }
054                            else if (db instanceof HypersonicDB) {
055                                    driverDelegateClass = HSQLDBDelegate.class;
056                            }
057                            else if (db instanceof PostgreSQLDB) {
058                                    driverDelegateClass = PostgreSQLDelegate.class;
059                            }
060                            else if (db instanceof SQLServerDB) {
061                                    driverDelegateClass = MSSQLDelegate.class;
062                            }
063                            else if (db instanceof SybaseDB) {
064                                    driverDelegateClass = MSSQLDelegate.class;
065                            }
066    
067                            if (_log.isDebugEnabled()) {
068                                    _log.debug("Instantiating " + driverDelegateClass);
069                            }
070    
071                            setDriverDelegateClass(driverDelegateClass.getName());
072    
073                            _driverDelegate = super.getDelegate();
074    
075                            if (_log.isInfoEnabled()) {
076                                    _log.info(
077                                            "Using driver delegate " +
078                                                    _driverDelegate.getClass().getName());
079                            }
080    
081                            return _driverDelegate;
082                    }
083                    catch (NoSuchDelegateException nsde) {
084                            throw nsde;
085                    }
086                    catch (Exception e) {
087                            throw new NoSuchDelegateException(e.getMessage());
088                    }
089            }
090    
091            private static Log _log = LogFactoryUtil.getLog(PortalJobStore.class);
092    
093            private DriverDelegate _driverDelegate;
094    
095    }