openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r882172 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed...
Date Thu, 19 Nov 2009 15:12:37 GMT
Author: faywang
Date: Thu Nov 19 15:12:36 2009
New Revision: 882172

URL: http://svn.apache.org/viewvc?rev=882172&view=rev
Log:
OPENJPA-1396: fix metadata-complete problem so that it will override @Transient annotation
in the entity class

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmbedXml.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractMetaDataDefaults.java
Thu Nov 19 15:12:36 2009
@@ -151,6 +151,10 @@
     }
 
     public void populate(ClassMetaData meta, int access) {
+        populate(meta, access, false);
+    }
+    
+    public void populate(ClassMetaData meta, int access, boolean ignoreTransient) {
         if (meta.getDescribedType() == Object.class)
             return;
         meta.setAccessType(access);
@@ -161,7 +165,7 @@
         if (!_pcRegistry || !populateFromPCRegistry(meta)) {
             if (log.isTraceEnabled())
                 log.trace(_loc.get("meta-reflect"));
-            populateFromReflection(meta);
+            populateFromReflection(meta, ignoreTransient);
         }
     }
 
@@ -197,15 +201,15 @@
         }
     }
 
-    protected abstract List<Member> getPersistentMembers(ClassMetaData meta);
+    protected abstract List<Member> getPersistentMembers(ClassMetaData meta, boolean
ignoreTransient);
     /**
      * Generate the given meta-data using reflection.
      * Adds FieldMetaData for each persistent state.
      * Delegate to concrete implementation to determine the persistent
      * members.
      */
