OPENJPA-933: Database version detection in MySQLDictionary is not reliable

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@766310 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Milosz Tylenda 2009-04-18 12:26:26 +00:00
parent 8bbf149781
commit 4d1b86e860
1 changed files with 27 additions and 27 deletions

View File

@ -119,15 +119,25 @@ public class MySQLDictionary
super.connectedConfiguration(conn); super.connectedConfiguration(conn);
DatabaseMetaData metaData = conn.getMetaData(); DatabaseMetaData metaData = conn.getMetaData();
// The product version looks like 4.1.3-nt int maj = 0;
String productVersion = metaData.getDatabaseProductVersion(); int min = 0;
// The driver version looks like mysql-connector-java-3.1.11 (...) if (isJDBC3) {
String driverVersion = metaData.getDriverVersion(); maj = metaData.getDatabaseMajorVersion();
min = metaData.getDatabaseMinorVersion();
} else {
try { try {
// The product version looks like 4.1.3-nt or 5.1.30
String productVersion = metaData.getDatabaseProductVersion();
int[] versions = getMajorMinorVersions(productVersion); int[] versions = getMajorMinorVersions(productVersion);
int maj = versions[0]; maj = versions[0];
int min = versions[1]; min = versions[1];
} catch (IllegalArgumentException e) {
// we don't understand the version format.
// That is ok. We just take the default values.
if (log.isWarnEnabled())
log.warn(e.toString(), e);
}
}
if (maj < 4 || (maj == 4 && min < 1)) { if (maj < 4 || (maj == 4 && min < 1)) {
supportsSubselect = false; supportsSubselect = false;
allowsAliasInBulkClause = false; allowsAliasInBulkClause = false;
@ -135,16 +145,9 @@ public class MySQLDictionary
if (maj > 5 || (maj == 5 && min >= 1)) if (maj > 5 || (maj == 5 && min >= 1))
supportsXMLColumn = true; supportsXMLColumn = true;
versions = getMajorMinorVersions(driverVersion); if (metaData.getDriverMajorVersion() < 5)
maj = versions[0];
if (maj < 5) {
driverDeserializesBlobs = true; driverDeserializesBlobs = true;
} }
} catch (IllegalArgumentException e) {
// we don't understand the version format.
// That is ok. We just take the default values.
}
}
public Connection decorate(Connection conn) throws SQLException { public Connection decorate(Connection conn) throws SQLException {
conn = super.decorate(conn); conn = super.decorate(conn);
@ -157,7 +160,6 @@ public class MySQLDictionary
private static int[] getMajorMinorVersions(String versionStr) private static int[] getMajorMinorVersions(String versionStr)
throws IllegalArgumentException { throws IllegalArgumentException {
int beginIndex = 0; int beginIndex = 0;
int endIndex = 0;
versionStr = versionStr.trim(); versionStr = versionStr.trim();
char[] charArr = versionStr.toCharArray(); char[] charArr = versionStr.toCharArray();
@ -168,6 +170,7 @@ public class MySQLDictionary
} }
} }
int endIndex = charArr.length;
for (int i = beginIndex+1; i < charArr.length; i++) { for (int i = beginIndex+1; i < charArr.length; i++) {
if (charArr[i] != '.' && !Character.isDigit(charArr[i])) { if (charArr[i] != '.' && !Character.isDigit(charArr[i])) {
endIndex = i; endIndex = i;
@ -175,9 +178,6 @@ public class MySQLDictionary
} }
} }
if (endIndex < beginIndex)
throw new IllegalArgumentException();
String[] arr = versionStr.substring(beginIndex, endIndex).split("\\."); String[] arr = versionStr.substring(beginIndex, endIndex).split("\\.");
if (arr.length < 2) if (arr.length < 2)
throw new IllegalArgumentException(); throw new IllegalArgumentException();