Skip to content

Commit a6f18af

Browse files
authored
Merge pull request #32769 from tjwatson/jdbcOverridde
check override library for jdbc and jsp
2 parents 7965ba4 + 0eeed5e commit a6f18af

File tree

13 files changed

+110
-12
lines changed

13 files changed

+110
-12
lines changed

dev/com.ibm.ws.jdbc/bnd.bnd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ instrument.disabled: true
127127
com.ibm.ws.container.service;version=latest,\
128128
com.ibm.ws.javaee.dd.common;version=latest,\
129129
com.ibm.ws.serialization;version=latest, \
130-
com.ibm.ws.org.osgi.annotation.versioning;version=latest
130+
com.ibm.ws.org.osgi.annotation.versioning;version=latest, \
131+
com.ibm.ws.kernel.boot.core;version=latest
131132

132133
-testpath: \
133134
../build.sharedResources/lib/junit/old/junit.jar;version=file, \

dev/com.ibm.ws.jdbc/src/com/ibm/ws/jdbc/DataSourceResourceFactoryBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.ibm.ws.jdbc.internal.JDBCDriverService;
5555
import com.ibm.ws.jdbc.internal.JDBCDrivers;
5656
import com.ibm.ws.jdbc.internal.PropertyService;
57+
import com.ibm.ws.kernel.productinfo.ProductInfo;
5758
import com.ibm.ws.resource.ResourceFactory;
5859
import com.ibm.ws.resource.ResourceFactoryBuilder;
5960
import com.ibm.ws.rsadapter.AdapterUtil;
@@ -487,6 +488,11 @@ private final String updateWithLibraries(BundleContext bundleContext,
487488

488489
// Do not check for privateLibraryRef for java:global data source definitions, applicationName is null when java:global is used
489490
if (applicationName != null) {
491+
Object overrideLibraryRef = ProductInfo.getBetaEdition() ? classloaderProps.get("overrideLibraryRef") : null;
492+
if (overrideLibraryRef != null && overrideLibraryRef instanceof String[])
493+
for (String pid : (String[]) overrideLibraryRef)
494+
libraryFilter.append(FilterUtils.createPropertyFilter(Constants.SERVICE_PID, pid));
495+
490496
Object privateLibraryRef = classloaderProps.get("privateLibraryRef");
491497
if (privateLibraryRef != null && privateLibraryRef instanceof String[])
492498
for (String pid : (String[]) privateLibraryRef)

dev/com.ibm.ws.jdbc_fat/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<classpathentry kind="src" path="test-applications/dsdfat/src"/>
1111
<classpathentry kind="src" path="test-applications/setupfat/src"/>
1212
<classpathentry kind="src" path="test-applications/dsdfat_global_lib/src"/>
13+
<classpathentry kind="src" path="test-applications/dsdfat_override_lib/src"/>
1314
<classpathentry kind="src" path="test-resource/loginmodule/src"/>
1415
<classpathentry exported="true" kind="con" path="aQute.bnd.classpath.container"/>
1516
<classpathentry kind="output" path="bin"/>

dev/com.ibm.ws.jdbc_fat/bnd.bnd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ src: \
2020
test-applications/basicfat/src,\
2121
test-applications/dsdfat/src,\
2222
test-applications/setupfat/src,\
23-
test-applications/dsdfat_global_lib/src
23+
test-applications/dsdfat_global_lib/src,\
24+
test-applications/dsdfat_override_lib/src
2425

2526
fat.project: true
2627
tested.features: databaseRotation

dev/com.ibm.ws.jdbc_fat/fat/src/com/ibm/ws/jdbc/fat/tests/ConfigTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2024 IBM Corporation and others.
2+
* Copyright (c) 2019, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -78,6 +78,7 @@ public class ConfigTest extends FATServletClient {
7878
private static final String jdbcapp = "jdbcapp";
7979
private static final String dsdfat = "dsdfat";
8080
private static final String dsdfat_global_lib = "dsdfat_global_lib";
81+
private static final String dsdfat_override_lib = "dsdfat_override_lib";
8182

8283
//Server used for ConfigTest.java and DataSourceTest.java
8384
@Server("com.ibm.ws.jdbc.fat")
@@ -158,6 +159,7 @@ public static void setUp() throws Exception {
158159
// Default app - dsdfat.war and dsdfat_global_lib.war
159160
ShrinkHelper.defaultApp(server, dsdfat, dsdfat);
160161
ShrinkHelper.defaultApp(server, dsdfat_global_lib, dsdfat_global_lib);
162+
ShrinkHelper.defaultApp(server, dsdfat_override_lib, dsdfat_override_lib);
161163

162164
// Default app - jdbcapp.ear [basicfat.war, application.xml]
163165
WebArchive basicfatWAR = ShrinkHelper.buildDefaultApp(basicfat, basicfat);

dev/com.ibm.ws.jdbc_fat/fat/src/com/ibm/ws/jdbc/fat/tests/DataSourceTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019, 2023 IBM Corporation and others.
2+
* Copyright (c) 2019, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -57,6 +57,7 @@ public class DataSourceTest extends FATServletClient {
5757
private static final String basicfat = "basicfat";
5858
private static final String dsdfat = "dsdfat";
5959
private static final String dsdfat_global_lib = "dsdfat_global_lib";
60+
private static final String dsdfat_override_lib = "dsdfat_override_lib";
6061

6162
@ClassRule
6263
public static final JdbcDatabaseContainer<?> testContainer = DatabaseContainerFactory.create();
@@ -88,9 +89,10 @@ public static void setUp() throws Exception {
8889
// Dropin app - setupfat.war
8990
ShrinkHelper.defaultDropinApp(server, setupfat, "setupfat");
9091

91-
// Default app - dsdfat.war and dsdfat_global_lib.war
92+
// Default app - dsdfat.war, dsdfat_global_lib.war and dsdfat_override_lib.war
9293
ShrinkHelper.defaultApp(server, dsdfat, dsdfat);
9394
ShrinkHelper.defaultApp(server, dsdfat_global_lib, dsdfat_global_lib);
95+
ShrinkHelper.defaultApp(server, dsdfat_override_lib, dsdfat_override_lib);
9496

9597
// Default app - jdbcapp.ear [basicfat.war, application.xml]
9698
WebArchive basicfatWAR = ShrinkHelper.buildDefaultApp(basicfat, basicfat);
@@ -358,6 +360,12 @@ public void testDataSourceDefGlobalLib() throws Exception {
358360
runTest(server, dsdfat_global_lib, testName);
359361
}
360362

363+
@Test
364+
@OnlyIfDataSourceProperties(DERBY_EMBEDDED)
365+
public void testDataSourceDefOverrideLib() throws Exception {
366+
runTest(server, dsdfat_override_lib, testName);
367+
}
368+
361369
/**
362370
* Test for PI23168 - two data sources with nested libraries with no IDs.
363371
*/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Dcom.ibm.ws.beta.edition=true

dev/com.ibm.ws.jdbc_fat/publish/servers/com.ibm.ws.jdbc.fat/server.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (c) 2019, 2021 IBM Corporation and others.
2+
Copyright (c) 2025 IBM Corporation and others.
33
All rights reserved. This program and the accompanying materials
44
are made available under the terms of the Eclipse Public License 2.0
55
which accompanies this distribution, and is available at
@@ -247,6 +247,10 @@
247247
-->
248248
</application>
249249

250+
<application type="war" id="dsdfat_override_lib" location="dsdfat_override_lib.war">
251+
<classloader overrideLibraryRef="DerbyLib" privateLibraryRef="empty"/>
252+
</application>
253+
<library id="empty"/>
250254
<!-- ### Permissions ### -->
251255
<!-- Note that until using a nested <file> works the following ACEs will be thrown: createClassLoader,
252256
java.util.PropertyPermission, javax.management.MBeanPermission -->

dev/com.ibm.ws.jdbc_fat/test-applications/dsdfat_global_lib/src/dsdfat_global_lib/DSDGlobalLibTestServlet.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 IBM Corporation and others.
2+
* Copyright (c) 2019, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-2.0/
7-
*
7+
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
1010
* Contributors:
1111
* IBM Corporation - initial API and implementation
1212
*******************************************************************************/
1313
package dsdfat_global_lib;
1414

15+
import java.sql.Connection;
16+
1517
import javax.annotation.Resource;
1618
import javax.annotation.sql.DataSourceDefinition;
1719
import javax.sql.DataSource;
@@ -32,7 +34,9 @@ public class DSDGlobalLibTestServlet extends FATServlet {
3234
DataSource xmlDS;
3335

3436
public void testDataSourceDefGlobalLib() throws Exception {
35-
annoDS.getConnection().close();
36-
xmlDS.getConnection().close();
37+
try (Connection con = annoDS.getConnection()) {
38+
}
39+
try (Connection con = xmlDS.getConnection()) {
40+
}
3741
}
3842
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0"
3+
xmlns="http://java.sun.com/xml/ns/javaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_3_0.xsd"
6+
id="WebApp_ID">
7+
8+
<servlet id="Default">
9+
<servlet-class>dsdfat_override_lib.DSDOverrideLibTestServlet</servlet-class>
10+
<load-on-startup></load-on-startup>
11+
</servlet>
12+
13+
<servlet-mapping id="ServletMapping_Default">
14+
<url-pattern>/*</url-pattern>
15+
</servlet-mapping>
16+
17+
<data-source>
18+
<name>java:app/jdbc/xmlDSOverride</name>
19+
<class-name>org.apache.derby.jdbc.EmbeddedXADataSource40</class-name>
20+
<database-name>memory:dsdfat_override_lib</database-name>
21+
<property><name>createDatabase</name><value>create</value></property>
22+
</data-source>
23+
</web-app>

0 commit comments

Comments
 (0)