OPENJPA-2005: check for unexpected (null) sequence names in PostgresDictionary

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1127898 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2011-05-26 13:28:00 +00:00
parent 7b0d1140ac
commit dcf90c68eb
1 changed files with 24 additions and 8 deletions

View File

@ -426,15 +426,26 @@ public class PostgresDictionary
// sequence is owned. This is not perfect, but considerably better than
// considering all sequences suffixed with _seq are db owned.
String[][] namePairs = buildNames(strName);
try {
for (int i = 0; i < namePairs.length; i++) {
if (queryOwnership(conn, namePairs[i], schema)) {
return true;
if(namePairs != null) { // unable to parse strName.
try {
for (int i = 0; i < namePairs.length; i++) {
if (queryOwnership(conn, namePairs[i], schema)) {
return true;
}
}
} catch (Throwable t) {
if (log.isWarnEnabled())
log.warn(_loc.get("psql-owned-seq-warning"), t);
return isOwnedSequence(strName);
}
} catch (Throwable t) {
if (log.isWarnEnabled())
log.warn(_loc.get("psql-owned-seq-warning"), t);
} else {
if(log.isTraceEnabled()) {
log.trace(String.format("Unable to query ownership for sequence %s using the connection. " +
"Falling back to simpler detection based on the name",
name.getName()));
}
return isOwnedSequence(strName);
}
return false;
@ -496,7 +507,8 @@ public class PostgresDictionary
* names can contain underscores so permutations of these names must be
* produced for ownership verification.
* @param strName
* @return
* @return If strName cannot be split into three or more parts null will be returned.
* Otherwise a String[][] of the potential sequence names will be returned.
*/
private String[][] buildNames(String strName) {
// split the sequence name into components
@ -504,6 +516,10 @@ public class PostgresDictionary
String[] parts = Normalizer.splitName(strName, "_");
if (parts == null || parts.length < 3) {
if(log.isTraceEnabled()) {
log.trace(String.format("Unable to parse sequences from %s. Found %s parts. Returning null",
strName, parts == null ? 0 : parts.length));
}
return null;
}
// Simple and most common case