openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r1024306 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/
Date Tue, 19 Oct 2010 16:14:52 GMT
Author: faywang
Date: Tue Oct 19 16:14:51 2010
New Revision: 1024306

URL: http://svn.apache.org/viewvc?rev=1024306&view=rev
Log:
OPENJPA-1837: fix the MaxEmbeddedLobFieldStrategy when there is limitation of max lob size
and when the field is in an embeddable which is contained in an element collection. 

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedBlobFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedByteArrayFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedCharArrayFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedClobFieldStrategy.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedLobFieldStrategy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
Tue Oct 19 16:14:51 2010
@@ -842,8 +842,14 @@ public class MappingRepository extends M
         }
 
         if (field.isSerialized()) {
-            if (_dict.maxEmbeddedBlobSize != -1)
+            if (_dict.maxEmbeddedBlobSize != -1) {
+                handler = defaultHandler(field, adapting);
+                if (handler != null) {
+                    if (installHandlers)
+                        field.setHandler(handler);
+                }
                 return new MaxEmbeddedBlobFieldStrategy();
+            }
         } else {
             // check for mapped strategy
             Object strat = mappedStrategy(field, field.getType(), adapting);
@@ -859,18 +865,36 @@ public class MappingRepository extends M
         // check for known field strategies
         if (!field.isSerialized() && (field.getType() == byte[].class
             || field.getType() == Byte[].class)) {
-            if (_dict.maxEmbeddedBlobSize != -1)
+            if (_dict.maxEmbeddedBlobSize != -1) {
+                handler = defaultHandler(field, adapting);
+                if (handler != null) {
+                    if (installHandlers)
+                        field.setHandler(handler);
+                }
                 return new MaxEmbeddedByteArrayFieldStrategy();
+            }
         } else if (!field.isSerialized()
             && (field.getType() == char[].class
             || field.getType() == Character[].class)) {
-            if (_dict.maxEmbeddedClobSize != -1 && isClob(field, false))
+            if (_dict.maxEmbeddedClobSize != -1 && isClob(field, false)) {
+                handler = defaultHandler(field, adapting);
+                if (handler != null) {
+                    if (installHandlers)
+                        field.setHandler(handler);
+                }
                 return new MaxEmbeddedCharArrayFieldStrategy();
+            }
         } else if (!field.isSerialized()) {
             FieldStrategy strat = defaultTypeStrategy(field, installHandlers,
                 adapting);
-            if (strat != null)
+            if (strat != null) {
+                handler = defaultHandler(field, adapting);
+                if (handler != null) {
+                    if (installHandlers)
+                        field.setHandler(handler);
+                }
                 return strat;
+            }
         }
 
         // check for default handler

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedValueHandler.java
Tue Oct 19 16:14:51 2010
@@ -180,7 +180,7 @@ public abstract class EmbedValueHandler
             if (ecols.length == 0)
                 continue;
 
-            cval = (em == null) ? null : em.fetch(i);
+            cval = (em == null) ? null : getValue(embed, em, i);
             cval = embed.toEmbeddedDataStoreValue(cval, store);
             if (cols.length == 1) {
                 // rvals is empty
@@ -196,6 +196,13 @@ public abstract class EmbedValueHandler
         }
         return idx;
     }
