Skip to content

Commit

Permalink
CAY-2870 Modeler: Upgrade CayenneDataObject to GenericPersistentObject
Browse files Browse the repository at this point in the history
  • Loading branch information
stariy95 committed Aug 27, 2024
1 parent b133964 commit 6178f53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public void processDataMapDom(UpgradeUnit upgradeUnit) {

dropROPProperties(upgradeUnit);
dropObjEntityClientInfo(upgradeUnit);
upgradeGenericObjEntity(upgradeUnit);
updateCgenConfig(upgradeUnit);
updateDbImportConfig(upgradeUnit);
}
Expand Down Expand Up @@ -147,6 +148,24 @@ private void dropObjEntityClientInfo(UpgradeUnit upgradeUnit) {
}
}

private void upgradeGenericObjEntity(UpgradeUnit upgradeUnit) {
NodeList objEntityNodes;
try {
XPath xpath = XPathFactory.newInstance().newXPath();
objEntityNodes = (NodeList) xpath.evaluate("/data-map/obj-entity", upgradeUnit.getDocument(), XPathConstants.NODESET);
} catch (Exception ex) {
return;
}

for (int j = 0; j < objEntityNodes.getLength(); j++) {
Element objEntityElement = (Element) objEntityNodes.item(j);
String className = objEntityElement.getAttribute("className");
if("org.apache.cayenne.CayenneDataObject".equals(className)) {
objEntityElement.setAttribute("className", "org.apache.cayenne.GenericPersistentObject");
}
}
}

private void updateDbImportConfig(UpgradeUnit upgradeUnit) {
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void testDataMapDomUpgrade() throws Exception {
assertEquals(2, attributes.getLength());
assertEquals("Artist", attributes.getNamedItem("name").getNodeValue());
assertEquals("Artist", attributes.getNamedItem("dbEntityName").getNodeValue());
assertEquals("org.apache.cayenne.GenericPersistentObject", attributes.getNamedItem("className").getNodeValue());
assertEquals(3, objEntity.getChildNodes().getLength());
assertEquals("http://cayenne.apache.org/schema/11/info",
objEntity.getFirstChild().getNextSibling().getAttributes().getNamedItem("xmlns:info")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<db-attribute name="untitledAttr" type="CHAR" isPrimaryKey="true" isMandatory="true" length="10"/>
<db-attribute name="untitledAttr1" type="DATE"/>
</db-entity>
<obj-entity name="Artist" dbEntityName="Artist" clientClassName="tmp.Artist" clientSuperClassName="tmp.ClientSuperClass" serverOnly="false">
<obj-entity name="Artist" dbEntityName="Artist" className="org.apache.cayenne.CayenneDataObject" clientClassName="tmp.Artist" clientSuperClassName="tmp.ClientSuperClass" serverOnly="false">
<info:property xmlns:info="http://cayenne.apache.org/schema/10/info" name="comment" value="test"/>
</obj-entity>
<cgen xmlns="http://cayenne.apache.org/schema/10/cgen">
Expand Down

0 comments on commit 6178f53

Please sign in to comment.