db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r414927 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms: Platform.java PlatformDefaultImpl.java PlatformMySQLImpl.java PlatformSapdbImpl.java
Date Fri, 16 Jun 2006 21:32:23 GMT
Author: arminw
Date: Fri Jun 16 14:32:22 2006
New Revision: 414927

URL: http://svn.apache.org/viewvc?rev=414927&view=rev
Log:
improve support for advanced jdbc data types (like JAVA_OBJECT)

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/Platform.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/Platform.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/Platform.java?rev=414927&r1=414926&r2=414927&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/Platform.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/Platform.java
Fri Jun 16 14:32:22 2006
@@ -16,6 +16,7 @@
  */
 
 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.query.LikeCriteria;
 
 import java.sql.CallableStatement;
@@ -96,6 +97,9 @@
     /**
      * Called to let the Platform implementation perform any JDBC type-specific operations
      * needed by the driver when binding positional parameters for a PreparedStatement.
+     * <br/>
+     * When read in result set columns, the counterpart of this method is
+     * {@link #postPrepareReadInValue(org.apache.ojb.broker.metadata.FieldDescriptor, Object)}.
      */
     void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType)
             throws SQLException;
@@ -103,6 +107,9 @@
     /**
      * Called to let the Platform implementation perform any JDBC type-specific operations
      * needed by the driver when binding null parameters for a PreparedStatement.
+     * <br/>
+     * When read in result set columns, the counterpart of this method is
+     * {@link #postPrepareReadInValue(org.apache.ojb.broker.metadata.FieldDescriptor, Object)}.
      */
     void setNullForStatement(PreparedStatement ps, int index, int sqlType)
             throws SQLException;
@@ -112,6 +119,9 @@
      * needed by the driver when binding positional parameters for a PreparedStatement.
      * <br/>
      * Note: This method may be called only if the JDBC-type is unknown.
+     * <br/>
+     * When read in result set columns, the counterpart of this method is
+     * {@link #postPrepareReadInValue(org.apache.ojb.broker.metadata.FieldDescriptor, Object)}.
      *
      * @param ps The {@link java.sql.PreparedStatement} to use.
      * @param index The column index.
@@ -143,15 +153,6 @@
      */
     boolean supportsBatchOperations();
 
-// arminw: think we can handle this internally
-//    /**
-//     * Sets platform information for if the jdbc driver/db combo support
-//     * batch operations. Will only be checked once, then have same batch
-//     * support setting for the entire session.
-//     * @param conn
-//     */
-//    void checkForBatchSupport(Connection conn);
-
     /**
      * Returns a query to create a sequence entry.
      *
@@ -258,15 +259,6 @@
      */
     String getEscapeClause(LikeCriteria aCriteria);
 
-// arminw: Check is not necessary any longer
-//    /**
-//     * Determines whether statement is {@link CallableStatement} or not.
-//     *
-//     * @param stmt the statement
-//     * @return true if statement is {@link CallableStatement}.
-//     */
-//    boolean isCallableStatement(PreparedStatement stmt);
-
     /**
      * Registers call argument at <code>position</code> as returning
      * a {@link ResultSet} value.
@@ -291,4 +283,18 @@
      * details see JDBC-spec. 16.3).
      */
     public boolean locatorsUpdateCopy(Connection con);
+
+    /**
+     * Allows database specific post preparation of ResultSet read in column values,
+     * e.g. casting of types or wrapping/unwrapping of classes or deserialisation
+     * of objects. It's the counterpart of {@link #setObjectForStatement(java.sql.PreparedStatement,
int, Object, int)}
+     * and {@link #setNullForStatement(java.sql.PreparedStatement, int, int)} methods.
+     * <br/>
+     * Note: This method is called before any
+     * {@link org.apache.ojb.broker.accesslayer.conversions.FieldConversion}
+     * could take place.
+     *
+     * @return The post prepared column value.
+     */
+    public Object postPrepareReadInValue(FieldDescriptor fld, Object value);
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java?rev=414927&r1=414926&r2=414927&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
Fri Jun 16 14:32:22 2006
@@ -30,9 +30,8 @@
 
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
-import org.apache.ojb.broker.lob.BlobHandle;
-import org.apache.ojb.broker.lob.ClobHandle;
 import org.apache.ojb.broker.lob.LobHandle;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
 import org.apache.ojb.broker.query.LikeCriteria;
 import org.apache.ojb.broker.util.SqlHelper;
@@ -670,5 +669,10 @@
 
         }
         return locatorsUpdateCopy.booleanValue();