+    
+    private Object getValue(Embeddable embed, OpenJPAStateManager sm, int idx) {
+        if (embed instanceof MaxEmbeddedLobFieldStrategy) {
+            return ((MaxEmbeddedLobFieldStrategy)embed).getValue(sm);
+        }
+        return sm.fetch(idx);
+    }
 
     /**
      * Helper to convert a datastore value to its object equivalent.

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -60,11 +60,11 @@ public class HandlerFieldStrategy
     private static final Localizer _loc = Localizer.forPackage
         (HandlerFieldStrategy.class);
 
-    private Column[] _cols = null;
-    private ColumnIO _io = null;
-    private Object[] _args = null;
-    private boolean _load = false;
-    private boolean _lob = false;
+    protected Column[] _cols = null;
+    protected ColumnIO _io = null;
+    protected Object[] _args = null;
+    protected boolean _load = false;
+    protected boolean _lob = false;
 
     public void map(boolean adapt) {
         if (field.getHandler() == null)

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedBlobFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedBlobFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedBlobFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedBlobFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -105,4 +105,13 @@ public class MaxEmbeddedBlobFieldStrateg
         _maxSize = dict.maxEmbeddedBlobSize;
         field.setUsesImplData(Boolean.TRUE);
     }
+    
+    protected Object getValue(OpenJPAStateManager sm) {
+        byte[] b = (byte[]) sm.getImplData(field.getIndex());
+        if (b == null || (b.length > _maxSize && !field.getColumns()[0].isNotNull()))
+            return null;
+        sm.setImplData(field.getIndex(), null);
+        DBDictionary.SerializedData dat = new DBDictionary.SerializedData(b);
+        return dat;
+    }    
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedByteArrayFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedByteArrayFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedByteArrayFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedByteArrayFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -56,9 +56,8 @@ public class MaxEmbeddedByteArrayFieldSt
 
     protected void update(OpenJPAStateManager sm, Row row)
         throws SQLException {
-        byte[] b = PrimitiveWrapperArrays.toByteArray(sm.fetchObject
-            (field.getIndex()));
-        if (b == null || (b.length > _maxSize && !field.getColumns()[0].isNotNull()))
+        byte[] b = (byte[]) getValue(sm);
+         if (b == null)
             row.setBytes(field.getColumns()[0], null);
         else
             row.setBytes(field.getColumns()[0], b);
@@ -94,4 +93,12 @@ public class MaxEmbeddedByteArrayFieldSt
         DBDictionary dict = field.getMappingRepository().getDBDictionary();
         _maxSize = dict.maxEmbeddedBlobSize;
     }
+    
+    protected Object getValue(OpenJPAStateManager sm) {
+        byte[] b = PrimitiveWrapperArrays.toByteArray(sm.fetchObject
+                (field.getIndex()));
+        if (b == null || (b.length > _maxSize && !field.getColumns()[0].isNotNull()))
+            return null;
+        return b;
+    }    
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedCharArrayFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedCharArrayFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedCharArrayFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedCharArrayFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -111,4 +111,13 @@ public class MaxEmbeddedCharArrayFieldSt
         DBDictionary dict = field.getMappingRepository().getDBDictionary();
         _maxSize = dict.maxEmbeddedClobSize;
     }
+    
+    protected Object getValue(OpenJPAStateManager sm) {
+        char[] c = PrimitiveWrapperArrays.
+        toCharArray(sm.fetchObject(field.getIndex()));
+        if (c == null || c.length > _maxSize)
+            return null;
+        else
+            return c;
+    }
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedClobFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedClobFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedClobFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedClobFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -52,8 +52,8 @@ public class MaxEmbeddedClobFieldStrateg
 
     protected void update(OpenJPAStateManager sm, Row row)
         throws SQLException {
-        String s = sm.fetchString(field.getIndex());
-        if (s == null || (s.length() > _maxSize && !field.getColumns()[0].isNotNull()))
+        String s = (String) getValue(sm);
+        if (s == null)
             row.setNull(field.getColumns()[0], true);
         else
             row.setString(field.getColumns()[0], s);
@@ -81,4 +81,12 @@ public class MaxEmbeddedClobFieldStrateg
         DBDictionary dict = field.getMappingRepository().getDBDictionary();
         _maxSize = dict.maxEmbeddedClobSize;
     }
+    
+    protected Object getValue(OpenJPAStateManager sm) {
+        String s = sm.fetchString(field.getIndex());
+        if (s == null || (s.length() > _maxSize && !field.getColumns()[0].isNotNull()))
{
+            return null;
+        }
+        return s;
+    }    
 }

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedLobFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedLobFieldStrategy.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedLobFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/MaxEmbeddedLobFieldStrategy.java
Tue Oct 19 16:14:51 2010
@@ -46,7 +46,7 @@ import org.apache.openjpa.meta.JavaTypes
  * @since 0.4.0
  */
 abstract class MaxEmbeddedLobFieldStrategy
-    extends AbstractFieldStrategy {
+    extends HandlerFieldStrategy {
 
     /**
      * Return the expected type of the field from {@link JavaTypes} or
@@ -95,11 +95,13 @@ abstract class MaxEmbeddedLobFieldStrate
         tmpCol.setIdentifier(fieldName);
         tmpCol.setJavaType(getExpectedJavaType());
         tmpCol.setSize(-1);
-        Column[] cols = vinfo.getColumns(field, fieldName,
+        _cols = vinfo.getColumns(field, fieldName,
             new Column[]{ tmpCol }, field.getTable(), adapt);
-
-        field.setColumns(cols);
-        field.setColumnIO(vinfo.getColumnIO());
+        _io = vinfo.getColumnIO();
+        if (_io == null)
+            _io = field.getColumnIO();
+        field.setColumns(_cols);
+        field.setColumnIO(_io);
         field.mapConstraints(fieldName, adapt);
         field.mapPrimaryKey(adapt);
     }
@@ -266,4 +268,6 @@ abstract class MaxEmbeddedLobFieldStrate
         Object prevValue)
         throws SQLException {
     }
+    
+    protected abstract Object getValue(OpenJPAStateManager sm);
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EmbedOwner.java
Tue Oct 19 16:14:51 2010
@@ -86,4 +86,8 @@ public class EmbedOwner {
     public Set<EmbedValue> getEmbedCollection() {
         return embedCollection;
     }
+
+    public void setEmbedCollection(Set<EmbedValue> embedCollection) {
+        this.embedCollection = embedCollection;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java?rev=1024306&r1=1024305&r2=1024306&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestEJBEmbedded.java
Tue Oct 19 16:14:51 2010
@@ -19,6 +19,7 @@
 package org.apache.openjpa.persistence.jdbc.annotations;
 
 import java.sql.Types;
+import java.util.HashSet;
 import java.util.Set;
 
 import javax.persistence.EntityManager;
@@ -70,6 +71,9 @@ public class TestEJBEmbedded extends Sin
         embed.setBlob("foobar".getBytes());
         embed.setOwner(owner);
         owner.setEmbed(embed);
+        Set<EmbedValue> embedVals = new HashSet<EmbedValue>();
+        embedVals.add(embed);
+        owner.setEmbedCollection(embedVals);
         em.persist(owner);
         int pk = owner.getPk();
         em.getTransaction().commit();



Mime
View raw message