From 6234f8d3da7d38864cf7c8460a23113a51313f01 Mon Sep 17 00:00:00 2001 From: Patrick Linskey Date: Tue, 8 Aug 2006 01:42:34 +0000 Subject: [PATCH] Changed logging infrastructure to be aware of localization; changed localization to return log-ready Message instances instead of strings. Changed tons of code to use the new logging and localization calls. git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@429535 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/ant/MappingToolTask.java | 3 +- .../openjpa/jdbc/ant/SchemaToolTask.java | 3 +- .../kernel/PreparedStatementManagerImpl.java | 2 +- .../openjpa/jdbc/kernel/TableJDBCSeq.java | 2 +- .../apache/openjpa/jdbc/meta/MappingInfo.java | 16 +- .../ClassNameDiscriminatorStrategy.java | 2 +- .../strats/ValueMapDiscriminatorStrategy.java | 2 +- .../openjpa/jdbc/schema/ForeignKey.java | 5 +- .../apache/openjpa/jdbc/schema/NameSet.java | 3 +- .../openjpa/jdbc/schema/SchemaGenerator.java | 5 +- .../openjpa/jdbc/schema/XMLSchemaParser.java | 5 +- .../apache/openjpa/jdbc/sql/DBDictionary.java | 3 +- .../openjpa/jdbc/sql/SQLExceptions.java | 9 + .../openjpa/jdbc/sql/localizer.properties | 1 + .../apache/openjpa/ant/MetaDataToolTask.java | 3 +- .../openjpa/conf/ProductDerivations.java | 2 +- .../org/apache/openjpa/datacache/Caches.java | 2 +- .../openjpa/datacache/DataCacheScheduler.java | 4 +- .../openjpa/enhance/PCDataGenerator.java | 8 +- .../apache/openjpa/enhance/PCEnhancer.java | 159 +++++++++--------- .../openjpa/event/LogOrphanedKeyAction.java | 4 - .../openjpa/kernel/AbstractBrokerFactory.java | 5 +- .../org/apache/openjpa/kernel/BrokerImpl.java | 2 +- .../kernel/DetachedStateAttachStrategy.java | 1 - .../openjpa/kernel/DetachedStateManager.java | 2 +- .../org/apache/openjpa/kernel/Filters.java | 2 +- .../exps/AbstractExpressionBuilder.java | 15 +- .../openjpa/kernel/jpql/ParseException.java | 10 +- .../org/apache/openjpa/meta/Extensions.java | 2 +- .../apache/openjpa/meta/UpdateStrategies.java | 5 +- .../apache/openjpa/meta/ValueStrategies.java | 5 +- .../openjpa/util/CallbackException.java | 12 +- .../apache/openjpa/util/GeneralException.java | 8 +- .../openjpa/util/InternalException.java | 12 ++ .../openjpa/util/InvalidStateException.java | 9 +- .../apache/openjpa/util/LockException.java | 7 - .../openjpa/util/MetaDataException.java | 9 +- .../openjpa/util/NoTransactionException.java | 12 +- .../openjpa/util/ObjectExistsException.java | 15 +- .../openjpa/util/ObjectNotFoundException.java | 6 +- .../apache/openjpa/util/OpenJPAException.java | 17 ++ .../openjpa/util/OptimisticException.java | 6 +- .../util/ReferentialIntegrityException.java | 9 +- .../apache/openjpa/util/StoreException.java | 13 +- .../openjpa/util/UnsupportedException.java | 8 +- .../apache/openjpa/util/UserException.java | 10 ++ .../openjpa/kernel/localizer.properties | 1 + .../apache/openjpa/lib/ant/AbstractTask.java | 2 +- .../openjpa/lib/conf/ConfigurationImpl.java | 11 +- .../openjpa/lib/conf/Configurations.java | 18 +- .../apache/openjpa/lib/conf/ObjectValue.java | 2 +- .../apache/openjpa/lib/conf/PluginValue.java | 2 +- .../openjpa/lib/jdbc/DataSourceLogs.java | 8 +- .../lib/jdbc/DelegatingConnection.java | 9 +- .../apache/openjpa/lib/log/AbstractLog.java | 13 -- .../openjpa/lib/log/CommonsLogFactory.java | 12 -- .../java/org/apache/openjpa/lib/log/Log.java | 21 +-- .../openjpa/lib/log/Log4JLogFactory.java | 12 -- .../openjpa/lib/log/LogFactoryImpl.java | 26 ++- .../openjpa/lib/log/LogOutputStream.java | 3 - .../openjpa/lib/log/MultiLogFactory.java | 17 -- .../openjpa/lib/log/NoneLogFactory.java | 10 -- .../openjpa/lib/meta/CFMetaDataParser.java | 2 +- .../openjpa/lib/meta/ClassArgParser.java | 15 +- .../lib/meta/FileMetaDataIterator.java | 2 +- .../openjpa/lib/meta/SourceTrackers.java | 2 +- .../openjpa/lib/meta/XMLMetaDataParser.java | 15 +- .../openjpa/lib/rop/AbstractListIterator.java | 9 +- .../openjpa/lib/rop/AbstractResultList.java | 27 +-- .../lib/rop/RangeResultObjectProvider.java | 2 +- .../openjpa/lib/rop/ResultListIterator.java | 2 +- .../lib/util/FormatPreservingProperties.java | 2 +- .../apache/openjpa/lib/util/Localizer.java | 110 ++++++++---- .../openjpa/lib/util/ParseException.java | 8 + .../org/apache/openjpa/lib/xml/Location.java | 7 +- .../openjpa/lib/conf/localizer.properties | 2 + .../openjpa/lib/jdbc/localizer.properties | 1 + .../openjpa/lib/log/localizer.properties | 6 +- .../openjpa/lib/meta/localizer.properties | 3 + .../openjpa/lib/test/AbstractTestCase.java | 19 ++- .../openjpa/lib/util/TestLocalizer.java | 6 + .../persistence/ArgumentException.java | 7 + .../ConfigurationProviderImpl.java | 2 +- .../persistence/EntityManagerImpl.java | 3 +- .../persistence/InvalidStateException.java | 6 + .../persistence/PersistenceExceptions.java | 4 +- .../persistence/PersistenceUnitInfoImpl.java | 3 +- .../apache/openjpa/persistence/QueryImpl.java | 4 +- .../TransactionRequiredException.java | 6 + 89 files changed, 478 insertions(+), 409 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java index 054a288e3..49fdd199e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java @@ -185,7 +185,8 @@ public class MappingToolTask conf.setClassResolver(resolver); if (!MappingTool.run(conf, files, flags, loader)) - throw new BuildException(_loc.get("bad-conf", "MappingToolTask")); + throw new BuildException(_loc.get("bad-conf", "MappingToolTask") + .getMessage()); } public static class Action diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/SchemaToolTask.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/SchemaToolTask.java index b1e3c3e36..2031cb019 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/SchemaToolTask.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/SchemaToolTask.java @@ -133,7 +133,8 @@ public class SchemaToolTask flags.writer = Files.getWriter(file, loader); if (!SchemaTool.run((JDBCConfiguration) getConfiguration(), files, flags, loader)) - throw new BuildException(_loc.get("bad-conf", "SchemaToolTask")); + throw new BuildException(_loc.get("bad-conf", "SchemaToolTask") + .getMessage()); } public static class Action diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java index de5ddecca..16658795b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedStatementManagerImpl.java @@ -97,7 +97,7 @@ class PreparedStatementManagerImpl else if (row.getAction() == Row.ACTION_INSERT) throw new SQLException(_loc.get( "update-failed-no-failed-obj", String.valueOf(count), - sql)); + sql).getMessage()); } } catch (SQLException se) { throw SQLExceptions.getStore(se, row.getFailedObject(), _dict); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java index 1b0468ba1..cbb226382 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java @@ -322,7 +322,7 @@ public class TableJDBCSeq if (!setSequence(mapping, stat, alloc, updateStatSeq, getConnection(store))) throw(err != null) ? err : new SQLException(_loc.get - ("no-seq-row", mapping, _table)); + ("no-seq-row", mapping, _table).getMessage()); } } catch (SQLException se2) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java index b579dc2fd..b69c864bc 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingInfo.java @@ -34,9 +34,11 @@ import org.apache.openjpa.jdbc.schema.Unique; import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.meta.MetaDataContext; import org.apache.openjpa.util.MetaDataException; + import serp.util.Strings; /** @@ -315,7 +317,7 @@ public abstract class MappingInfo { return; } - String msg = _loc.get("unexpected-cols", context); + Message msg = _loc.get("unexpected-cols", context); if (die) throw new MetaDataException(msg); context.getRepository().getLog().warn(msg); @@ -344,7 +346,7 @@ public abstract class MappingInfo { else strat = contextStrat.getClass().getName(); - String msg = _loc.get("unexpected-strategy", context, expected, + Message msg = _loc.get("unexpected-strategy", context, expected, strat); if (die) throw new MetaDataException(msg); @@ -358,7 +360,7 @@ public abstract class MappingInfo { if (_idx == null) return; - String msg = _loc.get("unexpected-index", context); + Message msg = _loc.get("unexpected-index", context); if (die) throw new MetaDataException(msg); context.getRepository().getLog().warn(msg); @@ -372,7 +374,7 @@ public abstract class MappingInfo { if (_unq == null) return; - String msg = _loc.get("unexpected-unique", context); + Message msg = _loc.get("unexpected-unique", context); if (die) throw new MetaDataException(msg); context.getRepository().getLog().warn(msg); @@ -385,7 +387,7 @@ public abstract class MappingInfo { if (_fk == null) return; - String msg = _loc.get("unexpected-fk", context); + Message msg = _loc.get("unexpected-fk", context); if (die) throw new MetaDataException(msg); context.getRepository().getLog().warn(msg); @@ -407,7 +409,7 @@ public abstract class MappingInfo { if (!join) return; - String msg = _loc.get("unexpected-join", context); + Message msg = _loc.get("unexpected-join", context); if (die) throw new MetaDataException(msg); context.getRepository().getLog().warn(msg); @@ -643,7 +645,7 @@ public abstract class MappingInfo { } else if ((compat || !ttype) && !col.isCompatible(type, size)) { // if existing column isn't compatible with desired type, die if // can't adapt, else warn and change the existing column type - String msg = _loc.get(prefix + "-bad-col", context, + Message msg = _loc.get(prefix + "-bad-col", context, Schemas.getJDBCName(type), col.getDescription()); if (!adapt) throw new MetaDataException(msg); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java index 31921aa5b..fa13eb7ac 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ClassNameDiscriminatorStrategy.java @@ -90,7 +90,7 @@ public class ClassNameDiscriminatorStrategy className = dict.getString(rs, 1); if (className == null || className.length() == 0) throw new ClassNotFoundException(_loc.get("no-class-name", - disc.getClassMapping(), col)); + disc.getClassMapping(), col).getMessage()); Class.forName(className, true, loader); } disc.setSubclassesLoaded(true); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java index 47fedc274..b48ea77d2 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ValueMapDiscriminatorStrategy.java @@ -95,7 +95,7 @@ public class ValueMapDiscriminatorStrategy throw new ClassNotFoundException(_loc.get("unknown-discrim-value", new Object[]{ str, disc.getClassMapping().getDescribedType().getName(), - new TreeSet(_vals.keySet()) })); + new TreeSet(_vals.keySet()) }).getMessage()); } /** diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java index 02c47c04d..3bbc3faac 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ForeignKey.java @@ -113,9 +113,10 @@ public class ForeignKey String msg; if (closest != null) - msg = _loc.get("bad-fk-action-hint", name, closest, recognized); + msg = _loc.get("bad-fk-action-hint", name, closest, recognized) + .getMessage(); else - msg = _loc.get("bad-fk-action", name, recognized); + msg = _loc.get("bad-fk-action", name, recognized).getMessage(); throw new IllegalArgumentException(msg); } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java index cbce16dc6..a2bb7e3e2 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java @@ -51,7 +51,8 @@ public class NameSet { protected void addName(String name, boolean validate) { if (name == null || name.length() == 0) { if (validate) - throw new IllegalArgumentException(_loc.get("bad-name", name)); + throw new IllegalArgumentException(_loc.get("bad-name", name) + .getMessage()); return; } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java index 825b6e52f..5fe4abb1e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java @@ -772,7 +772,7 @@ public class SchemaGenerator { pkTable = group.findTable(pkTableName); if (pkTable == null) throw new SQLException(_loc.get("gen-nofktable", - table, pkTableName)); + table, pkTableName).getMessage()); // this sucks, because it is *not* guaranteed to work; // the fk resultset is ordered by primary key table, then @@ -870,7 +870,8 @@ public class SchemaGenerator { for (Iterator i = _listeners.iterator(); i.hasNext();) { Listener l = (Listener) i.next(); if (!l.schemaObjectGenerated(e)) - throw new SQLException(_loc.get("refresh-cancelled")); + throw new SQLException(_loc.get("refresh-cancelled") + .getMessage()); } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java index 5a37e7082..87582b41e 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/XMLSchemaParser.java @@ -28,6 +28,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.lib.meta.XMLMetaDataParser; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.util.UserException; /** @@ -553,8 +554,8 @@ public class XMLSchemaParser return new Double(val); } - private void throwUserException(String msg) { - throw new UserException(getSourceName() + ": " + msg); + private void throwUserException(Message msg) { + throw new UserException(getSourceName() + ": " + msg.getMessage()); } /** diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 8afbd156e..14f947fb7 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -81,6 +81,7 @@ import org.apache.openjpa.lib.jdbc.ConnectionDecorator; import org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.JavaTypes; import org.apache.openjpa.util.GeneralException; @@ -1362,7 +1363,7 @@ public class DBDictionary if (storageLimitationsFatal || (warn && log.isWarnEnabled()) || (!warn && log.isTraceEnabled())) { - String msg = _loc.get("storage-restriction", new Object[]{ + Message msg = _loc.get("storage-restriction", new Object[]{ platform, orig, orig.getClass().getName(), diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java index c2adba16d..3decfede9 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java @@ -19,6 +19,7 @@ import java.sql.SQLException; import java.util.LinkedList; import java.util.List; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.util.OpenJPAException; import org.apache.openjpa.util.StoreException; @@ -63,6 +64,14 @@ public class SQLExceptions { return getStore(se.getMessage(), se, failed, dict); } + /** + * Convert the specified exception into a {@link StoreException}. + */ + public static OpenJPAException getStore(Message msg, SQLException se, + DBDictionary dict) { + return getStore(msg.getMessage(), se, null, dict); + } + /** * Convert the specified exception into a {@link StoreException}. */ diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties index a79b066c7..c74d15a0a 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties @@ -140,3 +140,4 @@ illegal-method: {0}.{1}() is illegal to be invoked column-not-mapped: SQLResultSetMapping "{0}" does not map the columns "{1}" \ that are selected by the SQL query\r\n "{2}" batch-license: Your license does not have SQL batching capabilities. +dictionary-configuration: DBDictionary configuration: \n{0} diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/ant/MetaDataToolTask.java b/openjpa-kernel/src/main/java/org/apache/openjpa/ant/MetaDataToolTask.java index 6a56801ac..c5d65a327 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/ant/MetaDataToolTask.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/ant/MetaDataToolTask.java @@ -73,7 +73,8 @@ public class MetaDataToolTask flags.file = Files.getFile(fileName, loader); if (!MetaDataTool.run((OpenJPAConfiguration) getConfiguration(), files, flags, null, loader)) - throw new BuildException(_loc.get("bad-conf", "MetaDataToolTask")); + throw new BuildException(_loc.get("bad-conf", "MetaDataToolTask") + .getMessage()); } public static class Action diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java index a4150595e..7674119f3 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/ProductDerivations.java @@ -51,7 +51,7 @@ public class ProductDerivations { if (derivations.isEmpty()) { Localizer loc = Localizer.forPackage(ProductDerivations.class); throw new MissingResourceException(loc.get("no-product-derivations", - ProductDerivation.class.getName()), + ProductDerivation.class.getName()).getMessage(), ProductDerivations.class.getName(), "derivations"); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java index 8fb09bc3c..f9ec4ca6d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/Caches.java @@ -47,7 +47,7 @@ class Caches { classes = new HashSet(); classes.add(cls); } catch (Throwable t) { - conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(t, t); + conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(null, t); } } return classes; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java index d6e75e36c..174bc1dbd 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java @@ -96,7 +96,7 @@ public class DataCacheScheduler _caches.put(cache, schedule); _stop = false; if (_thread == null) { - _thread = new Thread(this, _loc.get("scheduler-name")); + _thread = new Thread(this, _loc.get("scheduler-name").getMessage()); _thread.start(); if (_log.isTraceEnabled()) _log.trace(_loc.get("scheduler-start", _thread.getName())); @@ -191,7 +191,7 @@ public class DataCacheScheduler } private int[] parse(String token, int min, int max) { - if (token.trim().equals("*")) + if ("*".equals(token.trim())) return WILDCARD; String[] tokens = Strings.split(token, ",", 0); int [] times = new int[tokens.length]; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCDataGenerator.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCDataGenerator.java index 07fc772e3..012fcb9a5 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCDataGenerator.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCDataGenerator.java @@ -89,8 +89,8 @@ public class PCDataGenerator if (storage == null) { storage = generateStorage(meta); _generated.put(type, storage); - if (_log.isDebugEnabled()) - _log.debug(_loc.get("pcdata-created", type.getName(), meta)); + if (_log.isTraceEnabled()) + _log.trace(_loc.get("pcdata-created", type.getName(), meta)); } DynamicPCData data = (DynamicPCData) storage.newInstance(); data.setId(oid); @@ -103,8 +103,8 @@ public class PCDataGenerator * Actually generate the factory instance. */ private DynamicStorage generateStorage(ClassMetaData meta) { - if (_log.isDebugEnabled()) - _log.debug(_loc.get("pcdata-generate", meta)); + if (_log.isTraceEnabled()) + _log.trace(_loc.get("pcdata-generate", meta)); FieldMetaData[] fields = meta.getFields(); int[] types = new int[fields.length]; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index 378911120..2d8e7dfb4 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -51,6 +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.lib.util.TemporaryClassLoader; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.JavaTypes; @@ -513,7 +514,7 @@ public class PCEnhancer { if (itr.hasNext()) buf.append(sep); } - String msg = _loc.get("property-violations", buf); + Message msg = _loc.get("property-violations", buf); if (_fail) throw new UserException(msg); @@ -730,7 +731,7 @@ public class PCEnhancer { if (fmds[i].getManagement() != FieldMetaData.MANAGE_PERSISTENT) continue; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); switch (fmds[i].getDeclaredTypeCode()) { case JavaTypes.BOOLEAN: case JavaTypes.BYTE: @@ -884,11 +885,11 @@ public class PCEnhancer { // = pcStateManager.providedField // (this, fieldNumber); for (int i = 0; i < fmds.length; i++) { - tabins.addTarget(loadManagedInstance(code, false, false)); + tabins.addTarget(loadManagedInstance(code, false)); code.getfield().setField(SM, SMTYPE); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.iload().setParam(0); - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); addGetManagedValueCode(code, fmds[i]); code.invokeinterface().setMethod(getStateManagerMethod (fmds[i].getDeclaredType(), "provided", false, false)); @@ -935,11 +936,11 @@ public class PCEnhancer { // (this, fieldNumber); for (int i = 0; i < fmds.length; i++) { // for the addSetManagedValueCode call below. - tabins.addTarget(loadManagedInstance(code, true, false)); + tabins.addTarget(loadManagedInstance(code, false)); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.iload().setParam(0); code.invokeinterface().setMethod(getStateManagerMethod (fmds[i].getDeclaredType(), "replace", true, false)); @@ -990,7 +991,7 @@ public class PCEnhancer { for (int i = 0; i < fmds.length; i++) { // = other.; // or set (other.get); - tabins.addTarget(loadManagedInstance(code, true, false)); + tabins.addTarget(loadManagedInstance(code, false)); code.aload().setParam(0); addGetManagedValueCode(code, fmds[i]); addSetManagedValueCode(code, fmds[i]); @@ -1035,7 +1036,7 @@ public class PCEnhancer { // no super: if (rel < 0) throw new IllegalArgumentException (); JumpInstruction ifins = code.ifge(); if (_meta.getPCSuperclass() != null) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); String[] args; if (copy) { args = new String[]{ _meta.getPCSuperclass().getName(), @@ -1087,7 +1088,7 @@ public class PCEnhancer { // throw new IllegalArgumentException code.aload().setLocal(inst); code.getfield().setField(SM, SMTYPE); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifacmpeq(); throwException(code, IllegalArgumentException.class); @@ -1095,7 +1096,7 @@ public class PCEnhancer { // if (pcStateManager == null) // throw new IllegalStateException - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); ifins = code.ifnonnull(); throwException(code, IllegalStateException.class); @@ -1109,7 +1110,7 @@ public class PCEnhancer { JumpInstruction testins = code.go2(); // (fields[i]); - Instruction bodyins = loadManagedInstance(code, false, false); + Instruction bodyins = loadManagedInstance(code, false); if (copy) code.aload().setLocal(inst); code.aload().setParam(fieldNumbers); @@ -1178,7 +1179,7 @@ public class PCEnhancer { BCMethod meth = _pc.declareMethod(PRE + "GetStateManager", StateManager.class, null); Code code = meth.getCode(true); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, StateManager.class); code.areturn(); code.calculateMaxStack(); @@ -1202,7 +1203,7 @@ public class PCEnhancer { Code code = method.getCode(true); // if (pcStateManager == null) return ; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifnonnull(); if (returnType.equals(boolean.class)) @@ -1212,7 +1213,7 @@ public class PCEnhancer { code.xreturn().setType(returnType); // return pcStateManager. (); - ifins.setTarget(loadManagedInstance(code, false, false)); + ifins.setTarget(loadManagedInstance(code, false)); code.getfield().setField(SM, SMTYPE); for (int i = 0; i < params.length; i++) code.xload().setParam(i); @@ -1233,7 +1234,7 @@ public class PCEnhancer { Code code = method.getCode(true); // if (pcStateManager == null) - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifnonnull(); FieldMetaData versionField = _meta.getVersionField(); @@ -1247,7 +1248,7 @@ public class PCEnhancer { code.anew().setType(wrapper); code.dup(); } - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); addGetManagedValueCode(code, versionField); if (wrapper != null) code.invokespecial().setMethod(wrapper, "", void.class, @@ -1256,7 +1257,7 @@ public class PCEnhancer { code.areturn(); // return pcStateManager.getVersion (); - ifins.setTarget(loadManagedInstance(code, false, false)); + ifins.setTarget(loadManagedInstance(code, false)); code.getfield().setField(SM, SMTYPE); code.invokeinterface().setMethod(SMTYPE, "getVersion", Object.class, null); @@ -1297,14 +1298,14 @@ public class PCEnhancer { Code code = method.getCode(true); // if (pcStateManager != null) - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifnonnull(); code.vreturn(); // pcFlags = pcStateManager.replaceFlags (); - ifins.setTarget(loadManagedInstance(code, false, false)); - loadManagedInstance(code, false, false); + ifins.setTarget(loadManagedInstance(code, false)); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); code.invokeinterface().setMethod(SMTYPE, "replaceFlags", byte.class, null); @@ -1329,11 +1330,11 @@ public class PCEnhancer { // if (pcStateManager != null) // pcStateManager = pcStateManager.replaceStateManager(sm); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifnull(); - loadManagedInstance(code, false, false); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); code.aload().setParam(0); code.invokeinterface().setMethod(SMTYPE, "replaceStateManager", @@ -1348,7 +1349,7 @@ public class PCEnhancer { "getSecurityManager", SecurityManager.class, null)); // pcStateManager = sm; - ifins.setTarget(loadManagedInstance(code, false, false)); + ifins.setTarget(loadManagedInstance(code, false)); code.aload().setParam(0); code.putfield().setField(SM, SMTYPE); code.vreturn(); @@ -1438,7 +1439,7 @@ public class PCEnhancer { // call superclass method if (_meta.getPCSuperclass() != null) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); for (int i = 0; i < args.length; i++) code.aload().setParam(i); code.invokespecial().setMethod(_meta.getPCSuperclass().getName(), @@ -1496,7 +1497,7 @@ public class PCEnhancer { && !type.getName().equals(String.class.getName())) code.checkcast().setType(type); } else { - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); addGetManagedValueCode(code, fmds[i]); } @@ -1531,7 +1532,7 @@ public class PCEnhancer { // call superclass method if (_meta.getPCSuperclass() != null) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); for (int i = 0; i < args.length; i++) code.aload().setParam(i); code.invokespecial().setMethod(_meta.getPCSuperclass().getName(), @@ -1585,7 +1586,7 @@ public class PCEnhancer { code.iload().setLocal(inherited); code.iadd(); } else - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); if (unwrapped != type) { code.anew().setType(type); @@ -1710,7 +1711,7 @@ public class PCEnhancer { if (obj && usesClsString == null) { // throw new IllegalArgumentException (...); String msg = _loc.get("str-cons", oidType, - _meta.getDescribedType()); + _meta.getDescribedType()).getMessage(); code.anew().setType(IllegalArgumentException.class); code.dup(); code.constant().setValue(msg); @@ -1745,7 +1746,7 @@ public class PCEnhancer { args = new Class[]{ String.class }; } else if (_meta.isOpenJPAIdentity()) { // new Identity (XXX.class, ); - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); FieldMetaData pk = _meta.getPrimaryKeyFields()[0]; addGetManagedValueCode(code, pk); if (_meta.getObjectIdType() == ObjectId.class) @@ -2112,7 +2113,7 @@ public class PCEnhancer { code.beforeFirst(); // bool clear = pcSerializing (); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.invokevirtual().setMethod(PRE + "Serializing", boolean.class, null); int clear = code.getNextLocalsIndex(); @@ -2135,7 +2136,7 @@ public class PCEnhancer { // if (clear) pcSetDetachedState (null); code.iload().setLocal(clear); toret = code.ifeq(); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.constant().setNull(); code.invokevirtual().setMethod(PRE + "SetDetachedState", void.class, new Class[]{ Object.class }); @@ -2157,7 +2158,7 @@ public class PCEnhancer { // if this instance uses synthetic detached state, note that it has // been deserialized if (ClassMetaData.SYNTHETIC.equals(_meta.getDetachedState())) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getstatic().setField(PersistenceCapable.class, "DESERIALIZED", Object.class); code.invokevirtual().setMethod(PRE + "SetDetachedState", @@ -2207,10 +2208,10 @@ public class PCEnhancer { // if (sm != null) // return (sm.isDetached ()) ? Boolean.TRUE : Boolean.FALSE; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); JumpInstruction ifins = code.ifnull(); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); code.invokeinterface().setMethod(SMTYPE, "isDetached", boolean.class, null); @@ -2229,11 +2230,11 @@ public class PCEnhancer { JumpInstruction notdeser = null; Instruction target; if (state != Boolean.FALSE) { - ifins.setTarget(loadManagedInstance(code, false, false)); + ifins.setTarget(loadManagedInstance(code, false)); code.invokevirtual().setMethod(PRE + "GetDetachedState", Object.class, null); ifins = code.ifnull(); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.invokevirtual().setMethod(PRE + "GetDetachedState", Object.class, null); code.getstatic().setField(PersistenceCapable.class, @@ -2269,7 +2270,7 @@ public class PCEnhancer { if (state != Boolean.TRUE && version != null) { // if ( != ) // return true; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); addGetManagedValueCode(code, version); ifins = ifDefaultValue(code, version); code.getstatic().setField(Boolean.class, "TRUE", Boolean.class); @@ -2300,7 +2301,7 @@ public class PCEnhancer { if (state == null) { // if (pcGetDetachedState () == null) // instead of DESERIALIZED // return Boolean.FALSE; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.invokevirtual().setMethod(PRE + "GetDetachedState", Object.class, null); ifins = code.ifnonnull(); @@ -2322,7 +2323,7 @@ public class PCEnhancer { if (pks[i].getValueStrategy() == ValueStrategies.NONE) continue; - target = loadManagedInstance(code, false, false); + target = loadManagedInstance(code, false); if (ifins != null) ifins.setTarget(target); if (ifins2 != null) @@ -2333,7 +2334,7 @@ public class PCEnhancer { ifins = ifDefaultValue(code, pks[i]); if (pks[i].getDeclaredTypeCode() == JavaTypes.STRING) { code.constant().setValue(""); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); addGetManagedValueCode(code, pks[i]); code.invokevirtual().setMethod(String.class, "equals", boolean.class, new Class[]{ Object.class }); @@ -2451,7 +2452,7 @@ public class PCEnhancer { code = clone.getCode(true); // return super.clone (); - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); code.invokespecial().setMethod(_pc.getSuperclassName(), "clone", Object.class.getName(), null); code.areturn(); @@ -2681,7 +2682,7 @@ public class PCEnhancer { byte fieldFlag = getFieldFlag(fmd); if ((fieldFlag & PersistenceCapable.CHECK_READ) == 0 && (fieldFlag & PersistenceCapable.MEDIATE_READ) == 0) { - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xreturn().setType(fmd.getDeclaredType()); @@ -2693,21 +2694,21 @@ public class PCEnhancer { // dfg: if (inst.pcFlags <= 0) return inst.; JumpInstruction ifins = null; if ((fieldFlag & PersistenceCapable.CHECK_READ) > 0) { - loadManagedInstance(code, false, true); + loadManagedInstance(code, true); code.getfield().setField(PRE + "Flags", byte.class); ifins = code.ifgt(); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xreturn().setType(fmd.getDeclaredType()); } // if (inst.pcStateManager == null) return inst.; - Instruction ins = loadManagedInstance(code, false, true); + Instruction ins = loadManagedInstance(code, true); if (ifins != null) ifins.setTarget(ins); code.getfield().setField(SM, SMTYPE); ifins = code.ifnonnull(); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xreturn().setType(fmd.getDeclaredType()); @@ -2720,12 +2721,12 @@ public class PCEnhancer { // inst.pcStateManager.accessingField (field); // return inst.; - loadManagedInstance(code, false, true); + loadManagedInstance(code, true); code.getfield().setField(SM, SMTYPE); code.iload().setLocal(fieldLocal); code.invokeinterface().setMethod(SMTYPE, "accessingField", void.class, new Class[]{ int.class }); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xreturn().setType(fmd.getDeclaredType()); @@ -2753,35 +2754,35 @@ public class PCEnhancer { JumpInstruction ifins = null; byte fieldFlag = getFieldFlag(fmd); if ((fieldFlag & PersistenceCapable.CHECK_WRITE) > 0) { - loadManagedInstance(code, false, true); + loadManagedInstance(code, true); code.getfield().setField(PRE + "Flags", byte.class); ifins = code.ifne(); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); code.xload().setParam(firstParamOffset); addSetManagedValueCode(code, fmd); code.vreturn(); } // if (inst.pcStateManager == null) inst. = value; - Instruction ins = loadManagedInstance(code, false, true); + Instruction ins = loadManagedInstance(code, true); if (ifins != null) ifins.setTarget(ins); code.getfield().setField(SM, SMTYPE); ifins = code.ifnonnull(); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); code.xload().setParam(firstParamOffset); addSetManagedValueCode(code, fmd); code.vreturn(); // inst.pcStateManager.settingField (inst, // pcInheritedFieldCount + , inst., value, 0); - ifins.setTarget(loadManagedInstance(code, false, true)); + ifins.setTarget(loadManagedInstance(code, true)); code.getfield().setField(SM, SMTYPE); - loadManagedInstance(code, false, true); + loadManagedInstance(code, true); code.getstatic().setField(INHERIT, int.class); code.constant().setValue(index); code.iadd(); - loadManagedInstance(code, true, true); + loadManagedInstance(code, true); addGetManagedValueCode(code, fmd); code.xload().setParam(firstParamOffset); code.constant().setValue(0); @@ -2860,7 +2861,7 @@ public class PCEnhancer { Code code = method.getCode(true); if (impl) { // return pcDetachedState; - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); code.getfield().setField(declarer, name, Object.class.getName()); } else code.constant().setNull(); @@ -2875,7 +2876,7 @@ public class PCEnhancer { code = method.getCode(true); if (impl) { // pcDetachedState = state; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.putfield().setField(declarer, name, Object.class.getName()); @@ -2941,21 +2942,21 @@ public class PCEnhancer { // super.readExternal (in); Class sup = _meta.getDescribedType().getSuperclass(); if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokespecial().setMethod(sup, "readExternal", void.class, inargs); } // readUnmanaged (in); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokevirtual().setMethod(_meta.getDescribedType(), PRE + "ReadUnmanaged", void.class, inargs); if (detachedState) { // pcSetDetachedState (in.readObject ()); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokeinterface().setMethod(ObjectInput.class, "readObject", Object.class, null); @@ -2963,7 +2964,7 @@ public class PCEnhancer { void.class, new Class[]{ Object.class }); // pcReplaceStateManager ((StateManager) in.readObject ()); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokeinterface().setMethod(ObjectInput.class, "readObject", Object.class, null); @@ -3000,7 +3001,7 @@ public class PCEnhancer { // super.readUnmanaged (in); if (parentDetachable) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokespecial().setMethod(_meta.getPCSuperclass(), PRE + "ReadUnmanaged", void.class, inargs); @@ -3033,7 +3034,7 @@ public class PCEnhancer { methName = "readObject"; // = in.read (); - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); code.aload().setParam(0); Class ret = (type.isPrimitive()) ? type : Object.class; code.invokeinterface().setMethod(ObjectInput.class, methName, @@ -3053,10 +3054,10 @@ public class PCEnhancer { case JavaTypes.CALENDAR: // if (sm != null) // sm.proxyDetachedDeserialized (); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); IfInstruction ifins = code.ifnull(); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); code.constant().setValue(fmd.getIndex()); code.invokeinterface().setMethod(SMTYPE, @@ -3082,14 +3083,14 @@ public class PCEnhancer { // super.writeExternal (out); Class sup = _meta.getDescribedType().getSuperclass(); if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokespecial().setMethod(sup, "writeExternal", void.class, outargs); } // writeUnmanaged (out); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokevirtual().setMethod(_meta.getDescribedType(), PRE + "WriteUnmanaged", void.class, outargs); @@ -3099,10 +3100,10 @@ public class PCEnhancer { // if (sm != null) // if (sm.writeDetached (out)) // return; - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); IfInstruction ifnull = code.ifnull(); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.getfield().setField(SM, SMTYPE); code.aload().setParam(0); code.invokeinterface().setMethod(SMTYPE, "writeDetached", @@ -3114,7 +3115,7 @@ public class PCEnhancer { // out.writeObject (pcGetDetachedState ()); Class[] objargs = new Class[]{ Object.class }; ifnull.setTarget(code.aload().setParam(0)); - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.invokevirtual().setMethod(PRE + "GetDetachedState", Object.class, null); code.invokeinterface().setMethod(ObjectOutput.class, @@ -3133,7 +3134,7 @@ public class PCEnhancer { for (int i = 0; i < fmds.length; i++) if (!fmds[i].isTransient()) writeExternal(code, fmds[i].getName(), - fmds[i].getDeclaredType(), i, fmds[i]); + fmds[i].getDeclaredType(), fmds[i]); // return code.vreturn(); @@ -3156,7 +3157,7 @@ public class PCEnhancer { // super.writeUnmanaged (out); if (parentDetachable) { - loadManagedInstance(code, false, false); + loadManagedInstance(code, false); code.aload().setParam(0); code.invokespecial().setMethod(_meta.getPCSuperclass(), PRE + "WriteUnmanaged", void.class, outargs); @@ -3166,7 +3167,7 @@ public class PCEnhancer { BCField field; for (Iterator itr = unmgd.iterator(); itr.hasNext();) { field = (BCField) itr.next(); - writeExternal(code, field.getName(), field.getType(), -1, null); + writeExternal(code, field.getName(), field.getType(), null); } code.vreturn(); code.calculateMaxStack(); @@ -3177,7 +3178,7 @@ public class PCEnhancer { * Helper method to write a field to an externalization output stream. */ private void writeExternal(Code code, String fieldName, Class type, - int idx, FieldMetaData fmd) + FieldMetaData fmd) throws NoSuchMethodException { String methName; if (type.isPrimitive()) { @@ -3190,7 +3191,7 @@ public class PCEnhancer { // out.write (); code.aload().setParam(0); - loadManagedInstance(code, true, false); + loadManagedInstance(code, false); if (fmd == null) code.getfield().setField(fieldName, type); else @@ -3256,7 +3257,7 @@ public class PCEnhancer { * * @return the first instruction added to code. */ - private Instruction loadManagedInstance(Code code, boolean userObject, + private Instruction loadManagedInstance(Code code, boolean forAccessor) { if (_meta.getAccessType() == ClassMetaData.ACCESS_FIELD && forAccessor) return code.aload().setParam(0); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/event/LogOrphanedKeyAction.java b/openjpa-kernel/src/main/java/org/apache/openjpa/event/LogOrphanedKeyAction.java index 4a8800151..0a6ddd76a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/event/LogOrphanedKeyAction.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/event/LogOrphanedKeyAction.java @@ -82,10 +82,6 @@ public class LogOrphanedKeyAction if (log.isTraceEnabled()) log.trace(_loc.get(msg, oid, vmd, owner)); break; - case Log.DEBUG: - if (log.isDebugEnabled()) - log.debug(_loc.get(msg, oid, vmd, owner)); - break; case Log.INFO: if (log.isInfoEnabled()) log.info(_loc.get(msg, oid, vmd, owner)); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java index 9509ecebc..93d52f519 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java @@ -235,7 +235,8 @@ public abstract class AbstractBrokerFactory try { Class.forName((String) itr.next(), true, loader); } catch (Throwable t) { - _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(t, t); + _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME) + .warn(null, t); } } } @@ -515,7 +516,7 @@ public abstract class AbstractBrokerFactory if (itr.hasNext()) buf.append(lineSep); } - log.trace(buf.toString()); + log.trace(_loc.get("factory-properties", buf.toString())); } // setup transient state diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java index 12235ac41..d36e1d026 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java @@ -3989,7 +3989,7 @@ public class BrokerImpl //### JDO2 if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) throw new UnsupportedOperationException(_loc.get - ("new-abstract", cls)); + ("new-abstract", cls).getMessage()); // 1.5 doesn't initialize classes without a true Class.forName if (!PCRegistry.isRegistered(cls)) { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java index 72a059801..6f3a6a627 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java @@ -18,7 +18,6 @@ package org.apache.openjpa.kernel; import java.util.BitSet; import org.apache.openjpa.enhance.PersistenceCapable; -import org.apache.openjpa.event.LifecycleEvent; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.FieldMetaData; diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java index 743cee8eb..7f6f0141c 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java @@ -378,7 +378,7 @@ public class DetachedStateManager public void accessingField(int idx) { if (!_access && !_loaded.get(idx)) throw new IllegalStateException(_loc.get("unloaded-detached", - _pc)); + _pc).getMessage()); } public boolean serializing() { diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java index a04634bd9..53740a44b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Filters.java @@ -276,7 +276,7 @@ public class Filters { } if (!num) throw new ClassCastException(_loc.get("cant-convert", o, - o.getClass(), type)); + o.getClass(), type).getMessage()); if (type == Integer.class) { return Numbers.valueOf(((Number) o).intValue()); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java index c0928018c..242273c06 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java @@ -24,6 +24,7 @@ import java.util.Set; import org.apache.openjpa.kernel.Filters; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.util.InternalException; @@ -97,11 +98,11 @@ public abstract class AbstractExpressionBuilder { Exception nest) { String argStr; if (args == null) - argStr = getLocalizer().get(token); + argStr = getLocalizer().get(token).getMessage(); else - argStr = getLocalizer().get(token, args); + argStr = getLocalizer().get(token, args).getMessage(); - String msg = _loc.get("parse-error", argStr, currentQuery()); + Message msg = _loc.get("parse-error", argStr, currentQuery()); switch (e) { case EX_FATAL: @@ -361,14 +362,14 @@ public abstract class AbstractExpressionBuilder { String right; if (val1 instanceof Path && ((Path) val1).last() != null) left = _loc.get("non-numeric-path", ((Path) val1).last(). - getName(), t1.getName()); + getName(), t1.getName()).getMessage(); else - left = _loc.get("non-numeric-value", t1.getName()); + left = _loc.get("non-numeric-value", t1.getName()).getMessage(); if (val2 instanceof Path && ((Path) val2).last() != null) right = _loc.get("non-numeric-path", ((Path) val2).last(). - getName(), t2.getName()); + getName(), t2.getName()).getMessage(); else - right = _loc.get("non-numeric-value", t2.getName()); + right = _loc.get("non-numeric-value", t2.getName()).getMessage(); throw new UserException(_loc.get("non-numeric-comparison", left, right)); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ParseException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ParseException.java index cb02fdd45..04ce062e9 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ParseException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ParseException.java @@ -18,6 +18,7 @@ package org.apache.openjpa.kernel.jpql; import java.util.TreeSet; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.util.UserException; /** @@ -28,7 +29,8 @@ import org.apache.openjpa.util.UserException; public class ParseException extends UserException { - private static Localizer _loc = Localizer.forPackage(ParseException.class); + private static final Localizer _loc = + Localizer.forPackage(ParseException.class); /** * This constructor is used by the method "generateParseException" @@ -59,10 +61,6 @@ public class ParseException super(); } - public ParseException(String message) { - super(message); - } - /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses @@ -73,7 +71,7 @@ public class ParseException * of the final stack trace, and hence the correct error message * gets displayed. */ - private static String initMessage(Token currentToken, + private static Message initMessage(Token currentToken, int[][]expectedTokenSequences, String[]tokenImage) { TreeSet expected = new TreeSet(); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/Extensions.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/Extensions.java index f0c9a0deb..c73ded669 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/Extensions.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/Extensions.java @@ -320,7 +320,7 @@ public abstract class Extensions { // way a new vendor could theoretically add in their // own prefix into the localizer.properties file and // not have to issue warnings for their extensions - String prefixes = _loc.get("extension-datastore-prefix"); + String prefixes = _loc.get("extension-datastore-prefix").getMessage(); String[] allowedPrefixes = null; if (prefixes != null) allowedPrefixes = Strings.split(prefixes, ",", 0); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/UpdateStrategies.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/UpdateStrategies.java index b71fe42c3..9ab7d9137 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/UpdateStrategies.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/UpdateStrategies.java @@ -80,9 +80,10 @@ public class UpdateStrategies { String msg; if (closest != null) msg = _loc.get("bad-update-strategy-hint", new Object[]{ - context, val, closest, opts }); + context, val, closest, opts }).getMessage(); else - msg = _loc.get("bad-update-strategy", context, val, opts); + msg = _loc.get("bad-update-strategy", context, val, opts) + .getMessage(); throw new IllegalArgumentException(msg); } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java index 85c3aefda..f92a50c7d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueStrategies.java @@ -108,9 +108,10 @@ public class ValueStrategies { String msg; if (closest != null) msg = _loc.get("bad-value-strategy-hint", new Object[]{ - context, val, closest, _map.keySet() }); + context, val, closest, _map.keySet() }).getMessage(); else - msg = _loc.get("bad-value-strategy", context, val, _map.keySet()); + msg = _loc.get("bad-value-strategy", context, val, _map.keySet()) + .getMessage(); throw new IllegalArgumentException(msg); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/CallbackException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/CallbackException.java index c90e91e5a..d859a42b0 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/CallbackException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/CallbackException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type thrown when an error occurs in a callback. * @@ -24,18 +26,10 @@ package org.apache.openjpa.util; public class CallbackException extends UserException { - public CallbackException() { - } - - public CallbackException(String msg) { + public CallbackException(Message msg) { super(msg); } - public CallbackException(String msg, Object failed) { - super(msg); - setFailedObject(failed); - } - public int getSubtype() { return CALLBACK; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/GeneralException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/GeneralException.java index e640aacda..762e97f99 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/GeneralException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/GeneralException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * General exception type. * @@ -30,11 +32,15 @@ public class GeneralException super(msg); } + public GeneralException(Message msg) { + super(msg); + } + public GeneralException(Throwable cause) { super(cause); } - public GeneralException(String msg, Throwable cause) { + public GeneralException(Message msg, Throwable cause) { super(msg, cause); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/InternalException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/InternalException.java index bb13a233b..51139482f 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/InternalException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/InternalException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type for internal errors. * @@ -33,6 +35,11 @@ public class InternalException setFatal(true); } + public InternalException(Message msg) { + super(msg); + setFatal(true); + } + public InternalException(Throwable cause) { super(cause); setFatal(true); @@ -43,6 +50,11 @@ public class InternalException setFatal(true); } + public InternalException(Message msg, Throwable cause) { + super(msg, cause); + setFatal(true); + } + public int getType() { return INTERNAL; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/InvalidStateException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/InvalidStateException.java index 0e4a264ec..70f12c9a1 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/InvalidStateException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/InvalidStateException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type thrown when attempting to execute an operation that * is not allowed by the current state. @@ -25,14 +27,11 @@ package org.apache.openjpa.util; public class InvalidStateException extends UserException { - public InvalidStateException() { - } - - public InvalidStateException(String msg) { + public InvalidStateException(Message msg) { super(msg); } - public InvalidStateException(String msg, Object failed) { + public InvalidStateException(Message msg, Object failed) { super(msg); setFailedObject(failed); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/LockException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/LockException.java index 56e2c1cc1..8ccb15e00 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/LockException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/LockException.java @@ -35,13 +35,6 @@ public class LockException private int timeout = -1; - public LockException() { - } - - public LockException(String msg) { - super(msg); - } - public LockException(Object failed) { super(_loc.get("lock-failed", Exceptions.toString(failed))); setFailedObject(failed); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/MetaDataException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/MetaDataException.java index 8e85b197a..4669b00ca 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/MetaDataException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/MetaDataException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type reserved for missing or invalid metadata. * @@ -33,7 +35,12 @@ public class MetaDataException setFatal(true); } - public MetaDataException(String msg, Object failed) { + public MetaDataException(Message msg) { + super(msg); + setFatal(true); + } + + public MetaDataException(Message msg, Object failed) { super(msg); setFatal(true); setFailedObject(failed); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/NoTransactionException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/NoTransactionException.java index 28bf866f4..f6000e57c 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/NoTransactionException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/NoTransactionException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type thrown when attempting a transactional operation without * an active transaction. @@ -25,18 +27,10 @@ package org.apache.openjpa.util; public class NoTransactionException extends InvalidStateException { - public NoTransactionException() { - } - - public NoTransactionException(String msg) { + public NoTransactionException(Message msg) { super(msg); } - public NoTransactionException(String msg, Object failed) { - super(msg); - setFailedObject(failed); - } - public int getSubtype() { return NO_TRANSACTION; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectExistsException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectExistsException.java index d541c3258..c312e6bf9 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectExistsException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectExistsException.java @@ -15,7 +15,7 @@ */ package org.apache.openjpa.util; -import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; /** * Exception type reserved for conflicts with existing objects. @@ -25,21 +25,10 @@ import org.apache.openjpa.lib.util.Localizer; public class ObjectExistsException extends StoreException { - private static final transient Localizer _loc = Localizer.forPackage - (ObjectExistsException.class); - - public ObjectExistsException() { - } - - public ObjectExistsException(String msg) { + public ObjectExistsException(Message msg) { super(msg); } - public ObjectExistsException(Object failed) { - super(_loc.get("obj-exists", Exceptions.toString(failed))); - setFailedObject(failed); - } - public int getSubtype() { return OBJECT_EXISTS; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectNotFoundException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectNotFoundException.java index e9de0140b..b9365a78a 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectNotFoundException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ObjectNotFoundException.java @@ -18,6 +18,7 @@ package org.apache.openjpa.util; import java.util.Collection; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; /** * Exception type reserved for failed object lookups. @@ -30,10 +31,7 @@ public class ObjectNotFoundException private static final transient Localizer _loc = Localizer.forPackage (ObjectNotFoundException.class); - public ObjectNotFoundException() { - } - - public ObjectNotFoundException(String msg) { + public ObjectNotFoundException(Message msg) { super(msg); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAException.java index 185b14585..506af96e8 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAException.java @@ -22,6 +22,8 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serializable; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type for all OpenJPA exceptions. Meant to be easily * transformed into an appropriate exception at the API layer, since most APIs @@ -51,6 +53,13 @@ public abstract class OpenJPAException super(msg); } + /** + * Constructor; supply message. + */ + public OpenJPAException(Message msg) { + super(msg.getMessage()); + } + /** * Construct with cause. */ @@ -66,6 +75,14 @@ public abstract class OpenJPAException setCause(cause); } + /** + * Construct with message and cause. + */ + public OpenJPAException(Message msg, Throwable cause) { + super(msg.getMessage()); + setCause(cause); + } + /** * Exception type. */ diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OptimisticException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OptimisticException.java index 48a6df2da..9a7e278d5 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/OptimisticException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/OptimisticException.java @@ -18,6 +18,7 @@ package org.apache.openjpa.util; import java.util.Collection; import org.apache.openjpa.lib.util.Localizer; +import org.apache.openjpa.lib.util.Localizer.Message; /** * Exception type for optimistic concurrency violations. @@ -32,10 +33,7 @@ public class OptimisticException private static final transient Localizer _loc = Localizer.forPackage (OptimisticException.class); - public OptimisticException() { - } - - public OptimisticException(String msg) { + public OptimisticException(Message msg) { super(msg); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ReferentialIntegrityException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ReferentialIntegrityException.java index e762cadaf..ab3b453ea 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ReferentialIntegrityException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ReferentialIntegrityException.java @@ -40,9 +40,6 @@ public class ReferentialIntegrityException private int _iv = IV_UNKNOWN; - public ReferentialIntegrityException() { - } - public ReferentialIntegrityException(String msg) { super(msg); } @@ -55,11 +52,11 @@ public class ReferentialIntegrityException private static String getMessage(int iv) { switch (iv) { case IV_DUPLICATE_OID: - return _loc.get("dup-oid"); + return _loc.get("dup-oid").getMessage(); case IV_UNIQUE: - return _loc.get("unique"); + return _loc.get("unique").getMessage(); default: - return _loc.get("ref-integrity"); + return _loc.get("ref-integrity").getMessage(); } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java index cb5102858..b3d6e771e 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/StoreException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Base exception for data store errors. * @@ -30,21 +32,18 @@ public class StoreException public static final int REFERENTIAL_INTEGRITY = 4; public static final int OBJECT_EXISTS = 5; - public StoreException() { - } - public StoreException(String msg) { super(msg); } + public StoreException(Message msg) { + super(msg.getMessage()); + } + public StoreException(Throwable cause) { super(cause); } - public StoreException(String msg, Throwable cause) { - super(msg, cause); - } - public int getType() { return STORE; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/UnsupportedException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/UnsupportedException.java index 31b1c9784..7ef5f9af4 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/UnsupportedException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/UnsupportedException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Exception type for attempts to perform unsupported operations. * @@ -33,12 +35,12 @@ public class UnsupportedException setFatal(true); } - public UnsupportedException(Throwable cause) { - super(cause); + public UnsupportedException(Message msg) { + super(msg); setFatal(true); } - public UnsupportedException(String msg, Throwable cause) { + public UnsupportedException(Message msg, Throwable cause) { super(msg, cause); setFatal(true); } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/UserException.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/UserException.java index f5e477147..80638d8fb 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/UserException.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/UserException.java @@ -15,6 +15,8 @@ */ package org.apache.openjpa.util; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Base exception type for user errors. * @@ -36,6 +38,10 @@ public class UserException super(msg); } + public UserException(Message msg) { + super(msg); + } + public UserException(Throwable cause) { super(cause); } @@ -44,6 +50,10 @@ public class UserException super(msg, cause); } + public UserException(Message msg, Throwable cause) { + super(msg, cause); + } + public int getType() { return USER; } diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties index 950b8884a..4f6f7c642 100644 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties @@ -161,6 +161,7 @@ objectid-abstract: Cannot create new application identity instance for \ bad-id-value: The given value "{0}" cannot be converted into an identity \ for "{2}". The value is the wrong type ({1}). factory-init: Starting OpenJPA {0} +factory-properties: Properties: {0} inverse-consistency: An inverse inconsistency in the object model was \ detected while flushing the field "{0}" of the instance with id "{1}" \ in context "{2}". diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java index 22932efea..43a097a88 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/AbstractTask.java @@ -126,7 +126,7 @@ public abstract class AbstractTask extends MatchingTask { */ protected void assertFiles(String[] files) { if (files.length == 0) - throw new BuildException(_loc.get("no-filesets")); + throw new BuildException(_loc.get("no-filesets").getMessage()); } public void setClasspath(Path classPath) { diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java index 3df9435a2..068f72aeb 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ConfigurationImpl.java @@ -276,7 +276,7 @@ public class ConfigurationImpl } if (errs != null) throw new RuntimeException(_loc.get("get-prop-errs", - errs.toString())); + errs.toString()).getMessage()); } public boolean isReadOnly() { @@ -503,7 +503,7 @@ public class ConfigurationImpl if (scope != null) { loc = Localizer.forPackage(scope); try { - return loc.getFatal(key); + return loc.getFatal(key).getMessage(); } catch (MissingResourceException mse) { } } @@ -512,7 +512,7 @@ public class ConfigurationImpl cls = cls.getSuperclass()) { loc = Localizer.forPackage(cls); try { - return loc.getFatal(key); + return loc.getFatal(key).getMessage(); } catch (MissingResourceException mse) { } } @@ -670,7 +670,8 @@ public class ConfigurationImpl // if we've already found a property with a previous prefix, // then this is a collision. throw new IllegalStateException( - _loc.get("dup-with-different-prefixes", firstKey, key)); + _loc.get("dup-with-different-prefixes", firstKey, key) + .getMessage()); } } if (firstKey != null && setLoadKey) @@ -761,7 +762,7 @@ public class ConfigurationImpl */ public void assertNotReadOnly() { if (isReadOnly()) - throw new IllegalStateException(_loc.get("read-only")); + throw new IllegalStateException(_loc.get("read-only").getMessage()); } /** diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java index bc87062a8..689678a64 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java @@ -140,7 +140,7 @@ public class Configurations { throw re; Log log = (conf == null) ? null : conf.getConfigurationLog(); if (log != null && log.isErrorEnabled()) - log.error(re); + log.error(_loc.get("plugin-creation-exception", val), re); return null; } @@ -148,12 +148,12 @@ public class Configurations { return cls.newInstance(); } catch (Exception e) { RuntimeException re = new NestableRuntimeException(_loc.get - ("obj-create", cls), e); + ("obj-create", cls).getMessage(), e); if (fatal) throw re; Log log = (conf == null) ? null : conf.getConfigurationLog(); if (log != null && log.isErrorEnabled()) - log.error(re); + log.error(_loc.get("plugin-creation-exception", val), re); return null; } } @@ -279,7 +279,7 @@ public class Configurations { ((GenericConfigurable) obj).setInto(invalidEntries); if (!invalidEntries.isEmpty() && configurationName != null) { - String msg = null; + Localizer.Message msg = null; String first = (String) invalidEntries.keySet().iterator().next(); if (invalidEntries.keySet().size() == 1 && first.indexOf('.') == -1) { @@ -460,7 +460,7 @@ public class Configurations { Configurations.class.getName(), "defaults"); if (providerCount == 0) throw new MissingResourceException(_loc.get ("no-providers", - ConfigurationProvider.class.getName()), + ConfigurationProvider.class.getName()).getMessage(), Configurations.class.getName(), "defaults"); return null; } @@ -518,9 +518,9 @@ public class Configurations { msg = errs.toString(); else if (providerCount == 0) msg = _loc.get("no-providers", - ConfigurationProvider.class.getName()); + ConfigurationProvider.class.getName()).getMessage(); else - msg = _loc.get("no-provider", resource); + msg = _loc.get("no-provider", resource).getMessage(); throw new MissingResourceException(msg, Configurations.class.getName(), resource); @@ -572,8 +572,8 @@ public class Configurations { ctx = new InitialContext(); return ctx.lookup(name); } catch (NamingException ne) { - throw new NestableRuntimeException(_loc.get("naming-err", name), - ne); + throw new NestableRuntimeException( + _loc.get("naming-err", name).getMessage(), ne); } finally { if (ctx != null) try { diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java index 6662309c1..163d5f0c7 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ObjectValue.java @@ -107,7 +107,7 @@ public class ObjectValue extends Value { set(null); else throw new IllegalArgumentException(_loc.get("cant-set-string", - getProperty())); + getProperty()).getMessage()); } protected void setInternalObject(Object obj) { diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java index 43f55fd74..0f4c08ffa 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/PluginValue.java @@ -106,7 +106,7 @@ public class PluginValue extends ObjectValue { public void set(Object obj, boolean derived) { if (!_singleton) throw new IllegalStateException(_loc.get("not-singleton", - getProperty())); + getProperty()).getMessage()); super.set(obj, derived); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DataSourceLogs.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DataSourceLogs.java index f426817f0..8b56703db 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DataSourceLogs.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DataSourceLogs.java @@ -19,6 +19,7 @@ import java.sql.Connection; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.NoneLogFactory; +import org.apache.openjpa.lib.util.Localizer; /** * Provies basic logging facilities to a DataSource. @@ -28,6 +29,9 @@ import org.apache.openjpa.lib.log.NoneLogFactory; */ public class DataSourceLogs { + private static final Localizer _loc = + Localizer.forPackage(DataSourceLogs.class); + private Log _jdbcLog = null; private Log _sqlLog = null; @@ -136,12 +140,12 @@ public class DataSourceLogs { buf.append(", ").append(conn); buf.append("> "); - // in the time != -1, append time profiling information + // if the time != -1, append time profiling information if (totalTime != -1) buf.append("[").append(totalTime).append(" ms] "); buf.append(msg); - log.trace(buf.toString()); + log.trace(_loc.get("datasource-trace-data", buf.toString())); } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DelegatingConnection.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DelegatingConnection.java index 3b54db9a8..8a58af170 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DelegatingConnection.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/DelegatingConnection.java @@ -557,7 +557,8 @@ public class DelegatingConnection implements Connection, Closeable { private static void assertJDBC3() { if (_jdbc3 == null) - throw new UnsupportedOperationException(_loc.get("not-jdbc3")); + throw new UnsupportedOperationException(_loc.get("not-jdbc3") + .getMessage()); } private Object invokeJDBC3(Method m, Object[] args) throws SQLException { @@ -566,7 +567,8 @@ public class DelegatingConnection implements Connection, Closeable { } catch (Throwable t) { if (t instanceof SQLException) throw(SQLException) t; - throw new NestableRuntimeException(_loc.get("invoke-jdbc3"), t); + throw new NestableRuntimeException(_loc.get("invoke-jdbc3") + .getMessage(), t); } } @@ -577,7 +579,8 @@ public class DelegatingConnection implements Connection, Closeable { _jdbc3.put(key, m); return m; } catch (Throwable t) { - throw new NestableRuntimeException(_loc.get("error-jdbc3"), t); + throw new NestableRuntimeException(_loc.get("error-jdbc3") + .getMessage(), t); } } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/AbstractLog.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/AbstractLog.java index 2f572ce20..a1701d102 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/AbstractLog.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/AbstractLog.java @@ -44,10 +44,6 @@ public abstract class AbstractLog implements Log { return isEnabled(TRACE); } - public boolean isDebugEnabled() { - return isEnabled(DEBUG); - } - public boolean isInfoEnabled() { return isEnabled(INFO); } @@ -73,15 +69,6 @@ public abstract class AbstractLog implements Log { log(TRACE, toString(message), throwableParam(message, t)); } - public void debug(Object message) { - debug(message, throwableParam(message, null)); - } - - public void debug(Object message, Throwable t) { - if (isDebugEnabled()) - log(DEBUG, toString(message), throwableParam(message, t)); - } - public void info(Object message) { info(message, throwableParam(message, null)); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java index 85be18fb9..faa7bc853 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/CommonsLogFactory.java @@ -49,10 +49,6 @@ public class CommonsLogFactory extends LogFactoryAdapter { return _log; } - public boolean isDebugEnabled() { - return _log.isDebugEnabled(); - } - public boolean isErrorEnabled() { return _log.isErrorEnabled(); } @@ -81,14 +77,6 @@ public class CommonsLogFactory extends LogFactoryAdapter { _log.trace(o, t); } - public void debug(Object o) { - _log.debug(o); - } - - public void debug(Object o, Throwable t) { - _log.debug(o, t); - } - public void info(Object o) { _log.info(o); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log.java index 8b10f17ac..630e33494 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log.java @@ -24,7 +24,7 @@ package org.apache.openjpa.lib.log; public interface Log { public static final short TRACE = 1; - public static final short DEBUG = 2; + // the old DEBUG constant was 2. Leaving a hole for compatibility. public static final short INFO = 3; public static final short WARN = 4; public static final short ERROR = 5; @@ -35,11 +35,6 @@ public interface Log { */ public boolean isTraceEnabled(); - /** - * Returns if the {@link #DEBUG} log level is enabled. - */ - public boolean isDebugEnabled(); - /** * Returns if the {@link #INFO} log level is enabled. */ @@ -74,20 +69,6 @@ public interface Log { */ public void trace(Object o, Throwable t); - /** - * Write out a log message at the {@link #DEBUG} - * level with the stringification of o as the body - * of the message, also outputting t to the log. - */ - public void debug(Object o); - - /** - * Write out a log message at the {@link #DEBUG} - * level with the stringification of o as the body - * of the message, also outputting t to the log. - */ - public void debug(Object o, Throwable t); - /** * Write out a log message at the {@link #INFO} * level with the stringification of o as the body diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java index c2eee1095..7d5ba753d 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/Log4JLogFactory.java @@ -46,10 +46,6 @@ public class Log4JLogFactory extends LogFactoryAdapter { } public boolean isTraceEnabled() { - return isDebugEnabled(); - } - - public boolean isDebugEnabled() { return _log.getEffectiveLevel().toInt() >= Level.DEBUG_INT; } @@ -77,14 +73,6 @@ public class Log4JLogFactory extends LogFactoryAdapter { _log.debug(o, t); } - public void debug(Object o) { - _log.debug(o); - } - - public void debug(Object o, Throwable t) { - _log.debug(o, t); - } - public void info(Object o) { _log.info(o); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java index 3f7789b70..e1e5738e5 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogFactoryImpl.java @@ -42,12 +42,11 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable { private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class); - public static final String TRACE_STR = _loc.get("log-trace"); - public static final String DEBUG_STR = _loc.get("log-debug"); - public static final String INFO_STR = _loc.get("log-info"); - public static final String WARN_STR = _loc.get("log-warn"); - public static final String ERROR_STR = _loc.get("log-error"); - public static final String FATAL_STR = _loc.get("log-fatal"); + public static final String TRACE_STR = _loc.get("log-trace").getMessage(); + public static final String INFO_STR = _loc.get("log-info").getMessage(); + public static final String WARN_STR = _loc.get("log-warn").getMessage(); + public static final String ERROR_STR = _loc.get("log-error").getMessage(); + public static final String FATAL_STR = _loc.get("log-fatal").getMessage(); public static final String STDOUT = "stdout"; public static final String STDERR = "stderr"; @@ -187,8 +186,6 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable { switch (level) { case Log.TRACE: return TRACE_STR; - case Log.DEBUG: - return DEBUG_STR; case Log.INFO: return INFO_STR; case Log.WARN: @@ -198,7 +195,7 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable { case Log.FATAL: return FATAL_STR; default: - return _loc.get("log-unknown"); + return _loc.get("log-unknown").getMessage(); } } @@ -208,15 +205,14 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable { public static short getLevel(String str) { str = str.toUpperCase().trim(); short val = TRACE_STR.equals(str) ? Log.TRACE : - DEBUG_STR.equals(str) ? Log.DEBUG : - INFO_STR.equals(str) ? Log.INFO : - WARN_STR.equals(str) ? Log.WARN : - ERROR_STR.equals(str) ? Log.ERROR : - FATAL_STR.equals(str) ? Log.FATAL : -1; + INFO_STR.equals(str) ? Log.INFO : + WARN_STR.equals(str) ? Log.WARN : + ERROR_STR.equals(str) ? Log.ERROR : + FATAL_STR.equals(str) ? Log.FATAL : -1; if (val == -1) throw new IllegalArgumentException - (_loc.get("log-bad-constant", str)); + (_loc.get("log-bad-constant", str).getMessage()); return val; } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java index 75c5e47fc..b9eeae7f7 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/LogOutputStream.java @@ -69,9 +69,6 @@ public class LogOutputStream extends ByteArrayOutputStream { case Log.TRACE: _log.trace(msg); break; - case Log.DEBUG: - _log.debug(msg); - break; case Log.INFO: _log.info(msg); break; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java index 615639ce2..c1b7806e1 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/MultiLogFactory.java @@ -122,16 +122,6 @@ public class MultiLogFactory implements LogFactory { _logs[i].info(msg, t); } - public void debug(Object msg) { - for (int i = 0; i < _logs.length; i++) - _logs[i].debug(msg); - } - - public void debug(Object msg, Throwable t) { - for (int i = 0; i < _logs.length; i++) - _logs[i].debug(msg, t); - } - public void warn(Object msg) { for (int i = 0; i < _logs.length; i++) _logs[i].warn(msg); @@ -183,13 +173,6 @@ public class MultiLogFactory implements LogFactory { return false; } - public boolean isDebugEnabled() { - for (int i = 0; i < _logs.length; i++) - if (_logs[i].isDebugEnabled()) - return true; - return false; - } - public boolean isErrorEnabled() { for (int i = 0; i < _logs.length; i++) if (_logs[i].isErrorEnabled()) diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java index 65d0f8d13..7fe45d060 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/log/NoneLogFactory.java @@ -38,10 +38,6 @@ public class NoneLogFactory implements LogFactory { return s_log; } - public final boolean isDebugEnabled() { - return false; - } - public final boolean isErrorEnabled() { return false; } @@ -68,12 +64,6 @@ public class NoneLogFactory implements LogFactory { public final void trace(Object o, Throwable t) { } - public final void debug(Object o) { - } - - public final void debug(Object o, Throwable t) { - } - public final void info(Object o) { } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java index 117b6a691..2d2258905 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/CFMetaDataParser.java @@ -279,7 +279,7 @@ public class CFMetaDataParser extends XMLMetaDataParser { return null; Class cls = classForName(name, _package, resolve, currentClassLoader()); if (cls == null) - throw getException(_loc.get("invalid-class", name)); + throw getException(_loc.get("invalid-class", name).getMessage()); return cls; } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java index 63019ec35..8ca36b2c6 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/ClassArgParser.java @@ -101,12 +101,12 @@ public class ClassArgParser { if (i == 0) { if (charIdx == packageElementName.length()) throw new UnsupportedOperationException(_loc.get - ("cant-diff-elems")); + ("cant-diff-elems").getMessage()); buf[i] = packageElementName.charAt(charIdx); } else { if (charIdx == classElementNames[i - 1].length()) throw new UnsupportedOperationException(_loc.get - ("cant-diff-elems")); + ("cant-diff-elems").getMessage()); buf[i] = classElementNames[i - 1].charAt(charIdx); } } @@ -212,7 +212,8 @@ public class ClassArgParser { return (String[]) col.toArray(new String[col.size()]); } } catch (Exception e) { - throw new NestableRuntimeException(_loc.get("class-arg", arg), e); + throw new NestableRuntimeException( + _loc.get("class-arg", arg).getMessage(), e); } // must be a class name @@ -234,8 +235,8 @@ public class ClassArgParser { appendTypeNames(source, itr.getInputStream(), names); } } catch (Exception e) { - throw new NestableRuntimeException(_loc.get("class-arg", source), - e); + throw new NestableRuntimeException( + _loc.get("class-arg", source).getMessage(), e); } return (String[]) names.toArray(new String[names.size()]); } @@ -279,8 +280,8 @@ public class ClassArgParser { names.clear(); } } catch (Exception e) { - throw new NestableRuntimeException(_loc.get("class-arg", source), - e); + throw new NestableRuntimeException( + _loc.get("class-arg", source).getMessage(), e); } return map; } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java index 8997b4920..1089fdacd 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/FileMetaDataIterator.java @@ -74,7 +74,7 @@ public class FileMetaDataIterator implements MetaDataIterator { Collection metas, int scanned) throws IOException { if (scanned > SCAN_LIMIT) throw new IllegalStateException(_loc.get("too-many-files", - String.valueOf(SCAN_LIMIT))); + String.valueOf(SCAN_LIMIT)).getMessage()); scanned++; if (filter == null) diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTrackers.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTrackers.java index d3a08154a..f7bcff54a 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTrackers.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/SourceTrackers.java @@ -42,7 +42,7 @@ public class SourceTrackers { String sourceFilePath; for (int i = 0; i < trackers.length; i++) { sourceFilePath = (trackers[i].getSourceFile() == null ? - _loc.get("source-tracker-file-unknown") : + _loc.get("source-tracker-file-unknown").getMessage() : trackers[i].getSourceFile().getAbsolutePath()); buf.append(" ").append(_loc.get( "source-trackers-location-line-item", diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java index 162fcf6a7..917eedde7 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java @@ -40,6 +40,7 @@ import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.DefaultHandler; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.util.JavaVersions; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.xml.Commentable; import org.apache.openjpa.lib.xml.DocTypeReader; @@ -655,9 +656,19 @@ public abstract class XMLMetaDataParser extends DefaultHandler * Returns a SAXException with the source file name and the given error * message. */ - protected SAXException getException(String msg, Throwable cause) { + protected SAXException getException(Message msg) { + return new SAXException(getSourceName() + currentLocation() + + ": " + msg.getMessage()); + } + + /** + * Returns a SAXException with the source file name and the given error + * message. + */ + protected SAXException getException(Message msg, Throwable cause) { if (cause != null && _log != null && _log.isTraceEnabled()) - _log.trace(cause); + _log.trace(_loc.get("sax-exception", + getSourceName(), _location.getLocation()), cause); return new SAXException(getSourceName() + currentLocation() + ": " + msg + " [" + cause + "]"); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java index 61ac845f2..0e80d9541 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractListIterator.java @@ -31,14 +31,17 @@ abstract class AbstractListIterator implements ListIterator { (AbstractListIterator.class); public void add(Object o) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw new UnsupportedOperationException(_loc.get("read-only") + .getMessage()); } public void set(Object o) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw new UnsupportedOperationException(_loc.get("read-only") + .getMessage()); } public void remove() { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw new UnsupportedOperationException(_loc.get("read-only") + .getMessage()); } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java index ab020632b..e733322d7 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/AbstractResultList.java @@ -33,43 +33,48 @@ public abstract class AbstractResultList implements ResultList { (AbstractResultList.class); public void add(int index, Object element) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); + } + + private UnsupportedOperationException readOnly() { + return new UnsupportedOperationException(_loc.get("read-only") + .getMessage()); } public boolean add(Object o) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public boolean addAll(Collection c) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public Object remove(int index) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public boolean remove(Object o) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public boolean removeAll(Collection c) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public boolean retainAll(Collection c) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public Object set(int index, Object element) { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public void clear() { - throw new UnsupportedOperationException(_loc.get("read-only")); + throw readOnly(); } public List subList(int from, int to) { @@ -83,6 +88,6 @@ public abstract class AbstractResultList implements ResultList { protected void assertOpen() { if (isClosed()) - throw new NoSuchElementException(_loc.get("closed")); + throw new NoSuchElementException(_loc.get("closed").getMessage()); } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java index b34aac0e7..3352d9449 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/RangeResultObjectProvider.java @@ -57,7 +57,7 @@ public class RangeResultObjectProvider implements ResultObjectProvider { _delegate = delegate; if (startIdx > Integer.MAX_VALUE || endIdx > Integer.MAX_VALUE) throw new IllegalArgumentException(_loc.get("range-too-high", - String.valueOf(startIdx), String.valueOf(endIdx))); + String.valueOf(startIdx), String.valueOf(endIdx)).getMessage()); _startIdx = (int) startIdx; _endIdx = (int) endIdx; diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java index 54ca62d7a..8c48b6f42 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/rop/ResultListIterator.java @@ -56,7 +56,7 @@ public class ResultListIterator extends AbstractListIterator { public Object next() { if (_rl.isClosed()) - throw new NoSuchElementException(_loc.get("closed")); + throw new NoSuchElementException(_loc.get("closed").getMessage()); return _li.next(); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/FormatPreservingProperties.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/FormatPreservingProperties.java index 05697bfff..4245d057f 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/FormatPreservingProperties.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/FormatPreservingProperties.java @@ -557,7 +557,7 @@ public class FormatPreservingProperties extends Properties { public DuplicateKeyException(String key, Object firstVal, String secondVal) { - super(_loc.get("dup-key", key, firstVal, secondVal)); + super(_loc.get("dup-key", key, firstVal, secondVal).getMessage()); } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java index e41e33e8d..26764bb61 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Localizer.java @@ -56,6 +56,9 @@ public class Localizer { // the local file name and class' classloader private ResourceBundle _bundle = null; + // the package that this localizer was created for. + private Package _package; + /** * Return a Localizer instance that will access the properties file * in the package of the given class using the system default locale. @@ -106,7 +109,7 @@ public class Localizer { } // cache the localizer - loc = new Localizer(); + loc = new Localizer(cls == null ? null : cls.getPackage()); loc._bundle = bundle; _localizers.put(key, loc); return loc; @@ -126,18 +129,22 @@ public class Localizer { return _providers.remove(provider); } - /** - * Return the localized string matching the given key. - */ - public String get(String key) { - return get(key, false); + private Localizer(Package p) { + _package = p; } /** * Return the localized string matching the given key. */ - public String getFatal(String key) { - return get(key, true); + public Message get(String key) { + return get(key, null); + } + + /** + * Return the localized string matching the given key. + */ + public Message getFatal(String key) { + return getFatal(key, null); } /** @@ -148,7 +155,7 @@ public class Localizer { * * @see #get(String) */ - public String get(String key, Object sub) { + public Message get(String key, Object sub) { return get(key, new Object[]{ sub }); } @@ -160,7 +167,7 @@ public class Localizer { * * @see #getFatal(String) */ - public String getFatal(String key, Object sub) { + public Message getFatal(String key, Object sub) { return getFatal(key, new Object[]{ sub }); } @@ -169,7 +176,7 @@ public class Localizer { * * @see #get(String,Object) */ - public String get(String key, Object sub1, Object sub2) { + public Message get(String key, Object sub1, Object sub2) { return get(key, new Object[]{ sub1, sub2 }); } @@ -178,7 +185,7 @@ public class Localizer { * * @see #getFatal(String,Object) */ - public String getFatal(String key, Object sub1, Object sub2) { + public Message getFatal(String key, Object sub1, Object sub2) { return getFatal(key, new Object[]{ sub1, sub2 }); } @@ -187,7 +194,7 @@ public class Localizer { * * @see #get(String,Object) */ - public String get(String key, Object sub1, Object sub2, Object sub3) { + public Message get(String key, Object sub1, Object sub2, Object sub3) { return get(key, new Object[]{ sub1, sub2, sub3 }); } @@ -199,9 +206,8 @@ public class Localizer { * * @see #get(String) */ - public String get(String key, Object[] subs) { - String str = get(key); - return MessageFormat.format(str, subs); + public Message get(String key, Object[] subs) { + return new Message(key, subs, false); } /** @@ -212,24 +218,70 @@ public class Localizer { * * @see #getFatal(String) */ - public String getFatal(String key, Object[] subs) { - String str = getFatal(key); - return MessageFormat.format(str, subs); + public Message getFatal(String key, Object[] subs) { + return new Message(key, subs, true); } - private String get(String key, boolean fatal) { - if (_bundle == null) { - if (fatal) - throw new MissingResourceException(key, key, key); + /** + * A Message can provide a localized message via the + * {@link #getMessage} method call, and can also provide the original key, + * package, and substitution array that were used to assemble the message. + */ + public class Message { + + private final String key; + private final Object[] subs; + private String localizedMessage; + private boolean messageFound = false; + + private Message(String key, Object[] subs, boolean fatal) { + this.key = key; + this.subs = subs; + + if (_bundle == null) { + if (fatal) + throw new MissingResourceException(key, key, key); + else { + localizedMessage = key; + messageFound = false; + } + } else { + try { + localizedMessage = _bundle.getString(key); + messageFound = true; + } catch (MissingResourceException mre) { + if (!fatal) + localizedMessage = key; + else + throw mre; + } + } + } + + /** + * The localized message. + */ + public String getMessage() { + if (messageFound) + return MessageFormat.format(localizedMessage, subs); + else + return key; + } + + public String getKey() { return key; } - try { - return _bundle.getString(key); - } catch (MissingResourceException mre) { - if (!fatal) - return key; - throw mre; + public Object[] getSubstitutions() { + return subs; + } + + public Package getPackage() { + return _package; + } + + public String toString() { + return getMessage(); } } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java index 9757ba72f..5716e8274 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java @@ -33,6 +33,10 @@ public class ParseException extends NestableRuntimeException { super(msg); } + public ParseException(Localizer.Message msg) { + super(msg.getMessage()); + } + public ParseException(Throwable cause) { super(cause); } @@ -40,4 +44,8 @@ public class ParseException extends NestableRuntimeException { public ParseException(String msg, Throwable cause) { super(msg, cause); } + + public ParseException(Localizer.Message msg, Throwable cause) { + super(msg.getMessage(), cause); + } } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/xml/Location.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/xml/Location.java index 7338943ad..5c616aa2a 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/xml/Location.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/xml/Location.java @@ -47,17 +47,16 @@ public class Location { if (_locator == null) { if (_nullOnNoLocator) return null; - return _loc.get("no-locator"); + return _loc.get("no-locator").getMessage(); } - String forma = MessageFormat.format(format, new Object []{ + return MessageFormat.format(format, new Object []{ Numbers.valueOf(_locator.getLineNumber()), Numbers.valueOf(_locator.getColumnNumber()), _locator.getPublicId(), _locator.getSystemId() }); - return forma; } public String getLocation() { - return getLocation(_loc.get("location-format")); + return getLocation(_loc.get("location-format").getMessage()); } public void setLocator(Locator locator) { diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties index 495d26abc..d5c68f76b 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties @@ -60,6 +60,8 @@ closeable-ex: An exception occurred while invoking close() on "{0}". This \ exception will be consumed. dup-with-different-prefixes: Found multiple properties with different valid \ prefixes. Properties: {0}, {1}. +plugin-creation-exception: An exception occurred while creating a plugin for \ + value {0}. This exception will be consumed. Log-name: Log factory Log-desc: LogFactory and configuration diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/jdbc/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/jdbc/localizer.properties index 94f3a2af1..bf9048f9a 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/jdbc/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/jdbc/localizer.properties @@ -84,3 +84,4 @@ login-timeout-desc: The maximum number of milliseconds to block for database \ login. close-pool: Shutting down connection pool. close-pool-fail: Error caught when issuing close pool SQL: {0} +datasource-trace-data: {0} \ No newline at end of file diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/log/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/log/localizer.properties index 332351997..8c0eff901 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/log/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/log/localizer.properties @@ -1,14 +1,14 @@ log-trace: TRACE -log-debug: DEBUG log-info: INFO log-warn: WARN log-error: ERROR log-fatal: FATAL log-unknown: UNKNOWN log-bad-constant: The log level string "{0}" is not valid. Valid values are \ - TRACE, DEBUG, INFO, WARN, ERROR or FATAL. + TRACE, INFO, WARN, ERROR or FATAL. log-bad-file: The file name "{0}" is not valid. could-not-create-factory: An error occurred while trying to create a \ LogFactory of type "{0}", as specified by the \ - org.apache.openjpa.lib.log.LogFactory system property. Created a \ + openjpa.Log system property. Created a \ org.apache.openjpa.lib.log.LogFactoryImpl instead. +log-output-stream-data: {0} diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties index f37569532..869604f80 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties @@ -23,3 +23,6 @@ source-trackers-location-line-item: {0}: {1} source-tracker-file-unknown: parser-schema-bug: XML schema validation is disabled due to bugs detected \ in the SAX parser. +sax-exception: An exception occurred while parsing {0} at location {1}. \ + This exception has been translated to a SAXException, and will be \ + re-thrown. The original exception is being logged along with this message. \ No newline at end of file diff --git a/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java b/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java index cff4b1c22..4a187ffb1 100644 --- a/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java +++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/test/AbstractTestCase.java @@ -61,6 +61,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.LogFactoryImpl; +import org.apache.openjpa.lib.util.Localizer; /** * TestCase framework to run various tests against solarmetric code. @@ -85,6 +86,9 @@ public abstract class AbstractTestCase extends TestCase { public static final String SKIP_TOKEN = "SOLARSKIP"; public static final String SKIP_DELIMITER = "|"; + private static final Localizer _loc = + Localizer.forPackage(AbstractTestCase.class); + protected String multiThreadExecuting = null; protected boolean inTimeoutThread = false; @@ -148,7 +152,7 @@ public abstract class AbstractTestCase extends TestCase { try { _lastTest.tearDownTestClass(); } catch (Throwable t) { - getLog().error(t); + getLog().error(null, t); } } @@ -156,7 +160,7 @@ public abstract class AbstractTestCase extends TestCase { try { setUpTestClass(); } catch (Throwable t) { - getLog().error(t); + getLog().error(null, t); } } @@ -875,8 +879,8 @@ public abstract class AbstractTestCase extends TestCase { if (time != null) elapsed = System.currentTimeMillis() - time.longValue(); - getLog() - .info(name + ": " + (time == null ? "???" : "" + elapsed) + "ms"); + getLog().info(_loc.get("profile-info", name, + (time == null ? "???" : "" + elapsed))); return elapsed; } @@ -1234,9 +1238,10 @@ public abstract class AbstractTestCase extends TestCase { long used = total - free; NumberFormat nf = NumberFormat.getInstance(); - getLog().warn("memory:" + " used: " + nf.format(used) - + " total: " + nf.format(total) - + " free: " + nf.format(free)); + getLog().warn(_loc.get("mem-info", + nf.format(used), + nf.format(total), + nf.format(free))); } /** diff --git a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java index e9faa6fac..a53e76efa 100644 --- a/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java +++ b/openjpa-lib/src/test/java/org/apache/openjpa/lib/util/TestLocalizer.java @@ -19,6 +19,8 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; + +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.lib.util.testlocalizer.LocalizerTestHelper; /** @@ -108,6 +110,10 @@ public class TestLocalizer extends TestCase { } catch (MissingResourceException mre) { } } + + public static void assertEquals(String s, Message m) { + assertEquals(s, m.getMessage()); + } public static Test suite() { return new TestSuite(TestLocalizer.class); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ArgumentException.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ArgumentException.java index 0721e2f4a..9a827f196 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ArgumentException.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ArgumentException.java @@ -25,6 +25,8 @@ import java.io.Serializable; import org.apache.openjpa.util.ExceptionInfo; import org.apache.openjpa.util.Exceptions; +import org.apache.openjpa.lib.util.Localizer.Message; + /** * Extended {@link IllegalArgumentException}. * @@ -48,6 +50,11 @@ public class ArgumentException _fatal = fatal; } + public ArgumentException(Message msg, Throwable[] nested, Object failed, + boolean fatal) { + this(msg.getMessage(), nested, failed, fatal); + } + public int getType() { return USER; } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java index 85fd47057..059b8339b 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ConfigurationProviderImpl.java @@ -180,7 +180,7 @@ public class ConfigurationProviderImpl String msg = (pinfo == null) ? "missing-xml-config" : "cantload-xml-config"; throw new MissingResourceException(_loc.get(msg, rsrc, - String.valueOf(name)), getClass().getName(), rsrc); + String.valueOf(name)).getMessage(), getClass().getName(), rsrc); } return true; } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java index a6b3eb2db..d0755c227 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java @@ -386,7 +386,8 @@ public class EntityManagerImpl public boolean getRollbackOnly() { if (!isActive()) - throw new IllegalStateException(_loc.get("no-transaction")); + throw new IllegalStateException(_loc.get("no-transaction") + .getMessage()); return _broker.getRollbackOnly(); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/InvalidStateException.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/InvalidStateException.java index b1d97f886..49b15ffff 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/InvalidStateException.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/InvalidStateException.java @@ -25,6 +25,7 @@ import java.io.Serializable; import org.apache.openjpa.util.ExceptionInfo; import org.apache.openjpa.util.Exceptions; import org.apache.openjpa.util.UserException; +import org.apache.openjpa.lib.util.Localizer.Message; /** * Extended {@link IllegalStateException}. @@ -41,6 +42,11 @@ public class InvalidStateException private transient Object _failed = null; private transient Throwable[] _nested = null; + public InvalidStateException(Message msg, Throwable[] nested, Object failed, + boolean fatal) { + this(msg.getMessage(), nested, failed, fatal); + } + public InvalidStateException(String msg, Throwable[] nested, Object failed, boolean fatal) { super(msg); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java index beacdb076..3db3a3119 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceExceptions.java @@ -168,8 +168,8 @@ public class PersistenceExceptions Exception e; switch (ke.getSubtype()) { case UserException.NO_TRANSACTION: - e = - new org.apache.openjpa.persistence.TransactionRequiredException + e = new + org.apache.openjpa.persistence.TransactionRequiredException (ke.getMessage(), getNestedThrowables(ke), getFailedObject(ke), ke.isFatal()); break; diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java index 78afd52b9..da8ed3a55 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java @@ -215,7 +215,8 @@ public class PersistenceUnitInfoImpl } } } - throw new IllegalArgumentException(s_loc.get("bad-jar-name", name)); + throw new IllegalArgumentException(s_loc.get("bad-jar-name", name) + .getMessage()); } public List getManagedClassNames() { diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java index 5c66bfec4..17e25c2bb 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java @@ -278,11 +278,11 @@ public class QueryImpl Iterator itr = res.iterator(); if (!itr.hasNext()) throw new NoResultException(_loc.get("no-results", - _query.getQueryString()), null, null, false); + _query.getQueryString()).getMessage(), null, null, false); Object ret = itr.next(); if (itr.hasNext()) throw new NonUniqueResultException(_loc.get("mult-results", - _query.getQueryString()), null, null, false); + _query.getQueryString()).getMessage(), null, null, false); return ret; } finally { OpenJPAPersistence.close(res); diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TransactionRequiredException.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TransactionRequiredException.java index ac37d81cb..972c891ce 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TransactionRequiredException.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TransactionRequiredException.java @@ -22,6 +22,7 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.Serializable; +import org.apache.openjpa.lib.util.Localizer.Message; import org.apache.openjpa.util.ExceptionInfo; import org.apache.openjpa.util.Exceptions; import org.apache.openjpa.util.UserException; @@ -41,6 +42,11 @@ public class TransactionRequiredException private transient Object _failed = null; private transient Throwable[] _nested = null; + public TransactionRequiredException(Message msg, Throwable[] nested, + Object failed, boolean fatal) { + this(msg.getMessage(), nested, failed, fatal); + } + public TransactionRequiredException(String msg, Throwable[] nested, Object failed, boolean fatal) { super(msg);