Author: mriou
Date: Mon Dec 11 13:47:32 2006
New Revision: 485889

URL: http://svn.apache.org/viewvc?view=rev&rev=485889
Log:
Small tweak for SQL Server support (made necessary by Quartz).

Modified:
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
    
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java

Modified: 
incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java?view=diff&rev=485889&r1=485888&r2=485889
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java 
(original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java 
Mon Dec 11 13:47:32 2006
@@ -110,6 +110,8 @@
 
     private BpelServerConnector _connector;
 
+    private String _dbType;
+
     public void init(ServletConfig config, AxisConfiguration axisConf) throws 
ServletException {
         _axisConfig = axisConf;
         _appRoot = new 
File(config.getServletContext().getRealPath("/WEB-INF"));
@@ -416,6 +418,12 @@
                 else __log.error(errmsg);
             }
         }
+        if (properties.get(Environment.DIALECT) != null) {
+            String dialect = (String) properties.get(Environment.DIALECT);
+            if (dialect.equals("org.hibernate.dialect.SQLServerDialect"))
+                _dbType = "sqlserver";
+            else _dbType = "other";
+        }
         
         SessionManager sm = new SessionManager(properties, _datasource, 
_txMgr);
         _daoCF = new BpelDAOConnectionFactoryImpl(sm);
@@ -438,6 +446,7 @@
         _scheduler.setExecutorService(_executorService, 20);
         _scheduler.setTransactionManager(_txMgr);
         _scheduler.setDataSource(_datasource);
+        if ("sqlserver".equals(_dbType)) _scheduler.setSqlServer(true);
         _scheduler.init();
 
         _server.setDaoConnectionFactory(_daoCF);

Modified: 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java?view=diff&rev=485889&r1=485888&r2=485889
==============================================================================
--- 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
 (original)
+++ 
incubator/ode/trunk/bpel-scheduler-quartz/src/main/java/org/apache/ode/bpel/scheduler/quartz/QuartzSchedulerImpl.java
 Mon Dec 11 13:47:32 2006
@@ -50,271 +50,277 @@
  */
 public class QuartzSchedulerImpl implements Scheduler {
 
-  protected final Log __log = LogFactory.getLog(getClass());
+    protected final Log __log = LogFactory.getLog(getClass());
 
-  private static final Map<String, QuartzSchedulerImpl> __instanceMap = 
Collections
-      .synchronizedMap(new HashMap<String, QuartzSchedulerImpl>());
+    private static final Map<String, QuartzSchedulerImpl> __instanceMap = 
Collections
+            .synchronizedMap(new HashMap<String, QuartzSchedulerImpl>());
 
-  protected BpelServer _server;
+    protected BpelServer _server;
 
-  private org.quartz.Scheduler _quartz;
+    private org.quartz.Scheduler _quartz;
 
-  private final String _id;
-
-  private ExecutorService _executorSvc;
-
-  private int _threads;
-
-  private DataSource _managedDS;
-
-  private TransactionManager _txm;
-
-  
-  public QuartzSchedulerImpl() {
-    _id = "ODE";
-  }
-
-  public void setBpelServer(BpelServer server) {
-    _server = server;
-  }
-
-  public void setExecutorService(ExecutorService es, int threads) {
-    _executorSvc = es;
-    _threads = threads;
-  }
-
-  public void setDataSource(DataSource managedDs) {
-    _managedDS = managedDs;
-  }
-
-  public void setTransactionManager(TransactionManager txm) {
-    _txm = txm;
-  }
-
-  public void init() throws ContextException {
-    if (_server == null)
-      throw new NullPointerException("BpelServer not set!");
-    if (_executorSvc == null)
-      throw new NullPointerException("ExeuctorService not set!");
-    if (_managedDS == null)
-      throw new NullPointerException("Managed DataSource name not set!");
-    if (_txm == null)
-      throw new NullPointerException("TransactionManager not set!");
-      
-    DBConnectionManager.getInstance().addConnectionProvider("managed",
-        new DataSourceConnectionProvider(_managedDS));
-    JobStoreJTA jobStore = new JobStoreJTA(_txm);
-    jobStore.setDataSource("managed");
-    
-    try {
-      _quartz= createScheduler("ODEScheduler",_id,
-          new QuartzThreadPoolExecutorServiceImpl(_executorSvc, _threads),
-          jobStore);
-      _quartz.getSchedulerInstanceId();
-      __instanceMap.put(_id, this);
-    } catch (Exception ex) {
-      throw new ContextException(ex.getMessage(),ex);
-    }
-  }  
-  
-  public void start() {
-    if (_quartz == null)
-      throw new IllegalStateException("init() not called!");
-    
-    try {
-      _quartz.start();
-    } catch (SchedulerException e) {
-      throw new ContextException("Error starting Quartz.", e);
-    }
-  }
-  
-  public void stop() {
-    try {
-      _quartz.standby();
-    } catch (SchedulerException e) {
-      throw new ContextException("Error stopping Quartz.", e);
-    }
-    
-  }
-  
-  public void shutdown() {
-    try {
-      _quartz.shutdown();
-    } catch (Exception except) {
-      throw new RuntimeException(except);
-    } finally {
-      __instanceMap.remove(_id);
-    }
-  }
-
-  public String schedulePersistedJob(Map<String, Object> detail, Date when)
-      throws ContextException {
-    return schedule(detail, when, false, false);
-  }
-
-  protected String schedule(Map<String, Object> detail, Date when,
-      boolean volatil, boolean notx) {
-    if (when == null)
-      when = new Date();
-    JobDetail jobDetail = new JobDetail(new GUID().toString(), null,
-        JobImpl.class);
-    HashMap<String, Object> mcopy = new HashMap<String, Object>(detail);
-    mcopy.put("__scheduler", _id);
-
-    JobDataMap jdm = new JobDataMap(mcopy);
-    jobDetail.setJobDataMap(jdm);
-    jobDetail.setDurability(false);
-    jobDetail.setVolatility(volatil);
-    jobDetail.setRequestsRecovery(true);
-    Trigger trigger = new SimpleTrigger(jobDetail.getName() + ".trigger",
-        org.quartz.Scheduler.DEFAULT_GROUP, when, null, 0, 0L);
-      trigger.setVolatility(volatil);
-
-    try {
-      _quartz.scheduleJob(jobDetail, trigger);
-    } catch (SchedulerException e) {
-      String errmsg = "Quartz failure in schedulePersistentJob";
-      __log.error(errmsg, e);
-      throw new ContextException(errmsg, e);
-    }
-    return jobDetail.getName();
-  }
-
-  public String scheduleVolatileJob(boolean transacted,
-      Map<String, Object> detail, Date when) throws ContextException {
-    return schedule(detail, when, true, !transacted);
-  }
-
-  public void cancelJob(String jobId) throws ContextException {
-    try {
-      _quartz.deleteJob(jobId, jobId + ".trigger");
-    } catch (SchedulerException e) {
-      String errmsg = "Quartz failure in cancelJob";
-      __log.error(errmsg, e);
-      throw new ContextException(errmsg, e);
-    }
-  }
-
-  public <T> T execTransaction(Callable<T> transaction) throws Exception,
-      ContextException {
-
-    try {
-      begin();
-    } catch (Exception ex) {
-      String errmsg = "Failed to start transaction.";
-      __log.error(errmsg, ex);
-      throw new ContextException(errmsg, ex);
-    }
-
-    boolean success = false;
-    try {
-      T retval = transaction.call();
-      success = true;
-      return retval;
-    } finally {
-      if (success)
+    private final String _id;
+
+    private ExecutorService _executorSvc;
+
+    private int _threads;
+
+    private DataSource _managedDS;
+
+    private TransactionManager _txm;
+
+    private boolean isSqlServer = false;
+
+    public QuartzSchedulerImpl() {
+        _id = "ODE";
+    }
+
+    public void setBpelServer(BpelServer server) {
+        _server = server;
+    }
+
+    public void setExecutorService(ExecutorService es, int threads) {
+        _executorSvc = es;
+        _threads = threads;
+    }
+
+    public void setDataSource(DataSource managedDs) {
+        _managedDS = managedDs;
+    }
+
+    public void setTransactionManager(TransactionManager txm) {
+        _txm = txm;
+    }
+
+    public void init() throws ContextException {
+        if (_server == null)
+            throw new NullPointerException("BpelServer not set!");
+        if (_executorSvc == null)
+            throw new NullPointerException("ExeuctorService not set!");
+        if (_managedDS == null)
+            throw new NullPointerException("Managed DataSource name not set!");
+        if (_txm == null)
+            throw new NullPointerException("TransactionManager not set!");
+
+        DBConnectionManager.getInstance().addConnectionProvider("managed",
+                new DataSourceConnectionProvider(_managedDS));
+        JobStoreJTA jobStore = new JobStoreJTA(_txm);
+        jobStore.setDataSource("managed");
+
+        try {
+            _quartz= createScheduler("ODEScheduler",_id,
+                    new QuartzThreadPoolExecutorServiceImpl(_executorSvc, 
_threads),
+                    jobStore);
+            _quartz.getSchedulerInstanceId();
+            __instanceMap.put(_id, this);
+        } catch (Exception ex) {
+            throw new ContextException(ex.getMessage(),ex);
+        }
+    }
+
+    public void start() {
+        if (_quartz == null)
+            throw new IllegalStateException("init() not called!");
+
+        try {
+            _quartz.start();
+        } catch (SchedulerException e) {
+            throw new ContextException("Error starting Quartz.", e);
+        }
+    }
+
+    public void stop() {
+        try {
+            _quartz.standby();
+        } catch (SchedulerException e) {
+            throw new ContextException("Error stopping Quartz.", e);
+        }
+
+    }
+
+    public void shutdown() {
+        try {
+            _quartz.shutdown();
+        } catch (Exception except) {
+            throw new RuntimeException(except);
+        } finally {
+            __instanceMap.remove(_id);
+        }
+    }
+
+    public String schedulePersistedJob(Map<String, Object> detail, Date when)
+            throws ContextException {
+        return schedule(detail, when, false, false);
+    }
+
+    protected String schedule(Map<String, Object> detail, Date when,
+                              boolean volatil, boolean notx) {
+        if (when == null)
+            when = new Date();
+        JobDetail jobDetail = new JobDetail(new GUID().toString(), null,
+                JobImpl.class);
+        HashMap<String, Object> mcopy = new HashMap<String, Object>(detail);
+        mcopy.put("__scheduler", _id);
+
+        JobDataMap jdm = new JobDataMap(mcopy);
+        jobDetail.setJobDataMap(jdm);
+        jobDetail.setDurability(false);
+        jobDetail.setVolatility(volatil);
+        jobDetail.setRequestsRecovery(true);
+        Trigger trigger = new SimpleTrigger(jobDetail.getName() + ".trigger",
+                org.quartz.Scheduler.DEFAULT_GROUP, when, null, 0, 0L);
+        trigger.setVolatility(volatil);
+
+        try {
+            _quartz.scheduleJob(jobDetail, trigger);
+        } catch (SchedulerException e) {
+            String errmsg = "Quartz failure in schedulePersistentJob";
+            __log.error(errmsg, e);
+            throw new ContextException(errmsg, e);
+        }
+        return jobDetail.getName();
+    }
+
+    public String scheduleVolatileJob(boolean transacted,
+                                      Map<String, Object> detail, Date when) 
throws ContextException {
+        return schedule(detail, when, true, !transacted);
+    }
+
+    public void cancelJob(String jobId) throws ContextException {
         try {
-          commit();
+            _quartz.deleteJob(jobId, jobId + ".trigger");
+        } catch (SchedulerException e) {
+            String errmsg = "Quartz failure in cancelJob";
+            __log.error(errmsg, e);
+            throw new ContextException(errmsg, e);
+        }
+    }
+
+    public <T> T execTransaction(Callable<T> transaction) throws Exception,
+            ContextException {
+
+        try {
+            begin();
         } catch (Exception ex) {
-          String errmsg = "Failed to commit transaction.";
-          __log.error(errmsg, ex);
-          throw new ContextException(errmsg, ex);
+            String errmsg = "Failed to start transaction.";
+            __log.error(errmsg, ex);
+            throw new ContextException(errmsg, ex);
         }
-      else
+
+        boolean success = false;
         try {
-          rollback();
+            T retval = transaction.call();
+            success = true;
+            return retval;
+        } finally {
+            if (success)
+                try {
+                    commit();
+                } catch (Exception ex) {
+                    String errmsg = "Failed to commit transaction.";
+                    __log.error(errmsg, ex);
+                    throw new ContextException(errmsg, ex);
+                }
+            else
+                try {
+                    rollback();
+                } catch (Exception ex) {
+                    String errmsg = "Failed to rollback transaction.";
+                    __log.error(errmsg, ex);
+                    throw new ContextException(errmsg, ex);
+                }
+        }
+    }
+
+    protected void rollback() throws Exception {
+        try {
+            _txm.rollback();
         } catch (Exception ex) {
-          String errmsg = "Failed to rollback transaction.";
-          __log.error(errmsg, ex);
-          throw new ContextException(errmsg, ex);
-        }
-    }
-  }
-
-  protected void rollback() throws Exception {
-    try {
-      _txm.rollback();
-    } catch (Exception ex) {
-      __log.error("JTA ROLLBACK FAILED",ex);
-      throw ex;
-    }
-  }
-
-  protected void commit() throws Exception {
-    try {    
-      _txm.commit();
-    } catch (Exception ex) {
-      __log.error("JTA COMMIT FAILED",ex);
-      throw ex;
-    }
-  }
-
-  protected void begin() throws Exception {
-    try {
-      _txm.begin();
-    } catch (Exception ex) {
-      __log.error("JTA BEGIN FAILED",ex);
-      throw ex;
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  private void doExecute(JobExecutionContext jobcontext) {
-    _server.getEngine().onScheduledJob(jobcontext.getJobDetail().getName(),
-        jobcontext.getJobDetail().getJobDataMap());
-  }
-
-  public static void execute(JobExecutionContext jobcontext) {
-    String schedulerGuid = jobcontext.getJobDetail().getJobDataMap().getString(
-        "__scheduler");
-    __instanceMap.get(schedulerGuid).doExecute(jobcontext);
-  }
-
-  /**
-   * Create a QUARTZ scheduler using JTA Job Shell. Unfortunately there is 
-   * no "easy" way to do this using the standard scheduler factory.
-   * @param schedulerName
-   * @param schedulerInstanceId
-   * @param threadPool
-   * @param jobStore
-   * @param rmiRegistryHost
-   * @param rmiRegistryPort
-   * @param idleWaitTime
-   * @param dbFailureRetryInterval
-   * @throws SchedulerException
-   */
-  private org.quartz.Scheduler createScheduler(String schedulerName, String 
schedulerInstanceId,
-      ThreadPool threadPool, JobStoreJTA jobStore)
-      throws SchedulerException {
-
-    jobStore.setInstanceName(schedulerName);
-    jobStore.setInstanceId(schedulerInstanceId);
-    
-    JTAJobRunShellFactory jrsf = new JTAJobRunShellFactory(_txm);
-
-    SchedulingContext schedCtxt = new SchedulingContext();
-    schedCtxt.setInstanceId(schedulerInstanceId);
-
-    QuartzSchedulerResources qrs = new QuartzSchedulerResources();
-
-    qrs.setName(schedulerName);
-    qrs.setInstanceId(schedulerInstanceId);
-    qrs.setJobRunShellFactory(jrsf);
-    qrs.setThreadPool(threadPool);
-    qrs.setJobStore(jobStore);
-
-    QuartzScheduler qs = new QuartzScheduler(qrs, schedCtxt, 0,0);
-        
-
-    ClassLoadHelper cch = new CascadingClassLoadHelper();
-    cch.initialize();
-    jobStore.initialize(cch, qs.getSchedulerSignaler());
-    StdScheduler scheduler = new StdScheduler(qs, schedCtxt);
-    jrsf.initialize(scheduler, schedCtxt);
-    SchedulerRepository schedRep = SchedulerRepository.getInstance();
-    qs.addNoGCObject(schedRep); 
-    schedRep.bind(scheduler);
-    return scheduler;
-  }
+            __log.error("JTA ROLLBACK FAILED",ex);
+            throw ex;
+        }
+    }
+
+    protected void commit() throws Exception {
+        try {
+            _txm.commit();
+        } catch (Exception ex) {
+            __log.error("JTA COMMIT FAILED",ex);
+            throw ex;
+        }
+    }
+
+    protected void begin() throws Exception {
+        try {
+            _txm.begin();
+        } catch (Exception ex) {
+            __log.error("JTA BEGIN FAILED",ex);
+            throw ex;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void doExecute(JobExecutionContext jobcontext) {
+        _server.getEngine().onScheduledJob(jobcontext.getJobDetail().getName(),
+                jobcontext.getJobDetail().getJobDataMap());
+    }
+
+    public static void execute(JobExecutionContext jobcontext) {
+        String schedulerGuid = 
jobcontext.getJobDetail().getJobDataMap().getString(
+                "__scheduler");
+        __instanceMap.get(schedulerGuid).doExecute(jobcontext);
+    }
+
+    /**
+     * Create a QUARTZ scheduler using JTA Job Shell. Unfortunately there is
+     * no "easy" way to do this using the standard scheduler factory.
+     * @param schedulerName
+     * @param schedulerInstanceId
+     * @param threadPool
+     * @param jobStore
+     * @param rmiRegistryHost
+     * @param rmiRegistryPort
+     * @param idleWaitTime
+     * @param dbFailureRetryInterval
+     * @throws SchedulerException
+     */
+    private org.quartz.Scheduler createScheduler(String schedulerName, String 
schedulerInstanceId,
+                                                 ThreadPool threadPool, 
JobStoreJTA jobStore)
+            throws SchedulerException {
+
+        jobStore.setInstanceName(schedulerName);
+        jobStore.setInstanceId(schedulerInstanceId);
+        if (isSqlServer)
+            jobStore.setSelectWithLockSQL("SELECT * FROM {0}LOCKS UPDLOCK 
WHERE LOCK_NAME = ?");
+
+        JTAJobRunShellFactory jrsf = new JTAJobRunShellFactory(_txm);
+
+        SchedulingContext schedCtxt = new SchedulingContext();
+        schedCtxt.setInstanceId(schedulerInstanceId);
+
+        QuartzSchedulerResources qrs = new QuartzSchedulerResources();
+
+        qrs.setName(schedulerName);
+        qrs.setInstanceId(schedulerInstanceId);
+        qrs.setJobRunShellFactory(jrsf);
+        qrs.setThreadPool(threadPool);
+        qrs.setJobStore(jobStore);
+
+        QuartzScheduler qs = new QuartzScheduler(qrs, schedCtxt, 0,0);
+
+        ClassLoadHelper cch = new CascadingClassLoadHelper();
+        cch.initialize();
+        jobStore.initialize(cch, qs.getSchedulerSignaler());
+        StdScheduler scheduler = new StdScheduler(qs, schedCtxt);
+        jrsf.initialize(scheduler, schedCtxt);
+        SchedulerRepository schedRep = SchedulerRepository.getInstance();
+        qs.addNoGCObject(schedRep);
+        schedRep.bind(scheduler);
+        return scheduler;
+    }
+
+    public void setSqlServer(boolean sqlServer) {
+        isSqlServer = sqlServer;
+    }
 
 }

Modified: 
incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java?view=diff&rev=485889&r1=485888&r2=485889
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java 
(original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java 
Mon Dec 11 13:47:32 2006
@@ -74,6 +74,7 @@
     private boolean _needDerbyShutdown;
     private String _derbyUrl;
     private BpelServerConnector _connector;
+    private String _dbType;
 
     ServiceUnitManager getSUManager() {
         return _suManager;
@@ -246,10 +247,11 @@
         _ode._scheduler.setTransactionManager((TransactionManager) _ode
                 .getContext().getTransactionManager());
         _ode._scheduler.setDataSource(_ode._dataSource);
+        if ("sqlserver".equals(_dbType)) _ode._scheduler.setSqlServer(true);
         _ode._scheduler.init();
 
         _ode._store = new ProcessStoreImpl(_ode._dataSource);
-
+
 
         _ode._server.setInMemDaoConnectionFactory(new 
org.apache.ode.bpel.memdao.BpelDAOConnectionFactoryImpl());        
         _ode._server.setDaoConnectionFactory(_ode._daocf);
@@ -275,14 +277,6 @@
                 HibernateTransactionManagerLookup.class.getName());
         properties.put(Environment.SESSION_FACTORY_NAME, "jta");
 
-        try {
-            properties.put(Environment.DIALECT, 
guessDialect(_ode._dataSource));
-        } catch (Exception ex) {
-            String errmsg = __msgs.msgOdeInitHibernateDialectDetectFailed();
-            __log.error(errmsg,ex);
-            throw new JBIException(errmsg,ex);
-        }
-
         File hibernatePropFile = new File(_ode.getContext().getInstallRoot()
                 + File.separatorChar + "hibernate.properties");
 
@@ -300,6 +294,23 @@
         } else {
             __log.info(__msgs
                     .msgOdeInitHibernatePropertiesNotFound(hibernatePropFile));
+        }
+
+        // Guess Hibernate dialect if not specified in hibernate.properties
+        if (properties.get(Environment.DIALECT) == null) {
+            try {
+                properties.put(Environment.DIALECT, 
guessDialect(_ode._dataSource));
+            } catch (Exception ex) {
+                String errmsg = 
__msgs.msgOdeInitHibernateDialectDetectFailed();
+                if (__log.isDebugEnabled()) __log.error(errmsg,ex);
+                else __log.error(errmsg);
+            }
+        }
+        if (properties.get(Environment.DIALECT) != null) {
+            String dialect = (String) properties.get(Environment.DIALECT);
+            if (dialect.equals("org.hibernate.dialect.SQLServerDialect"))
+                _dbType = "sqlserver";
+            else _dbType = "other";
         }
 
         SessionManager sm = new SessionManager(properties, _ode._dataSource, 
_ode


Reply via email to