openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r942871 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ open...
Date Mon, 10 May 2010 19:46:21 GMT
Author: curtisr7
Date: Mon May 10 19:46:21 2010
New Revision: 942871

URL: http://svn.apache.org/viewvc?rev=942871&view=rev
Log:
OPENJPA-1612: Check for having a relationship to a type that is mapped to a blob field.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingRepository.java
    openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ConstantJoinPC4.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/BlobTest.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=942871&r1=942870&r2=942871&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
Mon May 10 19:46:21 2010
@@ -883,6 +883,13 @@ public class MappingRepository extends M
 
         // default to blob
         if (installHandlers) {
+            int type = field.getAssociationType();
+            // Having a ONE_TO_ONE, ONE_TO_MANY, MANY_TO_ONE, or MANY_TO_MANY relationship

+            // type as a blob is incorrect
+            if (type >= FieldMetaData.ONE_TO_ONE && type <= FieldMetaData.MANY_TO_MANY)
{
+                throw new UserException(_loc.get("invalid-mapping", field));
+            }
+
             if (getLog().isWarnEnabled())
                 getLog().warn(_loc.get("no-field-strategy", field));
             field.setSerialized(true);

Modified: openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties?rev=942871&r1=942870&r2=942871&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
Mon May 10 19:46:21 2010
@@ -417,4 +417,5 @@ unique-no-table: A unique constraint on 
 	table "{2}" nor any of its secondary table(s) "{3}".
 bad-version-column-table: One of the version column "{0}" has been associated \
 	with table "{1}", but no primary or secondary table of such name exists.
-version-type-unsupported: Version field "{0}" of {1} is not supported. 
\ No newline at end of file
+version-type-unsupported: Version field "{0}" of {1} is not supported. 
+invalid-mapping: The field "{0}" is an invalid type. Relationship fields must be a valid
Entity type.

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ConstantJoinPC4.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ConstantJoinPC4.java?rev=942871&r1=942870&r2=942871&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ConstantJoinPC4.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/ConstantJoinPC4.java
Mon May 10 19:46:21 2010
@@ -34,7 +34,7 @@ public class ConstantJoinPC4
 
 	@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
 	private ConstantJoinPC5 oneToOne1;
-	@ManyToMany
+	
 	private Set manyToMany = new HashSet ();
 
 	public ConstantJoinPC4()

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/BlobTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/BlobTest.java?rev=942871&r1=942870&r2=942871&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/BlobTest.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/BlobTest.java
Mon May 10 19:46:21 2010
@@ -18,12 +18,14 @@
  */
 package org.apache.openjpa.persistence.kernel.common.apps;
 
+import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.Lob;
 import javax.persistence.OneToOne;
 
 @Entity
@@ -34,13 +36,12 @@ public class BlobTest {
     private int id;
 
     @Column(name = "blobtab")
-    @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
-    private Object blob;
+    private byte[] blob;
 
     public BlobTest() {
     }
 
-    public void setBlob(Object blob) {
+    public void setBlob(byte[] blob) {
         this.blob = blob;
     }
 

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java?rev=942871&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java
Mon May 10 19:46:21 2010
@@ -0,0 +1,37 @@
+/*
+ * 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.meta;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+
+@Entity
+public class InvalidMappingFieldEntity {
+
+    @Id
+    int id;
+    
+    @ManyToOne
+    Object o; 
+    
+    @OneToOne
+    InvalidMappingFieldEntity other;
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/InvalidMappingFieldEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java?rev=942871&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java
Mon May 10 19:46:21 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.meta;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.util.UserException;
+
+public class TestMappingRepository extends SingleEMFTestCase {
+    @Override
+    protected void setUp(Object... props) {
+        super.setUp(InvalidMappingFieldEntity.class, "openjpa.jdbc.SynchronizeMappings",
"false");
+    }
+
+    public void test() {
+        try {
+            OpenJPAEntityManagerSPI em = emf.createEntityManager();
+            emf.getConfiguration().getMetaDataRepositoryInstance().getMetaData(InvalidMappingFieldEntity.class,
null,
+                true);
+            fail("Shouldn't be able to create an em with this Entity type.");
+        } catch (UserException e) {
+            // expected
+        }
+
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMappingRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message