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