Skip to content

Commit

Permalink
CAY-2834 v11 upgrade handler should update XMLPoolingDataSourceFactor…
Browse files Browse the repository at this point in the history
…y package
  • Loading branch information
stariy95 committed Dec 25, 2023
1 parent ec23486 commit 3405e7f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ CAY-2828 Rename values in `org.apache.cayenne.configuration.Constants`
CAY-2829 Merge `BaseContext` with `DataContext` and deprecate it
CAY-2830 Cleanup `DataContext` code
CAY-2831 Upgrade Gradle to 8.5
CAY-2834 v11 upgrade handler should update XMLPoolingDataSourceFactory package

Bug Fixes:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public String getVersion() {
@Override
public void processProjectDom(UpgradeUnit upgradeUnit) {
updateDomainSchemaAndVersion(upgradeUnit);
updateDataNodeConnectionPool(upgradeUnit);
}

@Override
Expand Down Expand Up @@ -167,6 +168,25 @@ private void updateCgenConfig(UpgradeUnit upgradeUnit) {
updateTemplates(upgradeUnit);
}

private void updateDataNodeConnectionPool(UpgradeUnit upgradeUnit) {
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes;
try {
nodes = (NodeList) xpath.evaluate("/domain/node",
upgradeUnit.getDocument(), XPathConstants.NODESET);
} catch (Exception e) {
return;
}

for (int j = 0; j < nodes.getLength(); j++) {
Element propertyElement = (Element) nodes.item(j);
String factory = propertyElement.getAttribute("factory");
if("org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory".equals(factory)) {
propertyElement.setAttribute("factory", "org.apache.cayenne.configuration.runtime.XMLPoolingDataSourceFactory");
}
}
}

private void renameQueryTemplates(UpgradeUnit upgradeUnit) {
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList queryTemplates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public void testProjectDomUpgrade() throws Exception {
assertEquals("11", root.getAttribute("project-version"));
assertEquals("http://cayenne.apache.org/schema/11/domain", root.getAttribute("xmlns"));
assertEquals(2, root.getElementsByTagName("map").getLength());

NodeList nodes = document.getElementsByTagName("node");
assertEquals(1, nodes.getLength());

Element node = (Element)nodes.item(0);
assertEquals("org.apache.cayenne.configuration.runtime.XMLPoolingDataSourceFactory", node.getAttribute("factory"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<map name="testProjectMap1_2" />

<node name="testProjectNode1"
adapter="org.example.test.Adapter" factory="org.example.test.DataSourceFactory">
adapter="org.example.test.Adapter"
factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory">
<data-source>
<connectionPool min="1" max="1" />
<login />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
*
* @since 3.1
*/
// TODO: this factory does not read XML anymore, should we rename it to
// something else?
// TODO: this factory does not read XML anymore, should we rename it to something else?
public class XMLPoolingDataSourceFactory implements DataSourceFactory {

private static final Logger logger = LoggerFactory.getLogger(XMLPoolingDataSourceFactory.class);
Expand Down

0 comments on commit 3405e7f

Please sign in to comment.