Author: ppoddar
Date: Wed Aug 23 16:45:42 2006
New Revision: 434251

URL: http://svn.apache.org/viewvc?rev=434251&view=rev
Log:
MappingTool modified to ignore persistence-aware classes

Modified:
    
incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
    
incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties

Modified: 
incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=434251&r1=434250&r2=434251&view=diff
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
 (original)
+++ 
incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
 Wed Aug 23 16:45:42 2006
@@ -51,14 +51,7 @@
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.lib.util.Services;
-import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.meta.FieldMetaData;
-import org.apache.openjpa.meta.JavaTypes;
-import org.apache.openjpa.meta.MetaDataFactory;
-import org.apache.openjpa.meta.MetaDataModes;
-import org.apache.openjpa.meta.QueryMetaData;
-import org.apache.openjpa.meta.SequenceMetaData;
-import org.apache.openjpa.meta.ValueStrategies;
+import org.apache.openjpa.meta.*;
 import org.apache.openjpa.util.GeneralException;
 import org.apache.openjpa.util.InternalException;
 import org.apache.openjpa.util.MetaDataException;
@@ -643,9 +636,7 @@
 
         _flush = true;
         _flushSchema = true;
-        MappingRepository repos = getRepository();
-        repos.setStrategyInstaller(new MappingStrategyInstaller(repos));
-        repos.getMapping(cls, null, true);
+        getMapping(cls);
     }
 
     /**
@@ -682,9 +673,7 @@
 
         _flush = true;
         _flushSchema = true;
-        MappingRepository repos = getRepository();
-        repos.setStrategyInstaller(new RefreshStrategyInstaller(repos));
-        repos.getMapping(cls, null, true);
+        getMapping(cls);
     }
 
     /**
@@ -696,9 +685,7 @@
 
         _flushSchema = !SCHEMA_ACTION_NONE.equals(_schemaAction)
             && !SchemaTool.ACTION_ADD.equals(_schemaAction);
-        MappingRepository repos = getRepository();
-        repos.setStrategyInstaller(new RuntimeStrategyInstaller(repos));
-        repos.getMapping(cls, null, true);
+        getMapping(cls);
     }
 
     /**
@@ -709,9 +696,8 @@
             return;
 
         _flushSchema = true;
-        MappingRepository repos = getRepository();
-        repos.setStrategyInstaller(new RuntimeStrategyInstaller(repos));
-        repos.getMapping(cls, null, true);
+        if (!getMapping(cls))
+               return;
 
         // set any logical pks to non-logical so they get flushed
         Schema[] schemas = _schema.getSchemas();
@@ -732,6 +718,33 @@
     }
 
     /**
+     * Gets mapping for the given class. 
+     * If the repository does not contain metadata for the class and raises
+     * a non-fatal exception on lookup, the exception is swallowed with a
+     * warning message, as the class is likely to be a persistence-aware class.
+     * 
+     * @param cls a class to be mapped
+     * 
+     * @return true if the mapping of the class is found, false otherwise.
+     */
+    boolean getMapping(Class cls) {
+       MappingRepository repos = getRepository();
+       repos.setStrategyInstaller(new RuntimeStrategyInstaller(repos));
+       try {
+               repos.getMapping(cls, null, true);
+       } catch (MetaDataException mex) {
+               if (!mex.isFatal()) {
+                       if (_log != null && _log.isWarnEnabled()) {
+                               _log.warn(_loc.get("no-mapping-aware",cls));
+                       }
+                       return false;
+               } else {
+                       throw mex;
+               }
+       }
+       return true;
+    }
+    /**
      * Drop mapping for given class.
      */
     private void drop(Class cls) {
@@ -980,6 +993,9 @@
                 parsed = classParser.parseTypes(args[i]);
                 classes.addAll(Arrays.asList(parsed));
             }
+            PersistenceAwareClass[] pawares = 
conf.getMappingRepositoryInstance().getPersistenceAwareClasses();
+            for (int i=0; i<pawares.length; i++)
+               classes.remove(pawares[i].getDescribedType());
         }
 
         Class[] act = (Class[]) classes.toArray(new Class[classes.size()]);

Modified: 
incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
URL: 
http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties?rev=434251&r1=434250&r2=434251&view=diff
==============================================================================
--- 
incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
 (original)
+++ 
incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
 Wed Aug 23 16:45:42 2006
@@ -9,6 +9,8 @@
 bad-equiv-field: Cannot use "{0}" as the mapped-by value for a field in "{1}". 
\
        The target-field "{2}" for column "{3}" is mapped to multiple columns.
 no-mapping: No mapping information found for type "{0}".
+no-mapping-aware: No mapping information found for type "{0}". Assuming to be \
+       persistence-aware.
 bad-mapped-by: Collection field "{0}" declares that it is mapped by "{1}", but 
\
        this is not a valid inverse relation.
 no-targetfield: Some of the columns on "{0}" are missing target field \


Reply via email to