-    private void populateFromReflection(ClassMetaData meta) {
-        List<Member> members = getPersistentMembers(meta);
+    private void populateFromReflection(ClassMetaData meta, boolean ignoreTransient) {
+        List<Member> members = getPersistentMembers(meta, ignoreTransient);
         boolean iface = meta.getDescribedType().isInterface();
         // If access is mixed or if the default is currently unknown, 
         // process all fields, otherwise only process members of the class  
@@ -220,7 +224,7 @@
             if (name == null || isReservedFieldName(name))
                 continue;
 
-            def = isDefaultPersistent(meta, member, name);
+            def = isDefaultPersistent(meta, member, name, ignoreTransient);
             if (!def && _ignore)
                 continue;
 
@@ -311,7 +315,7 @@
      * @param name the field name from {@link #getFieldName}
      */
     protected abstract boolean isDefaultPersistent(ClassMetaData meta,
-        Member member, String name);
+        Member member, String name, boolean ignoreTransient);
 
     /**
      * Gets the backing member of the given field. If the field has not been

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataDefaults.java
Thu Nov 19 15:12:36 2009
@@ -81,6 +81,13 @@
     public void populate(ClassMetaData meta, int access);
 
     /**
+     * Populate the given metadata with default settings.
+     *
+     * @param access access type constant from {@link ClassMetaData}
+     */
+    public void populate(ClassMetaData meta, int access, boolean ignoreTransient);
+
+    /**
      * Return the backing member for the given field metadata.
      */
     public Member getBackingMember(FieldMetaData field);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Thu Nov 19 15:12:36 2009
@@ -889,11 +889,22 @@
      *            the access type to use in populating metadata
      */
     public ClassMetaData addMetaData(Class<?> cls, int access) {
+        return addMetaData(cls, access, false);
+    }
+    
+    /**
+     * Create a new metadata, populate it with default information, add it to the repository,
and
+     * return it.
+     * 
+     * @param access
+     *            the access type to use in populating metadata
+     */
+    public ClassMetaData addMetaData(Class<?> cls, int access, boolean ignoreTransient)
{
         if (cls == null || cls.isPrimitive())
             return null;
 
         ClassMetaData meta = newClassMetaData(cls);
-        _factory.getDefaults().populate(meta, access);
+        _factory.getDefaults().populate(meta, access, ignoreTransient);
 
         // synchronize on this rather than the map, because all other methods
         // that access _metas are synchronized on this

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
Thu Nov 19 15:12:36 2009
@@ -128,6 +128,9 @@
     public void populate(ClassMetaData meta, int access) {
     }
 
+    public void populate(ClassMetaData meta, int access, boolean ignoreTransient) {
+    }
+
     public Member getBackingMember(FieldMetaData fmd) {
         return null;
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmbedXml.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmbedXml.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmbedXml.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EmbedXml.java
Thu Nov 19 15:12:36 2009
@@ -19,13 +19,17 @@
 package org.apache.openjpa.persistence.embed;
 
 import javax.persistence.Embeddable;
+import javax.persistence.Transient;
 
+@Embeddable
 public class EmbedXml {
     // owned by BasicA via Embed4
     // can not contain a collection of basic types if BasicA contains 
     // a collection of Embed4 
     protected int intVal1;
     protected int intVal2;
+    
+    @Transient
     protected int intVal3;
     
     public int getIntVal1() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
Thu Nov 19 15:12:36 2009
@@ -259,13 +259,7 @@
 	</embeddable>
 
 	<embeddable class="org.apache.openjpa.persistence.embed.EmbedXml"
-		access="FIELD">
-		<attributes>
-			<basic name="intVal1"></basic>
-			<basic name="intVal2"></basic>
-			<basic name="intVal3"></basic>
-		</attributes>
-	</embeddable>
+		access="FIELD"  metadata-complete="true"/>
 
     <embeddable class="org.apache.openjpa.persistence.embed.attrOverrides.BasicEmbedXML">
         <attributes>

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
Thu Nov 19 15:12:36 2009
@@ -145,11 +145,20 @@
      * no strategy.
      */
     public static PersistenceStrategy getPersistenceStrategy
-        (FieldMetaData fmd, Member member) {
+    (FieldMetaData fmd, Member member) {
+        return getPersistenceStrategy(fmd, member, false);
+    }
+    
+    /**
+     * Return the code for the strategy of the given member. Return null if
+     * no strategy.
+     */
+    public static PersistenceStrategy getPersistenceStrategy
+        (FieldMetaData fmd, Member member, boolean ignoreTransient) {
         if (member == null)
             return null;
         AnnotatedElement el = (AnnotatedElement) member;
-        if ((AccessController.doPrivileged(J2DoPrivHelper
+        if (!ignoreTransient && (AccessController.doPrivileged(J2DoPrivHelper
             .isAnnotationPresentAction(el, Transient.class))).booleanValue())
             return TRANSIENT;
         if (fmd != null
@@ -248,13 +257,26 @@
      */
     @Override
     public void populate(ClassMetaData meta, int access) {
+        populate(meta, access, false);
+    }
+    
+    /**
+     * Populates the given class metadata. The access style determines which
+     * field and/or getter method will contribute as the persistent property
+     * of the given class. If the given access is unknown, then the access
+     * type is to be determined at first. 
+     * 
+     * @see #determineAccessType(ClassMetaData)
+     */
+    @Override
+    public void populate(ClassMetaData meta, int access, boolean ignoreTransient) {
     	if (AccessCode.isUnknown(access)) {
     		access = determineAccessType(meta);
     	}
     	if (AccessCode.isUnknown(access)) {
     		error(meta, _loc.get("access-unknown", meta));
     	}
-        super.populate(meta, access);
+        super.populate(meta, access, ignoreTransient);
         meta.setDetachable(true);
         // do not call get*Fields as it will lock down the fields.
     }
@@ -425,7 +447,7 @@
      * Gets the fields that are possible candidate for being persisted. The  
      * result depends on the current access style of the given class. 
      */
-    List<Field> getPersistentFields(ClassMetaData meta) {
+    List<Field> getPersistentFields(ClassMetaData meta, boolean ignoreTransient) {
     	boolean explicit = meta.isExplicitAccess();
     	boolean unknown  = AccessCode.isUnknown(meta);
     	boolean isField  = AccessCode.isField(meta);
@@ -434,7 +456,8 @@
     		Field[] fields = AccessController.doPrivileged(J2DoPrivHelper.
                 getDeclaredFieldsAction(meta.getDescribedType()));
     		
-        	return filter(fields, fieldFilter, nonTransientFilter, 
+        	return filter(fields, fieldFilter, 
+        	    ignoreTransient ? null : nonTransientFilter, 
         		unknown || isField  ? null : annotatedFilter, 
         	    explicit ? (isField ? null : fieldAccessFilter) : null);
     	} 
@@ -445,7 +468,7 @@
      * Gets the methods that are possible candidate for being persisted. The  
      * result depends on the current access style of the given class. 
      */
-    List<Method> getPersistentMethods(ClassMetaData meta) {
+    List<Method> getPersistentMethods(ClassMetaData meta, boolean ignoreTransient)
{
     	boolean explicit = meta.isExplicitAccess();
     	boolean unknown  = AccessCode.isUnknown(meta.getAccessType());
     	boolean isProperty  = AccessCode.isProperty(meta.getAccessType());
@@ -455,7 +478,8 @@
               J2DoPrivHelper.getDeclaredMethodsAction(meta.getDescribedType()));
         
     		List<Method> getters = filter(publicMethods, methodFilter, 
-                getterFilter, nonTransientFilter, 
+                getterFilter, 
+                ignoreTransient ? null : nonTransientFilter, 
         		unknown || isProperty ? null : annotatedFilter, 
                 explicit ? (isProperty ? null : propertyAccessFilter) : null);
     		List<Method> setters = filter(publicMethods, setterFilter);
@@ -475,10 +499,10 @@
      * no access type set, this method will set it.
      */
     @Override
-    public List<Member> getPersistentMembers(ClassMetaData meta) {
+    public List<Member> getPersistentMembers(ClassMetaData meta, boolean ignoreTransient)
{
     	List<Member> members = new ArrayList<Member>();
-    	List<Field> fields   = getPersistentFields(meta);
-    	List<Method> getters = getPersistentMethods(meta);
+    	List<Field> fields   = getPersistentFields(meta, ignoreTransient);
+    	List<Method> getters = getPersistentMethods(meta, ignoreTransient);
     	
     	boolean isMixed = !fields.isEmpty() && !getters.isEmpty();
     	boolean isEmpty = fields.isEmpty() && getters.isEmpty();
@@ -532,16 +556,21 @@
     
     @Override
     protected List<String> getFieldAccessNames(ClassMetaData meta) {
-    	return toNames(getPersistentFields(meta));
+    	return toNames(getPersistentFields(meta, false));
     }
 
     @Override
     protected List<String> getPropertyAccessNames(ClassMetaData meta) {
-    	return toNames(getPersistentMethods(meta));
+    	return toNames(getPersistentMethods(meta, false));
     }
 
     protected boolean isDefaultPersistent(ClassMetaData meta, Member member,
         String name) {
+        return isDefaultPersistent(meta, member, name, false);
+    }
+    
+    protected boolean isDefaultPersistent(ClassMetaData meta, Member member,
+        String name, boolean ignoreTransient) {
         int mods = member.getModifiers();
         if (Modifier.isTransient(mods))
             return false;
@@ -581,7 +610,7 @@
             }
         }
 
-        PersistenceStrategy strat = getPersistenceStrategy(null, member);
+        PersistenceStrategy strat = getPersistenceStrategy(null, member, ignoreTransient);
         if (strat == null || strat == PersistenceStrategy.TRANSIENT)
             return false;
         return true;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?rev=882172&r1=882171&r2=882172&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Thu Nov 19 15:12:36 2009
@@ -829,8 +829,10 @@
     @Override
     protected boolean startClass(String elem, Attributes attrs)
         throws SAXException {
+        boolean metaDataComplete = false;
         super.startClass(elem, attrs);
         if (isMetaDataComplete(attrs)) {
+            metaDataComplete = true;
         	setAnnotationParser(null);
         } else if (!_isXMLMappingMetaDataComplete){
         	resetAnnotationParser();
@@ -874,7 +876,13 @@
             // be UNKNOWN)
             if (accessCode == AccessCode.UNKNOWN)
                 accessCode = _access;
-            meta = repos.addMetaData(_cls, accessCode);
+            meta = repos.addMetaData(_cls, accessCode, metaDataComplete);
+            FieldMetaData[] fmds = meta.getFields();
+            if (metaDataComplete) {
+                for (int i = 0; i < fmds.length; i++) {
+                    fmds[i].setExplicit(true);
+                }
+            }
             meta.setEnvClassLoader(_envLoader);
             meta.setSourceMode(MODE_NONE);
 



Mime
View raw message