1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.scheduler.quartz;
24  
25  import com.liferay.portal.dao.db.DB2DB;
26  import com.liferay.portal.dao.db.HypersonicDB;
27  import com.liferay.portal.dao.db.PostgreSQLDB;
28  import com.liferay.portal.dao.db.SQLServerDB;
29  import com.liferay.portal.dao.db.SybaseDB;
30  import com.liferay.portal.kernel.dao.db.DB;
31  import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
32  import com.liferay.portal.kernel.log.Log;
33  import com.liferay.portal.kernel.log.LogFactoryUtil;
34  
35  import org.quartz.impl.jdbcjobstore.DB2v8Delegate;
36  import org.quartz.impl.jdbcjobstore.DriverDelegate;
37  import org.quartz.impl.jdbcjobstore.HSQLDBDelegate;
38  import org.quartz.impl.jdbcjobstore.JobStoreTX;
39  import org.quartz.impl.jdbcjobstore.MSSQLDelegate;
40  import org.quartz.impl.jdbcjobstore.NoSuchDelegateException;
41  import org.quartz.impl.jdbcjobstore.PostgreSQLDelegate;
42  import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
43  
44  /**
45   * <a href="PortalJobStore.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   */
49  public class PortalJobStore extends JobStoreTX {
50  
51      protected DriverDelegate getDelegate() throws NoSuchDelegateException {
52          if (_driverDelegate != null) {
53              return _driverDelegate;
54          }
55  
56          try {
57              Class<?> driverDelegateClass = StdJDBCDelegate.class;
58  
59              DB db = DBFactoryUtil.getDB();
60  
61              if (db instanceof DB2DB) {
62                  driverDelegateClass = DB2v8Delegate.class;
63              }
64              else if (db instanceof HypersonicDB) {
65                  driverDelegateClass = HSQLDBDelegate.class;
66              }
67              else if (db instanceof PostgreSQLDB) {
68                  driverDelegateClass = PostgreSQLDelegate.class;
69              }
70              else if (db instanceof SQLServerDB) {
71                  driverDelegateClass = MSSQLDelegate.class;
72              }
73              else if (db instanceof SybaseDB) {
74                  driverDelegateClass = MSSQLDelegate.class;
75              }
76  
77              if (_log.isDebugEnabled()) {
78                  _log.debug("Instantiating " + driverDelegateClass);
79              }
80  
81              setDriverDelegateClass(driverDelegateClass.getName());
82  
83              _driverDelegate = super.getDelegate();
84  
85              if (_log.isInfoEnabled()) {
86                  _log.info(
87                      "Using driver delegate " +
88                          _driverDelegate.getClass().getName());
89              }
90  
91              return _driverDelegate;
92          }
93          catch (NoSuchDelegateException nsde) {
94              throw nsde;
95          }
96          catch (Exception e) {
97              throw new NoSuchDelegateException(e.getMessage());
98          }
99      }
100 
101     private static Log _log = LogFactoryUtil.getLog(PortalJobStore.class);
102 
103     private DriverDelegate _driverDelegate;
104 
105 }