Skip to content

Commit 2637c10

Browse files
authored
Bug 518774: HANAPlatform is not detected; improving platform detection (#520)
Signed-off-by: Will Dazey <[email protected]> Reviewed-by: Lukas Jungmann <[email protected]>
1 parent be65755 commit 2637c10

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/DBPlatformHelper.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 1998, 2019 IBM Corporation. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
56
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -56,20 +57,23 @@ public class DBPlatformHelper {
5657
* If vendorName does not match any of predefined vendor names, <code>
5758
* DEFAULTPLATFORM </code> is returned.
5859
*/
59-
public static String getDBPlatform(String vendorName, SessionLog logger) {
60+
public static String getDBPlatform(String vendorName, String minorVersion, String majorVersion, SessionLog logger) {
6061

6162
initializeNameToVendorPlatform(logger);
6263

63-
String detectedDbPlatform = null;
64-
if(vendorName != null) {
65-
detectedDbPlatform = matchVendorNameInProperties(vendorName, _nameToVendorPlatform, logger);
66-
}
64+
vendorName = (vendorName == null) ? "Vendor Not Found" : vendorName;
65+
minorVersion = (minorVersion == null) ? "0" : minorVersion;
66+
majorVersion = (majorVersion == null) ? "0" : majorVersion;
67+
68+
String vendor = vendorName + "[" + minorVersion + ", " + majorVersion + "]";
69+
70+
String detectedDbPlatform = matchVendorNameInProperties(vendor, _nameToVendorPlatform, logger);
6771
if (logger.shouldLog(SessionLog.FINE) ) {
6872
logger.log(SessionLog.FINE, SessionLog.CONNECTION, "dbPlatformHelper_detectedVendorPlatform", detectedDbPlatform ); // NOI18N
6973
}
7074
if (detectedDbPlatform == null) {
7175
if(logger.shouldLog(SessionLog.INFO)) {
72-
logger.log(SessionLog.INFO, SessionLog.CONNECTION, "dbPlatformHelper_defaultingPlatform", vendorName, DEFAULTPLATFORM); // NOI18N
76+
logger.log(SessionLog.INFO, SessionLog.CONNECTION, "dbPlatformHelper_defaultingPlatform", vendor, DEFAULTPLATFORM); // NOI18N
7377
}
7478
detectedDbPlatform = DEFAULTPLATFORM;
7579
}

foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/sessions/DatabaseSessionImpl.java

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 1998, 2018 IBM Corporation. All rights reserved.
3+
* Copyright (c) 1998, 2019 IBM Corporation. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -208,31 +208,25 @@ public void setDatasourceAndInitialize() throws DatabaseException {
208208
* @param throwException - set to true if the caller cares to throw exceptions, false to swallow them.
209209
*/
210210
protected void setOrDetectDatasource(boolean throwException) {
211-
String vendorNameAndVersion = null;
211+
String vendorName = null;
212+
String minorVersion = null;
213+
String majorVersion = null;
212214
String driverName = null;
213215

214216
// Try to set the platform from JPA 2.1 schema properties first before
215217
// attempting a detection.
216218
if (getProperties().containsKey(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME)) {
217-
vendorNameAndVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME);
218-
219-
String majorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MAJOR_VERSION);
220-
if (majorVersion != null) {
221-
vendorNameAndVersion += majorVersion;
222-
}
223-
224-
// The minorVersion is not currently used in platform matching, but
225-
// shouldn't change matching when added
226-
String minorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MINOR_VERSION);
227-
if (minorVersion != null) {
228-
vendorNameAndVersion += minorVersion;
229-
}
219+
vendorName = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME);
220+
minorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MINOR_VERSION);
221+
majorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MAJOR_VERSION);
230222
} else {
231223
Connection conn = null;
232224
try {
233225
conn = (Connection) getReadLogin().connectToDatasource(null, this);
234226
DatabaseMetaData dmd = conn.getMetaData();
235-
vendorNameAndVersion = dmd.getDatabaseProductName() + dmd.getDatabaseMajorVersion() + dmd.getDatabaseProductVersion();
227+
vendorName = dmd.getDatabaseProductName();
228+
minorVersion = dmd.getDatabaseProductVersion();
229+
majorVersion = Integer.toString(dmd.getDatabaseMajorVersion());
236230
driverName = conn.getMetaData().getDriverName();
237231
} catch (SQLException ex) {
238232
if (throwException) {
@@ -268,15 +262,15 @@ protected void setOrDetectDatasource(boolean throwException) {
268262
// null out the cached platform because the platform on the login
269263
// will be changed by the following line of code
270264
this.platform = null;
271-
platformName = DBPlatformHelper.getDBPlatform(vendorNameAndVersion, getSessionLog());
265+
platformName = DBPlatformHelper.getDBPlatform(vendorName, minorVersion, majorVersion, getSessionLog());
272266
getLogin().setPlatformClassName(platformName);
273267
} catch (EclipseLinkException classNotFound) {
274268
if (platformName != null && platformName.indexOf("Oracle") != -1) {
275269
try {
276270
// If we are running against Oracle, it is possible that we are
277271
// running in an environment where the extension OracleXPlatform classes can
278272
// not be loaded. Try using the core OracleXPlatform classes
279-
platformName = DBPlatformHelper.getDBPlatform("core."+ vendorNameAndVersion, getSessionLog());
273+
platformName = DBPlatformHelper.getDBPlatform("core."+ vendorName, minorVersion, majorVersion, getSessionLog());
280274
getLogin().setPlatformClassName(platformName);
281275
} catch (EclipseLinkException oracleClassNotFound) {
282276
// If we still cannot classload a matching OracleXPlatform class,

jpa/eclipselink.jpa.test.jse/src/org/eclipse/persistence/jpa/test/ddl/TestDBPlatformHelper.java

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2015 IBM Corporation. All rights reserved.
2+
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2015, 2019 IBM Corporation. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
66
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -26,8 +26,6 @@
2626
import org.eclipse.persistence.jpa.test.framework.Emf;
2727
import org.eclipse.persistence.jpa.test.framework.EmfRunner;
2828
import org.eclipse.persistence.logging.DefaultSessionLog;
29-
import org.eclipse.persistence.platform.database.DB2MainframePlatform;
30-
import org.eclipse.persistence.platform.database.DB2ZPlatform;
3129
import org.eclipse.persistence.platform.database.DatabasePlatform;
3230
import org.eclipse.persistence.sessions.DatabaseSession;
3331
import org.junit.Assert;
@@ -51,19 +49,49 @@ public void test() {
5149
@Test
5250
public void testDB2ZOS() {
5351
//Returned from jcc driver
54-
Assert.assertEquals(DB2ZPlatform.class.getName(), getPlatformClass("DB2", "DSN10015"));
52+
Assert.assertEquals(org.eclipse.persistence.platform.database.DB2ZPlatform.class.getName(), getPlatformClass("DB2", "10", "DSN10015"));
5553
}
5654

5755
@Test
5856
public void testDB2I() {
5957
//Returned from jcc driver (DRDA)
60-
Assert.assertEquals(DB2MainframePlatform.class.getName(), getPlatformClass("AS", "QSQ07020"));
58+
Assert.assertEquals(org.eclipse.persistence.platform.database.DB2MainframePlatform.class.getName(), getPlatformClass("AS", "10", "QSQ07020"));
6159

6260
//Returned from type 2 native driver & type 4 open source driver (non-DRDA)
63-
Assert.assertEquals(DB2MainframePlatform.class.getName(), getPlatformClass("DB2 UDB for AS/400", "07.02.0000 V7R2m0"));
61+
Assert.assertEquals(org.eclipse.persistence.platform.database.DB2MainframePlatform.class.getName(), getPlatformClass("DB2 UDB for AS/400", "07.02.0000", "V7R2m0"));
6462
}
6563

66-
private String getPlatformClass(String productName, String productVersion){
67-
return DBPlatformHelper.getDBPlatform(productName + productVersion, log);
64+
@Test
65+
public void testMySQL() {
66+
//Returned from jcc driver (DRDA)
67+
Assert.assertEquals(org.eclipse.persistence.platform.database.MySQLPlatform.class.getName(), getPlatformClass("MySQL", "5", "5.5.5-10.1.33-MariaDB"));
68+
}
69+
70+
@Test
71+
public void testDerby() {
72+
//Returned from jcc driver (DRDA)
73+
Assert.assertEquals(org.eclipse.persistence.platform.database.JavaDBPlatform.class.getName(), getPlatformClass("Apache Derby", "10", "10.12.1.1 - (1704137)"));
74+
}
75+
76+
@Test
77+
public void testOracle() {
78+
//Returned from jcc driver (DRDA)
79+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.OraclePlatform", getPlatformClass("Oracle", "7", "Oracle Database 7c"));
80+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.OraclePlatform", getPlatformClass("Oracle", "8", "Oracle Database 8c"));
81+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.Oracle9Platform", getPlatformClass("Oracle", "9", "Oracle Database 9c"));
82+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.Oracle10Platform", getPlatformClass("Oracle", "10", "Oracle Database 10c"));
83+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.Oracle11Platform", getPlatformClass("Oracle", "11", "Oracle Database 11c"));
84+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.Oracle12Platform", getPlatformClass("Oracle", "12", "Oracle Database 12c"));
85+
Assert.assertEquals("org.eclipse.persistence.platform.database.oracle.Oracle18Platform", getPlatformClass("Oracle", "18", "Oracle Database 18c"));
86+
}
87+
88+
@Test
89+
public void testHanaDB() {
90+
//Returned from jcc driver (DRDA)
91+
Assert.assertEquals(org.eclipse.persistence.platform.database.HANAPlatform.class.getName(), getPlatformClass("HDB", "2", "2.00.040.00.1553674765"));
92+
}
93+
94+
private String getPlatformClass(String productName, String minorVersion, String majorVersion){
95+
return DBPlatformHelper.getDBPlatform(productName, minorVersion, majorVersion, log);
6896
}
6997
}

0 commit comments

Comments
 (0)