mirror of https://github.com/apache/openjpa.git
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:
parent
8bbf149781
commit
4d1b86e860
|
@ -119,15 +119,25 @@ 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();
|
||||
|
||||
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);
|
||||
int maj = versions[0];
|
||||
int min = versions[1];
|
||||
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 < 4 || (maj == 4 && min < 1)) {
|
||||
supportsSubselect = false;
|
||||
allowsAliasInBulkClause = false;
|
||||
|
@ -135,16 +145,9 @@ public class MySQLDictionary
|
|||
if (maj > 5 || (maj == 5 && min >= 1))
|
||||
supportsXMLColumn = true;
|
||||
|
||||
versions = getMajorMinorVersions(driverVersion);
|
||||
maj = versions[0];
|
||||
if (maj < 5) {
|
||||
if (metaData.getDriverMajorVersion() < 5)
|
||||
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 {
|
||||
conn = super.decorate(conn);
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue