[jbpm-commits] JBoss JBPM SVN: r3965 - in jbpm3/branches/jbpm-3.2.5.SP/modules/core/src: main/java/org/jbpm/graph/log and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 20 04:16:34 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-02-20 04:16:34 -0500 (Fri, 20 Feb 2009)
New Revision: 3965

Modified:
   jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java
   jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/TextType.java
   jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/graph/log/ActionLog.java
   jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml
   jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java
Log:
[JBPM-2057] Do not truncate long messages/exceptions

Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java	2009-02-19 23:48:37 UTC (rev 3964)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/StringMax.java	2009-02-20 09:16:34 UTC (rev 3965)
@@ -1,37 +1,47 @@
 package org.jbpm.db.hibernate;
 
+// $Id$
+
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.Properties;
 
 import org.hibernate.type.StringType;
+import org.hibernate.usertype.ParameterizedType;
 import org.jbpm.JbpmException;
 
-public class StringMax extends StringType implements org.hibernate.usertype.ParameterizedType {
+/**
+ * A custom type that truncates string values
+ */
+public class StringMax extends StringType implements ParameterizedType
+{
+  private static final long serialVersionUID = 1L;
 
-  private static final long serialVersionUID = 1L;
-  
   int length = 4000;
 
-  public void set(PreparedStatement st, Object value, int index) throws SQLException {
+  public void set(PreparedStatement st, Object value, int index) throws SQLException
+  {
     String string = (String)value;
-    if ( (value!=null)
-         && (string.length()>length)
-       ) {
-      value = string.substring(0, length);
+    if (string != null && string.length() > length)
+    {
+      string = string.substring(0, length);
     }
-    super.set(st, value, index);
+    super.set(st, string, index);
   }
 
-  public void setParameterValues(Properties parameters) {
-    if ( (parameters!=null)
-         && (parameters.containsKey("length"))
-       ){
-      try {
-        length = Integer.parseInt(parameters.getProperty("length"));
-      } catch (NumberFormatException e) {
-        throw new JbpmException("hibernate column type 'string_max' can't parse value '"+parameters.getProperty("length")+"' as a max length.  default is 4000.", e);
+  public void setParameterValues(Properties parameters)
+  {
+    if (parameters != null && parameters.containsKey("length"))
+    {
+      String propval = parameters.getProperty("length");
+      try
+      {
+        length = Integer.parseInt(propval);
       }
+      catch (NumberFormatException e)
+      {
+        throw new JbpmException("hibernate column type 'string_max' can't parse value '" + propval + "' as a max length.  default is 4000.", e);
+      }
     }
   }
 }

Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/TextType.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/TextType.java	2009-02-19 23:48:37 UTC (rev 3964)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/db/hibernate/TextType.java	2009-02-20 09:16:34 UTC (rev 3965)
@@ -41,110 +41,138 @@
 /**
  * @author Alejandro Guizar
  */
-public class TextType implements EnhancedUserType, Serializable {
+public class TextType implements EnhancedUserType, Serializable
+{
 
   private transient Log log;
-  private static final boolean IS_VALUE_TRACING_ENABLED = LogFactory.getLog(
-      StringHelper.qualifier(Type.class.getName())).isTraceEnabled();
+  private static final boolean IS_VALUE_TRACING_ENABLED = LogFactory.getLog(StringHelper.qualifier(Type.class.getName())).isTraceEnabled();
 
   private static final long serialVersionUID = 1L;
 
-  private Log log() {
-    if (log == null) {
+  private Log log()
+  {
+    if (log == null)
+    {
       log = LogFactory.getLog(getClass());
     }
     return log;
   }
 
-  public Object assemble(Serializable cached, Object owner) throws HibernateException {
-    if (cached == null) {
+  public Object assemble(Serializable cached, Object owner) throws HibernateException
+  {
+    if (cached == null)
+    {
       return null;
     }
-    else {
+    else
+    {
       return deepCopy(cached);
     }
   }
 
-  public Object deepCopy(Object value) throws HibernateException {
+  public Object deepCopy(Object value) throws HibernateException
+  {
     return value;
   }
 
-  public Serializable disassemble(Object value) throws HibernateException {
-    if (value == null) {
+  public Serializable disassemble(Object value) throws HibernateException
+  {
+    if (value == null)
+    {
       return null;
     }
-    else {
-      return (Serializable) deepCopy(value);
+    else
+    {
+      return (Serializable)deepCopy(value);
     }
   }
 
-  public boolean equals(Object x, Object y) throws HibernateException {
+  public boolean equals(Object x, Object y) throws HibernateException
+  {
     return EqualsHelper.equals(x, y);
   }
 
-  public int hashCode(Object x) throws HibernateException {
+  public int hashCode(Object x) throws HibernateException
+  {
     return x.hashCode();
   }
 
-  public boolean isMutable() {
+  public boolean isMutable()
+  {
     return false;
   }
 
-  public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException,
-      SQLException {
+  public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException
+  {
     return nullSafeGet(rs, names[0]);
   }
 
-  public Object nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException {
-    try {
+  public Object nullSafeGet(ResultSet rs, String name) throws HibernateException, SQLException
+  {
+    try
+    {
       Object value = get(rs, name);
-      if (value == null) {
-        if (IS_VALUE_TRACING_ENABLED) {
+      if (value == null)
+      {
+        if (IS_VALUE_TRACING_ENABLED)
+        {
           log().trace("returning null as column: " + name);
         }
         return null;
       }
-      else {
-        if (IS_VALUE_TRACING_ENABLED) {
+      else
+      {
+        if (IS_VALUE_TRACING_ENABLED)
+        {
           log().trace("returning '" + toString(value) + "' as column: " + name);
         }
         return value;
       }
     }
-    catch (RuntimeException re) {
+    catch (RuntimeException re)
+    {
       log().info("could not read column value from result set: " + name + "; " + re.getMessage());
       throw re;
     }
-    catch (SQLException se) {
+    catch (SQLException se)
+    {
       log().info("could not read column value from result set: " + name + "; " + se.getMessage());
       throw se;
     }
   }
 
-  public Object get(ResultSet rs, String name) throws HibernateException, SQLException {
+  public Object get(ResultSet rs, String name) throws HibernateException, SQLException
+  {
     // retrieve the value of the designated column in the current row of the
     // result set as a character reader
     Reader charReader = rs.getCharacterStream(name);
 
     // if the corresponding SQL value is NULL, the reader we got is NULL as well
-    if (charReader == null || rs.wasNull()) return null;
+    if (charReader == null || rs.wasNull())
+      return null;
 
     // Fetch Reader content up to the end - and put characters in a StringBuffer
     StringBuffer sbuf = new StringBuffer();
-    try {
+    try
+    {
       char[] cbuf = new char[1024];
-      for (int amountRead; (amountRead = charReader.read(cbuf)) != -1;) {
+      for (int amountRead; (amountRead = charReader.read(cbuf)) != -1;)
+      {
         sbuf.append(cbuf, 0, amountRead);
       }
     }
-    catch (IOException ioe) {
+    catch (IOException ioe)
+    {
       throw new HibernateException("IOException occurred reading text", ioe);
     }
-    finally {
-      try {
+    finally
+    {
+      try
+      {
         charReader.close();
       }
-      catch (IOException e) {
+      catch (IOException e)
+      {
         throw new HibernateException("IOException occurred closing stream", e);
       }
     }
@@ -153,94 +181,100 @@
     return sbuf.toString();
   }
 
-  public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException,
-      SQLException {
-    try {
-      if (value == null) {
-        if (IS_VALUE_TRACING_ENABLED) {
+  public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException
+  {
+    try
+    {
+      if (value == null)
+      {
+        if (IS_VALUE_TRACING_ENABLED)
+        {
           log().trace("binding null to parameter: " + index);
         }
 
         setNull(st, index);
       }
-      else {
-        if (IS_VALUE_TRACING_ENABLED) {
+      else
+      {
+        if (IS_VALUE_TRACING_ENABLED)
+        {
           log().trace("binding '" + toString(value) + "' to parameter: " + index);
         }
 
         set(st, value, index);
       }
     }
-    catch (RuntimeException re) {
-      log().info(
-          "could not bind value '"
-              + nullSafeToString(value)
-              + "' to parameter: "
-              + index
-              + "; "
-              + re.getMessage());
+    catch (RuntimeException re)
+    {
+      log().info("could not bind value '" + nullSafeToString(value) + "' to parameter: " + index + "; " + re.getMessage());
       throw re;
     }
-    catch (SQLException se) {
-      log().info(
-          "could not bind value '"
-              + nullSafeToString(value)
-              + "' to parameter: "
-              + index
-              + "; "
-              + se.getMessage());
+    catch (SQLException se)
+    {
+      log().info("could not bind value '" + nullSafeToString(value) + "' to parameter: " + index + "; " + se.getMessage());
       throw se;
     }
   }
 
-  public void set(PreparedStatement st, Object value, int index) throws HibernateException,
-      SQLException {
-    String str = (String) value;
+  public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException
+  {
+    String str = (String)value;
     st.setCharacterStream(index, new StringReader(str), str.length());
   }
 
-  public void setNull(PreparedStatement st, int index) throws HibernateException, SQLException {
+  public void setNull(PreparedStatement st, int index) throws HibernateException, SQLException
+  {
     // JBPM-1818: workaround for SQL state JZ0SL: "Unsupported SQL type" with jConnect
     st.setCharacterStream(index, null, 0);
   }
 
-  public Object replace(Object original, Object target, Object owner) throws HibernateException {
+  public Object replace(Object original, Object target, Object owner) throws HibernateException
+  {
     return original;
   }
 
-  public Class returnedClass() {
+  public Class returnedClass()
+  {
     return String.class;
   }
 
-  public int[] sqlTypes() {
+  public int[] sqlTypes()
+  {
     return new int[] { sqlType() };
   }
 
-  public int sqlType() {
+  public int sqlType()
+  {
     return Types.CLOB;
   }
 
-  public String objectToSQLString(Object value) {
-    return '\'' + (String) value + '\'';
+  public String objectToSQLString(Object value)
+  {
+    return '\'' + (String)value + '\'';
   }
 
-  public Object fromXMLString(String xml) {
+  public Object fromXMLString(String xml)
+  {
     return xml == null || xml.length() == 0 ? null : fromStringValue(xml);
   }
 
-  public String toXMLString(Object value) {
+  public String toXMLString(Object value)
+  {
     return toString(value);
   }
 
-  public String nullSafeToString(Object value) throws HibernateException {
+  public String nullSafeToString(Object value) throws HibernateException
+  {
     return value == null ? null : toString(value);
   }
 
-  public String toString(Object val) {
-    return (String) val;
+  public String toString(Object val)
+  {
+    return (String)val;
   }
 
-  public Object fromStringValue(String xml) {
+  public Object fromStringValue(String xml)
+  {
     return xml;
   }
 }

Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/graph/log/ActionLog.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/graph/log/ActionLog.java	2009-02-19 23:48:37 UTC (rev 3964)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/java/org/jbpm/graph/log/ActionLog.java	2009-02-20 09:16:34 UTC (rev 3965)
@@ -27,45 +27,64 @@
 import org.jbpm.graph.def.Action;
 import org.jbpm.logging.log.CompositeLog;
 
-public class ActionLog extends CompositeLog {
+public class ActionLog extends CompositeLog
+{
 
   private static final long serialVersionUID = 1L;
 
   protected Action action = null;
   protected String exception = null;
+  
+  // [JBPM-2057] Do not truncate long messages/exceptions
+  protected String exceptionExt = null;
 
-  public ActionLog() {
+  public ActionLog()
+  {
   }
 
-  public ActionLog(Action action) {
+  public ActionLog(Action action)
+  {
     this.action = action;
   }
 
-  public String toString() {
+  public String toString()
+  {
     StringBuffer buffer = new StringBuffer();
     buffer.append("action[");
     buffer.append(action);
-    if (exception!=null) {
+    if (getException() != null)
+    {
       buffer.append(", threw '");
-      buffer.append(exception);
+      buffer.append(getException());
       buffer.append("'");
     }
     buffer.append("]");
     return buffer.toString();
   }
-  
-  public void setException(Throwable exception) {
+
+  public void setException(Throwable throwable)
+  {
     StringWriter stringWriter = new StringWriter();
-    exception.printStackTrace(new PrintWriter(stringWriter));
-    this.exception = stringWriter.toString();
+    throwable.printStackTrace(new PrintWriter(stringWriter));
+    String exString = stringWriter.toString();
+    if (exString.length() > 4000)
+      exceptionExt = exString;
+    else
+      exception = exString;
   }
-  public Action getAction() {
+
+  public Action getAction()
+  {
     return action;
   }
-  public void setAction(Action action) {
+
+  public void setAction(Action action)
+  {
     this.action = action;
   }
-  public String getException() {
-    return exception;
+
+  public String getException()
+  {
+    return exceptionExt != null ? exceptionExt : exception;
   }
 }

Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml	2009-02-19 23:48:37 UTC (rev 3964)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/main/resources/org/jbpm/graph/log/ActionLog.hbm.xml	2009-02-20 09:16:34 UTC (rev 3965)
@@ -6,16 +6,13 @@
 
 <hibernate-mapping auto-import="false" default-access="field">
 
-  <subclass name="org.jbpm.graph.log.ActionLog" 
-            extends="org.jbpm.logging.log.CompositeLog"
-            discriminator-value="A">
-            
+  <subclass name="org.jbpm.graph.log.ActionLog" extends="org.jbpm.logging.log.CompositeLog" discriminator-value="A">
+
     <property name="exception" column="EXCEPTION_" type="string" length="4000"/>
-    <many-to-one name="action" 
-                 column="ACTION_" 
-                 class="org.jbpm.graph.def.Action" 
-                 foreign-key="FK_LOG_ACTION" />
+    <property name="exceptionExt" column="EXCEPTION_EXT_" type="text"/>
 
+    <many-to-one name="action" column="ACTION_" class="org.jbpm.graph.def.Action" foreign-key="FK_LOG_ACTION" />
+
   </subclass>
 
 </hibernate-mapping>

Modified: jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java	2009-02-19 23:48:37 UTC (rev 3964)
+++ jbpm3/branches/jbpm-3.2.5.SP/modules/core/src/test/java/org/jbpm/graph/log/ActionLogDbTest.java	2009-02-20 09:16:34 UTC (rev 3965)
@@ -21,12 +21,14 @@
  */
 package org.jbpm.graph.log;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
 import org.jbpm.db.AbstractDbTestCase;
 import org.jbpm.graph.def.Action;
 
 public class ActionLogDbTest extends AbstractDbTestCase
 {
-
   public void testActionLog()
   {
     Action action = new Action();
@@ -40,13 +42,37 @@
     session.delete(action);
   }
 
+  // [JBPM-2057] Do not truncate long messages/exceptions
   public void testActionExceptionLog()
   {
     ActionLog actionLog = new ActionLog();
-    actionLog.setException(new IllegalArgumentException("it's not rocket science"));
+    actionLog.setException(getRuntimeException());
     actionLog = (ActionLog)saveAndReload(actionLog);
-    assertNotNull(actionLog.getException());
     
+    String rteStr = actionLog.getException();
+    assertNotNull(rteStr);
+    assertTrue("Exception string longer than 4000", rteStr.length() > 4000);
+    
     session.delete(actionLog);
   }
+
+  private RuntimeException getRuntimeException()
+  {
+    int level = 0;
+    RuntimeException rte = new RuntimeException("level " + (level++));
+    while (true)
+    {
+      StringWriter stwr = new StringWriter();
+      PrintWriter prwr = new PrintWriter(stwr);
+      rte.printStackTrace(prwr);
+      
+      String rteStr = stwr.toString();
+      if (rteStr.length() > 4000)
+        break;
+      
+      rte = new RuntimeException("level " + (level++), rte);
+    }
+
+    return rte;
+  }
 }




More information about the jbpm-commits mailing list