You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by aw...@apache.org on 2006/08/24 21:05:52 UTC
svn commit: r434473 - in /incubator/openjpa/trunk/openjpa-jdbc/src/main:
java/org/apache/openjpa/jdbc/meta/MappingTool.java
resources/org/apache/openjpa/jdbc/meta/localizer.properties
Author: awhite
Date: Thu Aug 24 12:05:51 2006
New Revision: 434473
URL: http://svn.apache.org/viewvc?rev=434473&view=rev
Log:
Slightly cleaner and in some cases more efficient exclusion of
persistence-aware types from mapping tool actions.
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=434473&r1=434472&r2=434473&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 Thu Aug 24 12:05:51 2006
@@ -641,11 +641,28 @@
if (cls == null)
return;
- _flush = true;
- _flushSchema = true;
MappingRepository repos = getRepository();
repos.setStrategyInstaller(new MappingStrategyInstaller(repos));
- getMapping(repos, cls);
+ if (getMapping(repos, cls, true) != null) {
+ _flush = true;
+ _flushSchema = true;
+ }
+ }
+
+ /**
+ * Return the mapping for the given type, or null if the type is
+ * persistence-aware.
+ */
+ private static ClassMapping getMapping(MappingRepository repos, Class cls,
+ boolean validate) {
+ // this will parse all possible metadata rsrcs looking for cls, so
+ // will detect if p-aware
+ ClassMapping mapping = repos.getMapping(cls, null, false);
+ if (mapping != null)
+ return mapping;
+ if (!validate || repos.getPersistenceAware(cls) != null)
+ return null;
+ throw new MetaDataException(_loc.get("no-meta", cls));
}
/**
@@ -680,11 +697,12 @@
if (cls == null)
return;
- _flush = true;
- _flushSchema = true;
MappingRepository repos = getRepository();
repos.setStrategyInstaller(new RefreshStrategyInstaller(repos));
- getMapping(repos, cls);
+ if (getMapping(repos, cls, true) != null) {
+ _flush = true;
+ _flushSchema = true;
+ }
}
/**
@@ -694,11 +712,11 @@
if (cls == null)
return;
- _flushSchema = !SCHEMA_ACTION_NONE.equals(_schemaAction)
- && !SchemaTool.ACTION_ADD.equals(_schemaAction);
MappingRepository repos = getRepository();
repos.setStrategyInstaller(new RuntimeStrategyInstaller(repos));
- getMapping(repos, cls);
+ if (getMapping(repos, cls, true) != null)
+ _flushSchema = !SCHEMA_ACTION_NONE.equals(_schemaAction)
+ && !SchemaTool.ACTION_ADD.equals(_schemaAction);
}
/**
@@ -708,13 +726,13 @@
if (cls == null)
return;
- _flushSchema = true;
MappingRepository repos = getRepository();
repos.setStrategyInstaller(new RuntimeStrategyInstaller(repos));
- if (!getMapping(repos, cls))
- return;
+ if (getMapping(repos, cls, true) == null)
+ return;
// set any logical pks to non-logical so they get flushed
+ _flushSchema = true;
Schema[] schemas = _schema.getSchemas();
Table[] tables;
Column[] cols;
@@ -733,31 +751,6 @@
}
/**
- * 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(MappingRepository repos, Class cls) {
- 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) {
@@ -792,10 +785,10 @@
////////
/**
- * Usage: java org.apache.openjpa.jdbc.meta.MappingTool [option]* [-action/-a
- * <refresh | add | buildSchema | drop | validate | import | export>]
- * <class name | .java file | .class file | .jdo file>*
- * Where the following options are recognized.
+ * Usage: java org.apache.openjpa.jdbc.meta.MappingTool [option]*
+ * [-action/-a <refresh | add | buildSchema | drop | validate | import
+ * | export>] <class name | .java file | .class file | .jdo file>*
+ * Where the following options are recognized.
* <ul>
* <li><i>-properties/-p <properties file or resource></i>: The
* path or resource name of a OpenJPA properties file containing
@@ -828,8 +821,8 @@
* same-named option in the {@link SchemaTool}.</li>
* <li><i>-dropSequences/-dsq <true/t | false/f></i>: Corresponds
* to the same-named option in the {@link SchemaTool}.</li>
- * <li><i>-openjpaTables/-kt <true/t | false/f></i>: Corresponds to the
- * same-named option in the {@link SchemaTool}.</li>
+ * <li><i>-openjpaTables/-kt <true/t | false/f></i>: Corresponds to
+ * the same-named option in the {@link SchemaTool}.</li>
* <li><i>-ignoreErrors/-i <true/t | false/f></i>: Corresponds to the
* same-named option in the {@link SchemaTool}.</li>
* <li><i>-readSchema/-rs <true/t | false/f></i>: Set this to true
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=434473&r1=434472&r2=434473&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 Thu Aug 24 12:05:51 2006
@@ -9,8 +9,6 @@
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 \
@@ -290,6 +288,7 @@
Undropped mappings will not affect the system.
no-drop-meta: The schema for type "{0}" may not be dropped, because its \
mapping could not be parsed.
+no-meta: Type "{0}" does not have persistence metadata.
bad-bk-file: Could not create a backup file for "{0}".
running-all-classes: No targets were given. Running on all classes listed in \
your configuration, or all persistent classes in the classpath if no \