+    }
+
+    public Object postPrepareReadInValue(final FieldDescriptor fld, final Object value)
+    {
+        return value;
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java?rev=414927&r1=414926&r2=414927&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformMySQLImpl.java
Fri Jun 16 14:32:22 2006
@@ -24,6 +24,8 @@
 import java.sql.Types;
 
 import org.apache.ojb.broker.query.LikeCriteria;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.commons.lang.SerializationUtils;
 
 /**
  * @version 1.0
@@ -34,10 +36,10 @@
 {
     private static final String LAST_INSERT = "SELECT LAST_INSERT_ID() FROM ";
     private static final String LIMIT = " LIMIT 1";
-    
+
     /*
-	 * @see Platform#setObjectForStatement(PreparedStatement, int, Object, int)
-	 */
+      * @see Platform#setObjectForStatement(PreparedStatement, int, Object, int)
+      */
     public void setObjectForStatement(PreparedStatement ps, int index, Object value, int
sqlType) throws SQLException
     {
         switch (sqlType)
@@ -45,7 +47,6 @@
             case Types.BIT :
                 ps.setObject(index, value);
                 break;
-
             case Types.BLOB :
             case Types.LONGVARBINARY :
             case Types.VARBINARY :
@@ -54,14 +55,12 @@
                     byte buf[] = (byte[]) value;
                     ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
                     ps.setBinaryStream(index, inputStream, buf.length);
-                    break;
                 }
                 else
                 {
                     super.setObjectForStatement(ps, index, value, sqlType);
-                    break;
                 }
-
+                break;
             case Types.CLOB :
                 Reader reader = null;
                 int length = 0;
@@ -93,16 +92,38 @@
                     super.setObjectForStatement(ps, index, value, sqlType);
                 }
                 break;
-
+            case Types.JAVA_OBJECT :
+            {
+                // JAVA_OBJECT is not proper supported, workaround: use OTHER type
+                ps.setObject(index, value, Types.OTHER);
+                break;
+            }
             default :
                 super.setObjectForStatement(ps, index, value, sqlType);
 
         }
     }
+
+    public Object postPrepareReadInValue(final FieldDescriptor fld, final Object value)
+    {
+        /*
+        workaround for JAVA_OBJECT type. Currently mysql (version 5.0) doesn't
+        proper support JAVA_OBJECT type
+        */
+        if(fld.getJdbcType().getType() == Types.JAVA_OBJECT && value instanceof byte[])
+        {
+            return SerializationUtils.deserialize((byte[]) value);
+        }
+        else
+        {
+            return super.postPrepareReadInValue(fld, value);
+        }
+    }
+
     /**
-	 * Get join syntax type for this RDBMS - one on of the constants from
-	 * JoinSyntaxType interface
-	 */
+     * Get join syntax type for this RDBMS - one on of the constants from
+     * JoinSyntaxType interface
+     */
     public byte getJoinSyntaxType()
     {
         return SQL92_NOPAREN_JOIN_SYNTAX;
@@ -142,9 +163,9 @@
         {
             return theColumns[0];
         }
-        
+
         StringBuffer buf = new StringBuffer();
-        
+
         buf.append("concat(");
         for (int i = 0; i < theColumns.length; i++)
         {
@@ -157,14 +178,14 @@
 
         buf.append(")");
         return buf.toString();
-    }    
-    
+    }
+
     /**
      * @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)
      */
     public String getEscapeClause(LikeCriteria aCriteria)
     {
-        if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER)
 
+        if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER)
         {
             // the default escape character is \, so there's no need for an escape clause
             return super.getEscapeClause(aCriteria);
@@ -174,12 +195,12 @@
             return "";
         }
     }
-    
+
     /**
      * @see org.apache.ojb.broker.platforms.PlatformDefaultImpl#getQuotedName(java.lang.String)
      */
     protected String getQuotedName(String aString)
     {
-        return '`' + aString + '`'; 
+        return '`' + aString + '`';
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java?rev=414927&r1=414926&r2=414927&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/platforms/PlatformSapdbImpl.java
Fri Jun 16 14:32:22 2006
@@ -19,8 +19,11 @@
 import java.sql.SQLException;
 import java.sql.Types;
 import java.util.Properties;
+import java.io.Serializable;
 
 import org.apache.ojb.broker.util.sequence.SequenceManagerHelper;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.commons.lang.SerializationUtils;
 
 /**
  * SapDB specific Platform implementation.
@@ -126,15 +129,36 @@
             int sqlType)
             throws SQLException
     {
-        if(((sqlType == Types.VARBINARY) || (sqlType == Types.LONGVARBINARY))
-                && (value instanceof byte[]))
+        switch (sqlType)
         {
-            byte buf[] = (byte[]) value;
-            ps.setBytes(index, buf);
+            case Types.VARBINARY:
+            case Types.LONGVARBINARY:
+                if(value instanceof byte[])
+                {
+                    byte buf[] = (byte[]) value;
+                    ps.setBytes(index, buf);
+                }
+                break;
+            case Types.JAVA_OBJECT:
+                // workaround for JAVA_OBJECT type.
+                Object ser = SerializationUtils.serialize((Serializable) value);
+                ps.setObject(index, ser);
+                break;
+            default:
+                super.setObjectForStatement(ps, index, value, sqlType);
+        }
+    }
+
+    public Object postPrepareReadInValue(final FieldDescriptor fld, final Object value)
+    {
+        // workaround for JAVA_OBJECT type.
+        if(fld.getJdbcType().getType() == Types.JAVA_OBJECT && value instanceof byte[])
+        {
+            return SerializationUtils.deserialize((byte[]) value);
         }
         else
         {
-            super.setObjectForStatement(ps, index, value, sqlType);
+            return super.postPrepareReadInValue(fld, value);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message