You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2009/07/22 21:36:59 UTC
svn commit: r796854 - in /openjpa/trunk/openjpa-persistence/src:
main/java/org/apache/openjpa/persistence/TupleImpl.java
main/resources/org/apache/openjpa/persistence/localizer.properties
test/java/org/apache/openjpa/persistence/TestTupleImpl.java
Author: mikedd
Date: Wed Jul 22 19:36:59 2009
New Revision: 796854
URL: http://svn.apache.org/viewvc?rev=796854&view=rev
Log:
OPWNJPA-1191
Adding messages exceptions thrown by TupleImpl
Modified:
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleImpl.java
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java
Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleImpl.java?rev=796854&r1=796853&r2=796854&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleImpl.java Wed Jul 22 19:36:59 2009
@@ -25,7 +25,11 @@
import javax.persistence.Tuple;
import javax.persistence.TupleElement;
+import org.apache.openjpa.kernel.ExpressionStoreQuery;
+import org.apache.openjpa.lib.util.Localizer;
+
public class TupleImpl implements Tuple {
+ private static final Localizer _loc = Localizer.forPackage(TupleImpl.class);
List<TupleElement<?>> elements = new ArrayList<TupleElement<?>>();
/**
@@ -39,9 +43,10 @@
*/
public <X> X get(TupleElement<X> tupleElement) {
if (!elements.contains(tupleElement)) {
- throw new IllegalArgumentException("tupleElement was not found in this tuple"); // TODO MDD improve
+ throw new IllegalArgumentException(_loc.get(
+ "tuple-element-not-found",
+ new Object[] { tupleElement, elements }).getMessage());
}
-
TupleElementImpl<X> impl = (TupleElementImpl<X>) tupleElement;
return impl.getValue();
}
@@ -61,13 +66,13 @@
@SuppressWarnings("unchecked")
public <X> X get(String alias, Class<X> type) {
if (type == null) {
- throw new IllegalArgumentException("Type was null");
+ throw new IllegalArgumentException(_loc.get("tuple-was-null", "type").getMessage());
}
Object rval = get(alias);
if (!type.isAssignableFrom(rval.getClass())) {
- throw new IllegalArgumentException(String.format(
- "TupleElement type did not match for alias: %s. Provided type: %s actual type: %s", alias, type, rval
- .getClass().toString()));
+ throw new IllegalArgumentException(_loc.get(
+ "tuple-element-wrong-type",
+ new Object[] { alias, type, rval.getClass() }).getMessage());
}
return (X) rval;
}
@@ -83,14 +88,21 @@
*/
public Object get(String alias) {
if (alias == null) {
- throw new IllegalArgumentException(String.format("Alias was null."));
+ // TODO MDD determine if we can support this.
+ throw new IllegalArgumentException(_loc.get("typle-was-null", "alias").getMessage());
}
for (TupleElement<?> te : elements) {
if (alias.equals(te.getAlias())) {
return ((TupleElementImpl<?>) te).getValue();
}
}
- throw new IllegalArgumentException(String.format("Alias %s was not found.", alias));
+
+ List<String> knownAliases = new ArrayList<String>();
+ for(TupleElement<?> te : elements) {
+ knownAliases.add(te.getAlias());
+ }
+ throw new IllegalArgumentException(_loc.get("tuple-alias-not-found",
+ new Object[] { alias, knownAliases }).getMessage());
}
/**
@@ -107,13 +119,13 @@
@SuppressWarnings("unchecked")
public <X> X get(int i, Class<X> type) {
if (type == null) {
- throw new IllegalArgumentException("Type was null");
+ throw new IllegalArgumentException(_loc.get("tuple-was-null", "type").getMessage());
}
Object rval = get(i);
if(! type.isAssignableFrom(rval.getClass())) {
- throw new IllegalArgumentException(String.format(
- "Type did not match for position: %d. Provided type: %s actual type: %s", i, type.getClass(),
- rval.getClass()));
+ throw new IllegalArgumentException(_loc.get(
+ "tuple-element-wrong-type",
+ new Object[] { "position", i, type, type.getClass() }).getMessage());
}
return (X) rval;
}
@@ -129,11 +141,11 @@
*/
public Object get(int i) {
if (i > elements.size()) {
- throw new IllegalArgumentException(String.format(
- "Attempt to read TupleElement %d when there are only %d elements available", i, elements.size()));
+ throw new IllegalArgumentException(_loc.get("tuple-exceeded-size",
+ new Object[] { i, elements.size() }).getMessage());
}
- if (i == -1) {
- throw new IllegalArgumentException("Cannot obtain the -1th element in this tuple. Thank you for playing");
+ if (i <= -1) {
+ throw new IllegalArgumentException(_loc.get("tuple-stop-thinking-in-python").getMessage());
}
return toArray()[i];
}
Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=796854&r1=796853&r2=796854&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties (original)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties Wed Jul 22 19:36:59 2009
@@ -198,4 +198,9 @@
loaded by the JVM.
vlem-creation-info: OpenJPA dynamically loaded a validation provider.
no-embeddable-metadata: Unable to load metadata for embeddable class "{0}".
-
+tuple-element-not-found: TupleElement "{0}" "{1}" was not found in this Tuple. Contents of the Tuple: {2}.
+tuple-was-null: Input argument {0} was null. Unable to proceed.
+tuple-element-wrong-type: TupleElement type did not match for {0} "{1}". Provided type "{2}" , actual type "{3}"
+tuple-alias-not-found: Alias "{0}" was not found in this tuple. Aliases found : "{1}"
+tuple-exceeded-size : Attempt to read TupleElement {0} when there are only {1} elements available
+tuple-stop-thinking-in-python: Currently we do not support negative indexes into a Tuple.
Modified: openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java?rev=796854&r1=796853&r2=796854&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java Wed Jul 22 19:36:59 2009
@@ -21,10 +21,11 @@
import java.util.List;
-import javax.persistence.Entity;
import javax.persistence.Tuple;
import javax.persistence.TupleElement;
+import org.apache.openjpa.lib.util.Localizer;
+
import junit.framework.TestCase;
/**