openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r641842 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
Date Thu, 27 Mar 2008 15:08:09 GMT
Author: allee8285
Date: Thu Mar 27 08:08:07 2008
New Revision: 641842

URL: http://svn.apache.org/viewvc?rev=641842&view=rev
Log:
OPENJPA-417 - add openjpa.Compability(StoreMapCollectionInEntityAsBlob=true) option to enable
map/collection stores as Blob in the database. This allows existing application continues
to work.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMapCollectionToBlob.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.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=641842&r1=641841&r2=641842&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
Thu Mar 27 08:08:07 2008
@@ -883,6 +883,9 @@
      */
     protected FieldStrategy handlerCollectionStrategy(FieldMapping field, 
         ValueHandler ehandler, boolean installHandlers) {
+        if (getConfiguration().getCompatibilityInstance()
+            .isStoreMapCollectionInEntityAsBlob())
+            return null;
         if (installHandlers)
             field.getElementMapping().setHandler(ehandler);
         return new HandlerCollectionTableFieldStrategy();
@@ -895,6 +898,9 @@
     protected FieldStrategy handlerMapStrategy(FieldMapping field, 
         ValueHandler khandler, ValueHandler vhandler, boolean krel, 
         boolean vrel,  boolean installHandlers) {
+        if (getConfiguration().getCompatibilityInstance()
+            .isStoreMapCollectionInEntityAsBlob())
+            return null;
         if (installHandlers) {
             field.getKeyMapping().setHandler(khandler);
             field.getElementMapping().setHandler(vhandler);
@@ -1077,7 +1083,9 @@
             case JavaTypes.OID:
                 return new ObjectIdValueHandler();
         }
-        if (val.isEmbeddedPC())
+        if (!getConfiguration().getCompatibilityInstance()
+            .isStoreMapCollectionInEntityAsBlob()
+            && val.isEmbeddedPC())
             return new ElementEmbedValueHandler();
         return null;
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java?rev=641842&r1=641841&r2=641842&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java
Thu Mar 27 08:08:07 2008
@@ -54,6 +54,7 @@
     private boolean _quotedNumbers = false;
     private boolean _nonOptimisticVersionCheck = false;
     private int _jpql = JPQL_STRICT;
+    private boolean _storeMapCollectionInEntityAsBlob = false;
 
     /**
      * Whether to require exact identity value types when creating object
@@ -214,5 +215,26 @@
             _jpql = JPQL_EXTENDED;
         else
             throw new IllegalArgumentException(jpql);
+    }
+
+    /**
+     * Whether if map and collection in entity are stored as blob.
+     * Defaults to <code>false</code>.
+     *
+     * @since 1.1.0 
+     */
+
+    public boolean isStoreMapCollectionInEntityAsBlob() {
+        return _storeMapCollectionInEntityAsBlob;
+    }
+
+    /**
+     * Whether if map and collection in entity are stored as blob.
+     * Defaults to <code>false</code>.
+     *
+     * @since 1.1.0 
+     */
+    public void setStoreMapCollectionInEntityAsBlob(boolean storeAsBlob) {
+        _storeMapCollectionInEntityAsBlob = storeAsBlob;
     }
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMapCollectionToBlob.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMapCollectionToBlob.java?rev=641842&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMapCollectionToBlob.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestMapCollectionToBlob.java
Thu Mar 27 08:08:07 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.relations;
+
+import java.sql.Types;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestMapCollectionToBlob
+    extends SingleEMTestCase {
+
+    public void setUp() {
+        setUp(HandlerToHandlerMapInstance.class, CLEAR_TABLES,
+            "openjpa.Compatibility", "StoreMapCollectionInEntityAsBlob=true");
+    }
+
+    public void testHandlerToHandlerMaps() {
+        ClassMapping cm = (ClassMapping) JPAFacadeHelper.getMetaData(em,
+            HandlerToHandlerMapInstance.class);
+        FieldMapping fm = cm.getFieldMapping("map");        
+        assertEquals(HandlerFieldStrategy.class, fm.getStrategy().getClass());
+        assertEquals("NONSTD_MAPPING_MAP", fm.getTable().getName());
+        assertEquals(fm.getTable().getColumn("MAP").getType(), Types.BLOB);
+
+        HandlerToHandlerMapInstance o = new HandlerToHandlerMapInstance();
+        o.getMap().put("foo", "bar");
+        em.getTransaction().begin();
+        em.persist(o);
+        em.getTransaction().commit();
+        em.close();
+    }
+}



Mime
View raw message