mirror of https://github.com/apache/openjpa.git
Improve error messages when processing metadata / JPQL queries.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@572492 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8274867a54
commit
a3b0778071
|
@ -164,11 +164,17 @@ public class JPQLExpressionBuilder
|
||||||
if (c != null)
|
if (c != null)
|
||||||
cmd = repos.getMetaData(c, loader, assertValid);
|
cmd = repos.getMetaData(c, loader, assertValid);
|
||||||
else if (assertValid)
|
else if (assertValid)
|
||||||
cmd = repos.getMetaData(alias, loader, true);
|
cmd = repos.getMetaData(alias, loader, false);
|
||||||
|
|
||||||
if (cmd == null && assertValid)
|
if (cmd == null && assertValid) {
|
||||||
throw parseException(EX_USER, "not-schema-name",
|
String close = repos.getClosestAliasName(alias);
|
||||||
new Object[]{ alias }, null);
|
if (close != null)
|
||||||
|
throw parseException(EX_USER, "not-schema-name-hint",
|
||||||
|
new Object[]{ alias, close, repos.getAliasNames() }, null);
|
||||||
|
else
|
||||||
|
throw parseException(EX_USER, "not-schema-name",
|
||||||
|
new Object[]{ alias, repos.getAliasNames() }, null);
|
||||||
|
}
|
||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.openjpa.lib.log.Log;
|
||||||
import org.apache.openjpa.lib.util.Closeable;
|
import org.apache.openjpa.lib.util.Closeable;
|
||||||
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
import org.apache.openjpa.lib.util.J2DoPrivHelper;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
|
import org.apache.openjpa.lib.util.StringDistance;
|
||||||
import org.apache.openjpa.util.ImplHelper;
|
import org.apache.openjpa.util.ImplHelper;
|
||||||
import org.apache.openjpa.util.InternalException;
|
import org.apache.openjpa.util.InternalException;
|
||||||
import org.apache.openjpa.util.MetaDataException;
|
import org.apache.openjpa.util.MetaDataException;
|
||||||
|
@ -360,8 +361,7 @@ public class MetaDataRepository
|
||||||
// maybe this is some type we've seen but just isn't valid
|
// maybe this is some type we've seen but just isn't valid
|
||||||
if (_aliases.containsKey(alias)) {
|
if (_aliases.containsKey(alias)) {
|
||||||
if (mustExist)
|
if (mustExist)
|
||||||
throw new MetaDataException(_loc.get("no-alias-meta", alias,
|
throwNoRegisteredAlias(alias);
|
||||||
_aliases.toString()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +370,43 @@ public class MetaDataRepository
|
||||||
|
|
||||||
if (!mustExist)
|
if (!mustExist)
|
||||||
return null;
|
return null;
|
||||||
throw new MetaDataException(_loc.get("no-alias-meta", alias, _aliases));
|
return throwNoRegisteredAlias(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClassMetaData throwNoRegisteredAlias(String alias) {
|
||||||
|
String close = getClosestAliasName(alias);
|
||||||
|
if (close != null)
|
||||||
|
throw new MetaDataException(
|
||||||
|
_loc.get("no-alias-meta-hint", alias, _aliases, close));
|
||||||
|
else
|
||||||
|
throw new MetaDataException(
|
||||||
|
_loc.get("no-alias-meta", alias, _aliases));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nearest match to the specified alias name
|
||||||
|
* @since 1.1.0
|
||||||
|
*/
|
||||||
|
public String getClosestAliasName(String alias) {
|
||||||
|
Collection aliases = getAliasNames();
|
||||||
|
return StringDistance.getClosestLevenshteinDistance(alias, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the registered alias names
|
||||||
|
* @since 1.1.0
|
||||||
|
*/
|
||||||
|
public Collection getAliasNames() {
|
||||||
|
Collection aliases = new HashSet();
|
||||||
|
synchronized (_aliases) {
|
||||||
|
for (Iterator iter = _aliases.entrySet().iterator();
|
||||||
|
iter.hasNext(); ) {
|
||||||
|
Map.Entry e = (Map.Entry) iter.next();
|
||||||
|
if (e.getValue() != null)
|
||||||
|
aliases.add(e.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,10 @@ unknown-comp: Unknown comparison operator "{0}".
|
||||||
wrong-child-count: Wrong number of arguments to expression \
|
wrong-child-count: Wrong number of arguments to expression \
|
||||||
of type "{1}": should have been {0}, but the following arguments \
|
of type "{1}": should have been {0}, but the following arguments \
|
||||||
were specified: "{2}".
|
were specified: "{2}".
|
||||||
not-schema-name: The name "{0}" is not a recognized entity or identifier.
|
not-schema-name: The name "{0}" is not a recognized entity or identifier. \
|
||||||
|
Known entity names: {1}
|
||||||
|
not-schema-name-hint: The name "{0}" is not a recognized entity or identifier. \
|
||||||
|
Perhaps you meant {1}, which is a close match. Known entity names: {2}
|
||||||
duplicate-alias: Alias "{0}" was declared twice.
|
duplicate-alias: Alias "{0}" was declared twice.
|
||||||
unknown-type: Cannot determine the type of field "{0}".
|
unknown-type: Cannot determine the type of field "{0}".
|
||||||
unexpected-var: The variable "{0}" was found where a constant or \
|
unexpected-var: The variable "{0}" was found where a constant or \
|
||||||
|
|
|
@ -142,9 +142,15 @@ no-meta: No metadata was found for type "{0}". Ensure that the class is \
|
||||||
if you list your persistent classes, the class is included in your list.
|
if you list your persistent classes, the class is included in your list.
|
||||||
no-oid-meta: Could not locate metadata for the class using oid "{0}" of \
|
no-oid-meta: Could not locate metadata for the class using oid "{0}" of \
|
||||||
type "{1}". Registered oid type mappings: "{2}"
|
type "{1}". Registered oid type mappings: "{2}"
|
||||||
no-alias-meta: Could not locate metadata for the class using alias "{0}". This \
|
no-alias-meta: Could not locate metadata for the class using alias "{0}". \
|
||||||
could mean that the OpenJPA enhancer or load-time weaver was not run on \
|
This could mean that you have mis-spelled the alias, or that OpenJPA failed\
|
||||||
the type whose alias is "{0}". Registered alias mappings: "{1}"
|
to properly load the metadata for the type whose alias is "{0}". \
|
||||||
|
Registered alias mappings: "{1}"
|
||||||
|
no-alias-meta-hint: Could not locate metadata for the class using alias "{0}". \
|
||||||
|
Perhaps you meant {2}, which is a close match. \
|
||||||
|
This could mean that you have mis-spelled the alias, or that OpenJPA failed\
|
||||||
|
to properly load the metadata for the type whose alias is "{0}". \
|
||||||
|
Registered alias mappings: "{1}"
|
||||||
error-registered: An error occurred while processing registered class "{0}".
|
error-registered: An error occurred while processing registered class "{0}".
|
||||||
failed-registered: A potentially serious error occurred while processing \
|
failed-registered: A potentially serious error occurred while processing \
|
||||||
registered class "{0}". Deferring processing of this class until next \
|
registered class "{0}". Deferring processing of this class until next \
|
||||||
|
|
|
@ -53,7 +53,8 @@ public class TestSimpleXmlEntity
|
||||||
fail("should not be able to execute query using short class name " +
|
fail("should not be able to execute query using short class name " +
|
||||||
"for entity that has an entity name specified");
|
"for entity that has an entity name specified");
|
||||||
} catch (ArgumentException ae) {
|
} catch (ArgumentException ae) {
|
||||||
// expected
|
assertTrue(
|
||||||
|
ae.getMessage().indexOf("Perhaps you meant SimpleXml,") != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +68,8 @@ public class TestSimpleXmlEntity
|
||||||
fail("should not be able to execute query using short class name " +
|
fail("should not be able to execute query using short class name " +
|
||||||
"for entity that has an entity name specified");
|
"for entity that has an entity name specified");
|
||||||
} catch (ArgumentException ae) {
|
} catch (ArgumentException ae) {
|
||||||
// expected
|
assertTrue(
|
||||||
|
ae.getMessage().indexOf("Perhaps you meant SimpleXml,") != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue