001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
033     * @author Brian Wing Shun Chan
034     */
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    }