You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2009/09/25 19:45:50 UTC
svn commit: r818928 - in /openjpa/trunk/openjpa-persistence/src:
main/java/org/apache/openjpa/persistence/
test/java/org/apache/openjpa/persistence/
test/java/org/apache/openjpa/persistence/entity/ test/resources/META-INF/
Author: curtisr7
Date: Fri Sep 25 17:45:49 2009
New Revision: 818928
URL: http://svn.apache.org/viewvc?rev=818928&view=rev
Log:
OPENJPA-859: Handle having relational info in mapping file and annotations. Patch contributed by Rick Curtis.
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java (with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java (with props)
openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml (with props)
Modified:
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/persistence.xml
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=818928&r1=818927&r2=818928&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java Fri Sep 25 17:45:49 2009
@@ -485,21 +485,26 @@
* Read annotations for the current type.
*/
private ClassMetaData parseClassAnnotations() {
- // check immediately whether the user is using any annotations,
- // regardless of mode. this prevents adding non-entity classes to
- // repository if we're ignoring these annotations in mapping mode
- if (!(AccessController.doPrivileged(J2DoPrivHelper
- .isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
- && !(AccessController.doPrivileged(J2DoPrivHelper
- .isAnnotationPresentAction(_cls, Embeddable.class)))
- .booleanValue()
- && !(AccessController.doPrivileged(J2DoPrivHelper
- .isAnnotationPresentAction(_cls, MappedSuperclass.class)))
- .booleanValue())
- return null;
-
+ // Check to see if there is cached metadata for the class that we are currently parsing. It is possible
+ // that one of the annotations (Entity, Embeddable, MappedSuperclass) is in the orm.xml. We still need to look
+ // at these files for other annotations and more importantly setup defaults (ie: Basic fields).
+ ClassMetaData m = getRepository().getCachedMetaData(_cls);
+ if(m == null) {
+ // check immediately whether the user is using any annotations,
+ // regardless of mode. this prevents adding non-entity classes to
+ // repository if we're ignoring these annotations in mapping mode
+ if (!(AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
+ && !(AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, Embeddable.class)))
+ .booleanValue()
+ && !(AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, MappedSuperclass.class)))
+ .booleanValue())
+ return null;
+ }
// find / create metadata
- ClassMetaData meta = getMetaData();
+ ClassMetaData meta = (m == null) ? getMetaData() : m;
if (meta == null)
return null;
Added: openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java?rev=818928&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java (added)
+++ openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java Fri Sep 25 17:45:49 2009
@@ -0,0 +1,39 @@
+package org.apache.openjpa.persistence;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.meta.MetaDataRepository;
+
+public class TestParsing extends TestCase {
+
+ /**
+ * Testcase for added OPENJPA-859.
+ *
+ * This scenario is testing whether the default annotations are being generated for a class that
+ * isn't annotated with a persistence class type (ie: @Entity, @Mapped-Superclass, @Embeddable),
+ * but it is in a mapping file.
+ *
+ * @throws Exception
+ */
+ public void testMixedOrmAnno() throws Exception {
+ PersistenceProductDerivation pd = new PersistenceProductDerivation();
+ Map<String, String> m = new HashMap<String, String>();
+
+ ConfigurationProvider cp = pd.load("", "test_parsing", m);
+ OpenJPAConfigurationImpl conf = new OpenJPAConfigurationImpl(true, true);
+ cp.setInto(conf);
+
+ MetaDataRepository mdr = conf.getMetaDataRepositoryInstance();
+ Set<String> classes = mdr.getPersistentTypeNames(false, null);
+ for (String c : classes) {
+ Class cls = Class.forName(c);
+ mdr.getMetaData(cls, null, true);
+ }
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java?rev=818928&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java (added)
+++ openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java Fri Sep 25 17:45:49 2009
@@ -0,0 +1,17 @@
+package org.apache.openjpa.persistence.entity;
+
+import javax.persistence.Basic;
+import javax.persistence.Id;
+
+/**
+ * This class doesn't have an @Entity and @Basic on purpose.
+ */
+public class MixedMappingLocation {
+ @Id
+ int id;
+
+ String basic1;
+
+ @Basic
+ String basic2;
+}
Propchange: openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/entity/MixedMappingLocation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml?rev=818928&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml (added)
+++ openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml Fri Sep 25 17:45:49 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+ <entity class="org.apache.openjpa.persistence.entity.MixedMappingLocation">
+ <attributes>
+ <basic name="basic1">
+ <column name="basic1_override" length="100"/>
+ </basic>
+ </attributes>
+ </entity>
+</entity-mappings>
Propchange: openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/persistence.xml?rev=818928&r1=818927&r2=818928&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence/src/test/resources/META-INF/persistence.xml Fri Sep 25 17:45:49 2009
@@ -43,4 +43,8 @@
<persistence-unit name="exclude_true">
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
+ <persistence-unit name="test_parsing">
+ <mapping-file>META-INF/parsing-orm.xml</mapping-file>
+ <class>org.apache.openjpa.persistence.entity.MixedMappingLocation</class>
+ </persistence-unit>
</persistence>