Author: curtisr7
Date: Fri Sep 25 17:45:15 2009
New Revision: 818927
URL: http://svn.apache.org/viewvc?rev=818927&view=rev
Log:
OPENJPA-859: Handle having relational info in mapping file and annotations.
Patch contributed by Rick Curtis.
Added:
openjpa/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
(with props)
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
(with props)
Modified:
openjpa/branches/1.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/persistence.xml
Modified:
openjpa/branches/1.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=818927&r1=818926&r2=818927&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++
openjpa/branches/1.3.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Fri Sep 25 17:45:15 2009
@@ -464,6 +464,11 @@
* Read annotations for the current type.
*/
private ClassMetaData parseClassAnnotations() {
+ // 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
@@ -476,9 +481,9 @@
.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/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java?rev=818927&view=auto
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
(added)
+++
openjpa/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
Fri Sep 25 17:45:15 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/branches/1.3.x/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestParsing.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml?rev=818927&view=auto
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
(added)
+++
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
Fri Sep 25 17:45:15 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/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/parsing-orm.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/persistence.xml
URL:
http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/persistence.xml?rev=818927&r1=818926&r2=818927&view=diff
==============================================================================
---
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/persistence.xml
(original)
+++
openjpa/branches/1.3.x/openjpa-persistence/src/test/resources/META-INF/persistence.xml
Fri Sep 25 17:45:15 2009
@@ -32,4 +32,8 @@
</persistence-unit>
<persistence-unit name="encryption_plugin_default_pu"
transaction-type="RESOURCE_LOCAL">
</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>