mirror of https://github.com/apache/openjpa.git
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:
parent
7b0d1140ac
commit
dcf90c68eb
|
@ -426,15 +426,26 @@ public class PostgresDictionary
|
||||||
// sequence is owned. This is not perfect, but considerably better than
|
// sequence is owned. This is not perfect, but considerably better than
|
||||||
// considering all sequences suffixed with _seq are db owned.
|
// considering all sequences suffixed with _seq are db owned.
|
||||||
String[][] namePairs = buildNames(strName);
|
String[][] namePairs = buildNames(strName);
|
||||||
try {
|
|
||||||
for (int i = 0; i < namePairs.length; i++) {
|
if(namePairs != null) { // unable to parse strName.
|
||||||
if (queryOwnership(conn, namePairs[i], schema)) {
|
try {
|
||||||
return true;
|
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) {
|
} else {
|
||||||
if (log.isWarnEnabled())
|
if(log.isTraceEnabled()) {
|
||||||
log.warn(_loc.get("psql-owned-seq-warning"), t);
|
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 isOwnedSequence(strName);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -496,7 +507,8 @@ public class PostgresDictionary
|
||||||
* names can contain underscores so permutations of these names must be
|
* names can contain underscores so permutations of these names must be
|
||||||
* produced for ownership verification.
|
* produced for ownership verification.
|
||||||
* @param strName
|
* @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) {
|
private String[][] buildNames(String strName) {
|
||||||
// split the sequence name into components
|
// split the sequence name into components
|
||||||
|
@ -504,6 +516,10 @@ public class PostgresDictionary
|
||||||
String[] parts = Normalizer.splitName(strName, "_");
|
String[] parts = Normalizer.splitName(strName, "_");
|
||||||
|
|
||||||
if (parts == null || parts.length < 3) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
// Simple and most common case
|
// Simple and most common case
|
||||||
|
|
Loading…
Reference in New Issue