[jbpm-commits] JBoss JBPM SVN: r2576 - in jbpm3/trunk/modules/core/src/main/java/org/jbpm: persistence/db and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 21 22:54:47 EDT 2008


Author: alex.guizar at jboss.com
Date: 2008-10-21 22:54:47 -0400 (Tue, 21 Oct 2008)
New Revision: 2576

Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/StaleObjectLogConfigurer.java
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java
Log:
[JBPM-1754] added verbosity control code to flushSession()
encapsulated staleObjectExceptionsLog

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2008-10-22 02:28:06 UTC (rev 2575)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/JbpmConfiguration.java	2008-10-22 02:54:47 UTC (rev 2576)
@@ -38,7 +38,6 @@
 import org.jbpm.configuration.ValueInfo;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.instantiation.DefaultProcessClassLoaderFactory;
-import org.jbpm.instantiation.ProcessClassLoader;
 import org.jbpm.instantiation.ProcessClassLoaderFactory;
 import org.jbpm.job.executor.JobExecutor;
 import org.jbpm.persistence.db.DbPersistenceServiceFactory;
@@ -51,12 +50,16 @@
  * configuration of one jBPM instance.
  * 
  * <p>
- * During process execution, jBPM might need to use some services. A JbpmConfiguration contains the knowledge on how to create those services.
+ * During process execution, jBPM might need to use some services. A
+ * JbpmConfiguration contains the knowledge on how to create those services.
  * </p>
  * 
  * <p>
- * A JbpmConfiguration is a thread safe object and serves as a factory for {@link org.jbpm.JbpmContext}s, which means one JbpmConfiguration can be used to create
- * {@link org.jbpm.JbpmContext}s for all threads. The single JbpmConfiguration can be maintained in a static member or in the JNDI tree if that is available.
+ * A JbpmConfiguration is a thread safe object and serves as a factory for
+ * {@link org.jbpm.JbpmContext}s, which means one JbpmConfiguration can be used
+ * to create {@link org.jbpm.JbpmContext}s for all threads. The single
+ * JbpmConfiguration can be maintained in a static member or in the JNDI tree if
+ * that is available.
  * </p>
  * 
  * <p>
@@ -87,8 +90,9 @@
  * </pre>
  * 
  * </li>
- * <li>By specifying a custom implementation of an object factory. This can be used to specify a JbpmConfiguration in other bean-style notations such as used by JBoss
- * Microcontainer or Spring.
+ * <li>By specifying a custom implementation of an object factory. This can be
+ * used to specify a JbpmConfiguration in other bean-style notations such as
+ * used by JBoss Microcontainer or Spring.
  * 
  * <pre>
  * ObjectFactory of = new &lt;i&gt;MyCustomObjectFactory&lt;/i&gt;();
@@ -101,7 +105,8 @@
  * </p>
  * 
  * <p>
- * JbpmConfigurations can be configured using a spring-like XML notation (in relax ng compact notation):
+ * JbpmConfigurations can be configured using a spring-like XML notation (in
+ * relax ng compact notation):
  * </p>
  * 
  * <pre>
@@ -235,8 +240,7 @@
  * </p>
  * 
  * <p>
- * Other configuration properties
- * <table>
+ * Other configuration properties <table>
  * <tr>
  * <td>jbpm.files.dir</td>
  * <td></td>
@@ -248,8 +252,8 @@
  * </table>
  * </p>
  */
-public class JbpmConfiguration implements Serializable
-{
+public class JbpmConfiguration implements Serializable {
+
   private static final long serialVersionUID = 1L;
 
   static ObjectFactory defaultObjectFactory;
@@ -260,50 +264,44 @@
   private ThreadLocal jbpmContextStacks = new ThreadLocal();
   private JobExecutor jobExecutor;
 
-  public JbpmConfiguration(ObjectFactory objectFactory)
-  {
+  public JbpmConfiguration(ObjectFactory objectFactory) {
     this.objectFactory = objectFactory;
   }
 
-  public static JbpmConfiguration getInstance()
-  {
+  public static JbpmConfiguration getInstance() {
     return getInstance(null);
   }
 
-  public static JbpmConfiguration getInstance(String resource)
-  {
+  public static JbpmConfiguration getInstance(String resource) {
     JbpmConfiguration instance = null;
-    synchronized (instances)
-    {
-      if (resource == null)
-      {
+    synchronized (instances) {
+      if (resource == null) {
         resource = "jbpm.cfg.xml";
       }
 
-      instance = (JbpmConfiguration)instances.get(resource);
-      if (instance == null)
-      {
+      instance = (JbpmConfiguration) instances.get(resource);
+      if (instance == null) {
 
-        if (defaultObjectFactory != null)
-        {
-          log.debug("creating jbpm configuration from given default object factory '" + defaultObjectFactory + "'");
+        if (defaultObjectFactory != null) {
+          log.debug("creating jbpm configuration from given default object factory '"
+              + defaultObjectFactory
+              + "'");
           instance = new JbpmConfiguration(defaultObjectFactory);
 
         }
-        else
-        {
+        else {
 
-          try
-          {
+          try {
             log.info("using jbpm configuration resource '" + resource + "'");
             InputStream jbpmCfgXmlStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
 
-            // if a custom resource is to be used, but is not found in the classpath
+            // if a custom resource is to be used, but is not found in the
+            // classpath
             // log a warning (otherwise, users who want to load custom stuff
-            // will be confused if the resource is not found and not loaded, without
+            // will be confused if the resource is not found and not loaded,
+            // without
             // any notice)
-            if (jbpmCfgXmlStream == null && !"jbpm.cfg.xml".equals(resource))
-            {
+            if (jbpmCfgXmlStream == null && !"jbpm.cfg.xml".equals(resource)) {
               log.warn("jbpm configuration resource '" + resource + "' is not available");
             }
 
@@ -311,9 +309,10 @@
             instance = createJbpmConfiguration(objectFactory);
 
           }
-          catch (RuntimeException e)
-          {
-            throw new JbpmException("couldn't parse jbpm configuration from resource '" + resource + "'", e);
+          catch (RuntimeException e) {
+            throw new JbpmException("couldn't parse jbpm configuration from resource '"
+                + resource
+                + "'", e);
           }
         }
 
@@ -324,29 +323,25 @@
     return instance;
   }
 
-  public static boolean hasInstance(String resource)
-  {
+  public static boolean hasInstance(String resource) {
     boolean hasInstance = false;
-    if (resource == null)
-    {
+    if (resource == null) {
       resource = "jbpm.cfg.xml";
     }
-    if ((instances != null) && (instances.containsKey(resource)))
-    {
+    if ((instances != null) && (instances.containsKey(resource))) {
       hasInstance = true;
     }
     return hasInstance;
   }
 
-  protected static ObjectFactory parseObjectFactory(InputStream inputStream)
-  {
+  protected static ObjectFactory parseObjectFactory(InputStream inputStream) {
     log.debug("loading defaults in jbpm configuration");
     ObjectFactoryParser objectFactoryParser = new ObjectFactoryParser();
     ObjectFactoryImpl objectFactoryImpl = new ObjectFactoryImpl();
-    objectFactoryParser.parseElementsFromResource("org/jbpm/default.jbpm.cfg.xml", objectFactoryImpl);
+    objectFactoryParser.parseElementsFromResource("org/jbpm/default.jbpm.cfg.xml",
+        objectFactoryImpl);
 
-    if (inputStream != null)
-    {
+    if (inputStream != null) {
       log.debug("loading specific configuration...");
       objectFactoryParser.parseElementsStream(inputStream, objectFactoryImpl);
     }
@@ -357,31 +352,26 @@
   /**
    * create an ObjectFacotory from an XML string.
    */
-  public static JbpmConfiguration parseXmlString(String xml)
-  {
+  public static JbpmConfiguration parseXmlString(String xml) {
     log.debug("creating jbpm configuration from xml string");
     InputStream inputStream = null;
-    if (xml != null)
-    {
+    if (xml != null) {
       inputStream = new ByteArrayInputStream(xml.getBytes());
     }
     ObjectFactory objectFactory = parseObjectFactory(inputStream);
     return createJbpmConfiguration(objectFactory);
   }
 
-  protected static JbpmConfiguration createJbpmConfiguration(ObjectFactory objectFactory)
-  {
+  protected static JbpmConfiguration createJbpmConfiguration(ObjectFactory objectFactory) {
     JbpmConfiguration jbpmConfiguration = new JbpmConfiguration(objectFactory);
 
     // now we make the bean jbpm.configuration always availble
-    if (objectFactory instanceof ObjectFactoryImpl)
-    {
-      ObjectFactoryImpl objectFactoryImpl = (ObjectFactoryImpl)objectFactory;
+    if (objectFactory instanceof ObjectFactoryImpl) {
+      ObjectFactoryImpl objectFactoryImpl = (ObjectFactoryImpl) objectFactory;
       ObjectInfo jbpmConfigurationInfo = new ValueInfo("jbpmConfiguration", jbpmConfiguration);
       objectFactoryImpl.addObjectInfo(jbpmConfigurationInfo);
 
-      if (mustStaleObjectExceptionsBeHidden(objectFactory))
-      {
+      if (getHideStaleObjectExceptions(objectFactory)) {
         StaleObjectLogConfigurer.hideStaleObjectExceptions();
       }
     }
@@ -389,351 +379,286 @@
     return jbpmConfiguration;
   }
 
-  private static boolean mustStaleObjectExceptionsBeHidden(ObjectFactory objectFactory)
-  {
-    if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions"))
-    {
+  private static boolean getHideStaleObjectExceptions(ObjectFactory objectFactory) {
+    if (!objectFactory.hasObject("jbpm.hide.stale.object.exceptions")) {
       return true;
     }
-    Object o = (Boolean)objectFactory.createObject("jbpm.hide.stale.object.exceptions");
-    if ((o instanceof Boolean) && (((Boolean)o).booleanValue() == false))
-    {
-      return false;
-    }
-    return true;
+    Object object = objectFactory.createObject("jbpm.hide.stale.object.exceptions");
+    return object instanceof Boolean ? ((Boolean) object).booleanValue() : true; 
   }
 
-  public static JbpmConfiguration parseInputStream(InputStream inputStream)
-  {
+  public static JbpmConfiguration parseInputStream(InputStream inputStream) {
     ObjectFactory objectFactory = parseObjectFactory(inputStream);
     log.debug("creating jbpm configuration from input stream");
     return createJbpmConfiguration(objectFactory);
   }
 
-  public static JbpmConfiguration parseResource(String resource)
-  {
+  public static JbpmConfiguration parseResource(String resource) {
     InputStream inputStream = null;
     log.debug("creating jbpm configuration from resource '" + resource + "'");
-    if (resource != null)
-    {
+    if (resource != null) {
       inputStream = ClassLoaderUtil.getJbpmConfigurationStream(resource);
     }
     ObjectFactory objectFactory = parseObjectFactory(inputStream);
     return createJbpmConfiguration(objectFactory);
   }
 
-  public JbpmContext createJbpmContext()
-  {
+  public JbpmContext createJbpmContext() {
     return createJbpmContext(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public JbpmContext createJbpmContext(String name)
-  {
-    JbpmContext jbpmContext = (JbpmContext)objectFactory.createObject(name);
+  public JbpmContext createJbpmContext(String name) {
+    JbpmContext jbpmContext = (JbpmContext) objectFactory.createObject(name);
     jbpmContext.jbpmConfiguration = this;
     jbpmContextCreated(jbpmContext);
     return jbpmContext;
   }
 
-  public ServiceFactory getServiceFactory(String serviceName)
-  {
+  public ServiceFactory getServiceFactory(String serviceName) {
     return getServiceFactory(serviceName, JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName)
-  {
+  public ServiceFactory getServiceFactory(String serviceName, String jbpmContextName) {
     ServiceFactory serviceFactory = null;
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
+    try {
       serviceFactory = jbpmContext.getServices().getServiceFactory(serviceName);
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
     return serviceFactory;
   }
-  
+
   public static ClassLoader getProcessClassLoader(ProcessDefinition processDefinition) {
     ProcessClassLoaderFactory factory = null;
     if (Configs.hasObject("jbpm.processClassLoader")) {
-     factory = (ProcessClassLoaderFactory) Configs.getObject("jbpm.processClassLoader");
+      factory = (ProcessClassLoaderFactory) Configs.getObject("jbpm.processClassLoader");
     }
     else {
       factory = new DefaultProcessClassLoaderFactory();
     }
     return factory.getProcessClassLoader(processDefinition);
-  }  
+  }
 
-
   /**
-   * gives the jbpm domain model access to configuration information via the current JbpmContext.
+   * gives the jbpm domain model access to configuration information via the
+   * current JbpmContext.
    */
-  public abstract static class Configs
-  {
-    public static ObjectFactory getObjectFactory()
-    {
+  public abstract static class Configs {
+
+    public static ObjectFactory getObjectFactory() {
       ObjectFactory objectFactory = null;
       JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
-      if (jbpmContext != null)
-      {
+      if (jbpmContext != null) {
         objectFactory = jbpmContext.objectFactory;
       }
-      else
-      {
+      else {
         objectFactory = getInstance().objectFactory;
       }
       return objectFactory;
     }
 
-    public static void setDefaultObjectFactory(ObjectFactory objectFactory)
-    {
+    public static void setDefaultObjectFactory(ObjectFactory objectFactory) {
       defaultObjectFactory = objectFactory;
     }
 
-    public static boolean hasObject(String name)
-    {
+    public static boolean hasObject(String name) {
       ObjectFactory objectFactory = getObjectFactory();
       return objectFactory.hasObject(name);
     }
 
-    public static synchronized Object getObject(String name)
-    {
+    public static synchronized Object getObject(String name) {
       ObjectFactory objectFactory = getObjectFactory();
       return objectFactory.createObject(name);
     }
 
-    public static String getString(String name)
-    {
-      return (String)getObject(name);
+    public static String getString(String name) {
+      return (String) getObject(name);
     }
 
-    public static long getLong(String name)
-    {
-      return ((Long)getObject(name)).longValue();
+    public static long getLong(String name) {
+      return ((Long) getObject(name)).longValue();
     }
 
-    public static int getInt(String name)
-    {
-      return ((Integer)getObject(name)).intValue();
+    public static int getInt(String name) {
+      return ((Integer) getObject(name)).intValue();
     }
 
-    public static boolean getBoolean(String name)
-    {
-      return ((Boolean)getObject(name)).booleanValue();
+    public static boolean getBoolean(String name) {
+      return ((Boolean) getObject(name)).booleanValue();
     }
   }
 
-  public void cleanSchema()
-  {
+  public void cleanSchema() {
     cleanSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public void cleanSchema(String jbpmContextName)
-  {
+  public void cleanSchema(String jbpmContextName) {
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
+    try {
       Services services = jbpmContext.getServices();
-      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory)services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
       persistenceServiceFactory.cleanSchema();
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
   }
 
-  public void createSchema()
-  {
+  public void createSchema() {
     createSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public void createSchema(String jbpmContextName)
-  {
+  public void createSchema(String jbpmContextName) {
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
+    try {
       Services services = jbpmContext.getServices();
-      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory)services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
       persistenceServiceFactory.createSchema();
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
   }
 
-  public void dropSchema()
-  {
+  public void dropSchema() {
     dropSchema(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public void dropSchema(String jbpmContextName)
-  {
+  public void dropSchema(String jbpmContextName) {
     log.warn("Dropping schema: " + jbpmContextName);
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
+    try {
       Services services = jbpmContext.getServices();
-      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory)services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
+      DbPersistenceServiceFactory persistenceServiceFactory = (DbPersistenceServiceFactory) services.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
       persistenceServiceFactory.dropSchema();
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
   }
 
-  public void close()
-  {
+  public void close() {
     close(JbpmContext.DEFAULT_JBPM_CONTEXT_NAME);
   }
 
-  public void close(String jbpmContextName)
-  {
+  public void close(String jbpmContextName) {
     JbpmContext jbpmContext = createJbpmContext(jbpmContextName);
-    try
-    {
+    try {
 
-      synchronized (instances)
-      {
+      synchronized (instances) {
         Iterator iter = instances.keySet().iterator();
-        while (iter.hasNext())
-        {
-          String resource = (String)iter.next();
-          if (this == instances.get(resource))
-          {
+        while (iter.hasNext()) {
+          String resource = (String) iter.next();
+          if (this == instances.get(resource)) {
             instances.remove(resource);
             break;
           }
         }
       }
 
-      if (jobExecutor != null)
-      {
+      if (jobExecutor != null) {
         jobExecutor.stop();
       }
 
       Map serviceFactories = jbpmContext.getServices().getServiceFactories();
-      if (serviceFactories != null)
-      {
+      if (serviceFactories != null) {
         Iterator iter = serviceFactories.values().iterator();
-        while (iter.hasNext())
-        {
-          ServiceFactory serviceFactory = (ServiceFactory)iter.next();
+        while (iter.hasNext()) {
+          ServiceFactory serviceFactory = (ServiceFactory) iter.next();
           serviceFactory.close();
         }
       }
     }
-    finally
-    {
+    finally {
       jbpmContext.close();
     }
   }
 
-  static JbpmConfiguration getCurrentJbpmConfiguration()
-  {
+  static JbpmConfiguration getCurrentJbpmConfiguration() {
     JbpmConfiguration currentJbpmConfiguration = null;
     Stack stack = getJbpmConfigurationStack();
-    if (!stack.isEmpty())
-    {
-      currentJbpmConfiguration = (JbpmConfiguration)stack.peek();
+    if (!stack.isEmpty()) {
+      currentJbpmConfiguration = (JbpmConfiguration) stack.peek();
     }
     return currentJbpmConfiguration;
   }
 
-  static synchronized Stack getJbpmConfigurationStack()
-  {
-    Stack stack = (Stack)jbpmConfigurationsStacks.get();
-    if (stack == null)
-    {
+  static synchronized Stack getJbpmConfigurationStack() {
+    Stack stack = (Stack) jbpmConfigurationsStacks.get();
+    if (stack == null) {
       stack = new Stack();
       jbpmConfigurationsStacks.set(stack);
     }
     return stack;
   }
 
-  synchronized void pushJbpmConfiguration()
-  {
+  synchronized void pushJbpmConfiguration() {
     getJbpmConfigurationStack().push(this);
   }
 
-  synchronized void popJbpmConfiguration()
-  {
+  synchronized void popJbpmConfiguration() {
     getJbpmConfigurationStack().remove(this);
   }
 
-  public JbpmContext getCurrentJbpmContext()
-  {
+  public JbpmContext getCurrentJbpmContext() {
     JbpmContext currentJbpmContext = null;
     Stack stack = getJbpmContextStack();
-    if (!stack.isEmpty())
-    {
-      currentJbpmContext = (JbpmContext)stack.peek();
+    if (!stack.isEmpty()) {
+      currentJbpmContext = (JbpmContext) stack.peek();
     }
     return currentJbpmContext;
   }
 
-  Stack getJbpmContextStack()
-  {
-    Stack stack = (Stack)jbpmContextStacks.get();
-    if (stack == null)
-    {
+  Stack getJbpmContextStack() {
+    Stack stack = (Stack) jbpmContextStacks.get();
+    if (stack == null) {
       stack = new Stack();
       jbpmContextStacks.set(stack);
     }
     return stack;
   }
 
-  void pushJbpmContext(JbpmContext jbpmContext)
-  {
+  void pushJbpmContext(JbpmContext jbpmContext) {
     getJbpmContextStack().push(jbpmContext);
   }
 
-  void popJbpmContext(JbpmContext jbpmContext)
-  {
+  void popJbpmContext(JbpmContext jbpmContext) {
     Stack stack = getJbpmContextStack();
-    if (stack.isEmpty())
-    {
-      throw new JbpmException("closed JbpmContext more then once... check your try-finally's around JbpmContexts blocks");
+    if (stack.isEmpty()) {
+      throw new JbpmException(
+          "closed JbpmContext more then once... check your try-finally's around JbpmContexts blocks");
     }
-    JbpmContext popped = (JbpmContext)stack.pop();
-    if (jbpmContext != popped)
-    {
-      throw new JbpmException("closed JbpmContext in different order then they were created... check your try-finally's around JbpmContexts blocks");
+    JbpmContext popped = (JbpmContext) stack.pop();
+    if (jbpmContext != popped) {
+      throw new JbpmException(
+          "closed JbpmContext in different order then they were created... check your try-finally's around JbpmContexts blocks");
     }
   }
 
-  void jbpmContextCreated(JbpmContext jbpmContext)
-  {
+  void jbpmContextCreated(JbpmContext jbpmContext) {
     pushJbpmConfiguration();
     pushJbpmContext(jbpmContext);
   }
 
-  void jbpmContextClosed(JbpmContext jbpmContext)
-  {
+  void jbpmContextClosed(JbpmContext jbpmContext) {
     popJbpmConfiguration();
     popJbpmContext(jbpmContext);
   }
 
-  public void startJobExecutor()
-  {
+  public void startJobExecutor() {
     getJobExecutor().start();
   }
 
-  public synchronized JobExecutor getJobExecutor()
-  {
-    if (jobExecutor == null)
-    {
-      try
-      {
-        jobExecutor = (JobExecutor)this.objectFactory.createObject("jbpm.job.executor");
+  public synchronized JobExecutor getJobExecutor() {
+    if (jobExecutor == null) {
+      try {
+        jobExecutor = (JobExecutor) this.objectFactory.createObject("jbpm.job.executor");
       }
-      catch (ClassCastException e)
-      {
-        throw new JbpmException("jbpm configuration object under key 'jbpm.job.executor' is not a " + JobExecutor.class.getName(), e);
+      catch (ClassCastException e) {
+        throw new JbpmException("jbpm configuration object under key 'jbpm.job.executor' is not a "
+            + JobExecutor.class.getName(), e);
       }
     }
     return jobExecutor;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java	2008-10-22 02:28:06 UTC (rev 2575)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/DbPersistenceService.java	2008-10-22 02:54:47 UTC (rev 2576)
@@ -29,7 +29,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.Session;
 import org.hibernate.SessionFactory;
-import org.hibernate.StaleObjectStateException;
+import org.hibernate.StaleStateException;
 import org.hibernate.Transaction;
 import org.jbpm.JbpmContext;
 import org.jbpm.JbpmException;
@@ -237,8 +237,7 @@
     if (flushException!=null) {
       // JBPM-1465 transaction has been either committed or rolled back at this point
       // on the other hand, it is possible that no transaction is underway
-      // rolling back here is redundant and possibly dangerous
-      // rollback();
+      // hence rolling back here is redundant and possibly dangerous
       closeSession();
       closeConnection();
       throw new JbpmPersistenceException("hibernate flush failed", flushException);
@@ -258,12 +257,12 @@
 
   Exception commit() {
     try {
-      log.debug("committing hibernate transaction " + transaction.toString());
+      log.debug("committing " + transaction);
       mustSessionBeFlushed = false; // commit does a flush anyway 
       transaction.commit();
-    } catch (StaleObjectStateException e) {
-      log.info("optimistic locking failed");
-      StaleObjectLogConfigurer.staleObjectExceptionsLog.error("optimistic locking failed", e);
+    } catch (StaleStateException e) {
+      log.info("problem committing transaction: optimistic locking failed");
+      StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("optimistic locking failed while committing " + transaction, e);
       return e;
     } catch (Exception e) {
       log.error("hibernate commit failed", e);
@@ -275,8 +274,12 @@
   Exception flushSession() {
     if (mustSessionBeFlushed) {
       try {
-        log.debug("flushing hibernate session " + session.toString());
+        log.debug("flushing " + session);
         session.flush();
+      } catch (StaleStateException e) {
+        log.info("problem flushing session: optimistic locking failed");
+        StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("optimistic locking failed while flushing " + session, e);
+        return e;
       } catch (Exception e) {
         log.error("hibernate flush failed", e);
         return e;

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/StaleObjectLogConfigurer.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/StaleObjectLogConfigurer.java	2008-10-22 02:28:06 UTC (rev 2575)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/persistence/db/StaleObjectLogConfigurer.java	2008-10-22 02:54:47 UTC (rev 2576)
@@ -26,28 +26,37 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public abstract class StaleObjectLogConfigurer {
+public class StaleObjectLogConfigurer {
 
-  private static Log log = LogFactory.getLog(StaleObjectLogConfigurer.class);
-  public static Log staleObjectExceptionsLog = LogFactory.getLog(StaleObjectLogConfigurer.class.getName()+".staleObjectExceptions");
-  
+  private static final Log log = LogFactory.getLog(StaleObjectLogConfigurer.class);
+  private static Log staleObjectExceptionsLog = LogFactory.getLog(StaleObjectLogConfigurer.class.getName()+".staleObjectExceptions");
+
+  private StaleObjectLogConfigurer() {
+    // hide default constructor to prevent instantiation
+  }
+
+  public static Log getStaleObjectExceptionsLog() {
+    return staleObjectExceptionsLog;
+  }
+
   public static void hideStaleObjectExceptions() {
+    if (staleObjectExceptionsLog instanceof LogWrapper) {
+      log.debug("stale object exceptions are already hidden from logging");
+      return;
+    }
+
     try {
-      staleObjectExceptionsLog = wrap(staleObjectExceptionsLog);
+      staleObjectExceptionsLog = new LogWrapper(staleObjectExceptionsLog);
       log.info("stale object exceptions will be hidden from logging");
     } catch (Exception e) {
       log.info("couldn't hide stale object exceptions from logging");
     }
   }
 
-  private static Log wrap(Log log) {
-    return new LogWrapper(log);
-  }
-
-  public static class LogWrapper implements Log, Serializable {
+  static class LogWrapper implements Log, Serializable {
+    Log delegate;
     private static final long serialVersionUID = 1L;
-    Log delegate;
-    public LogWrapper(Log delegate) {
+    LogWrapper(Log delegate) {
       this.delegate = delegate;
     }
     public void debug(Object arg0, Throwable arg1) {

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java	2008-10-22 02:28:06 UTC (rev 2575)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/svc/Services.java	2008-10-22 02:54:47 UTC (rev 2576)
@@ -238,7 +238,7 @@
             // if this is a stale state exception, the jbpm configuration has control over the logging
             if (isCausedByStaleState(e)) {
               log.info("problem closing service '"+serviceName+"': optimistic locking failed");
-              StaleObjectLogConfigurer.staleObjectExceptionsLog.error("problem closing service '"+serviceName+"': optimistic locking failed", e);
+              StaleObjectLogConfigurer.getStaleObjectExceptionsLog().error("problem closing service '"+serviceName+"': optimistic locking failed", e);
             } else {
               log.error("problem closing service '"+serviceName+"'", e);
             }




More information about the jbpm-commits mailing list