You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2026/10/04 19:55:22 UTC
(cayenne) branch master updated (760543bd26 -> 176a7594b0)
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
from 760543bd26 removing unused API
new f212b835c8 XML loader to ignore tags from prior versions
new a618de44f0 missing attribute in v14 schema
new bfef44a04a XML loaders cleanup
new 176a7594b0 cleanup
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../cayenne/crypto/map/CryptoDataMapLoader.java | 4 +-
.../org/apache/cayenne/project/DataMapLoader.java | 2 +-
.../org/apache/cayenne/project/ProjectLoader.java | 7 +-
.../project/upgrade/ProjectFileUpgrader.java | 30 +++++-
.../cayenne/project/upgrade/UpgradeContext.java | 28 +++++
.../apache/cayenne/project/xml/DataMapHandler.java | 40 ++++---
.../cayenne/project/xml/DbEntityHandler.java | 58 +++++------
.../cayenne/project/xml/DbKeyGeneratorHandler.java | 34 ++----
.../cayenne/project/xml/DbRelationshipHandler.java | 24 ++---
.../project/xml/EmbeddableAttributeHandler.java | 20 ++--
.../cayenne/project/xml/EmbeddableHandler.java | 20 ++--
.../cayenne/project/xml/ObjEntityHandler.java | 115 ++++++++-------------
.../project/xml/ObjRelationshipHandler.java | 33 +-----
.../cayenne/project/xml/ProcedureHandler.java | 23 ++---
.../project/xml/ProjectChildrenHandler.java | 38 +++----
.../apache/cayenne/project/xml/ProjectHandler.java | 13 ++-
.../project/xml/QueryDescriptorHandler.java | 96 +++++++----------
.../cayenne/project/xml/RootDataMapHandler.java | 23 ++++-
.../cayenne/project/xml/XMLDataMapLoader.java | 60 ++---------
.../cayenne/project/xml/XMLProjectLoader.java | 54 ++--------
.../org/apache/cayenne/schema/14/dataMap.xsd | 1 +
.../cayenne/project/xml/XMLDataMapLoaderTest.java | 16 +++
...tConfigMap2.map.xml => testConfigMap11.map.xml} | 4 +-
...tConfigMap2.map.xml => testConfigMap12.map.xml} | 5 +-
24 files changed, 330 insertions(+), 418 deletions(-)
copy cayenne/src/test/resources/org/apache/cayenne/project/xml/{testConfigMap2.map.xml => testConfigMap11.map.xml} (89%)
copy cayenne/src/test/resources/org/apache/cayenne/project/xml/{testConfigMap2.map.xml => testConfigMap12.map.xml} (88%)
(cayenne) 01/04: XML loader to ignore tags from prior versions
Posted by aa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit f212b835c88a1cfab85ffcc4e95212847fe167be
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sun Oct 4 15:17:13 2026 -0400
XML loader to ignore tags from prior versions
---
.../cayenne/project/xml/DbEntityHandler.java | 6 ------
.../cayenne/project/xml/ObjEntityHandler.java | 9 ++------
.../project/xml/ObjRelationshipHandler.java | 24 ----------------------
.../project/xml/QueryDescriptorHandler.java | 8 +-------
4 files changed, 3 insertions(+), 44 deletions(-)
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
index 57a3a0d99e..7bccec708e 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
@@ -112,12 +112,6 @@ public class DbEntityHandler extends NamespaceAwareNestedTagHandler {
lastAttribute.setAttributePrecision(Integer.parseInt(precision));
}
- // this is an obsolete 1.2 'precision' attribute that really meant 'scale'
- String pseudoPrecision = attributes.getValue("precision");
- if (pseudoPrecision != null) {
- lastAttribute.setScale(Integer.parseInt(pseudoPrecision));
- }
-
String scale = attributes.getValue("scale");
if (scale != null) {
lastAttribute.setScale(Integer.parseInt(scale));
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
index 4804e16e8d..2a583672e1 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
@@ -127,7 +127,7 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
entity.setClassName(attributes.getValue("className"));
entity.setAbstract(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("abstract")));
entity.setReadOnly(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("readOnly")));
- if ("optimistic".equals(attributes.getValue("", "lockType"))) {
+ if ("optimistic".equals(attributes.getValue("lockType"))) {
entity.setDeclaredLockType(ObjEntity.LOCK_TYPE_OPTIMISTIC);
}
@@ -143,16 +143,11 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
}
private void createObjAttribute(Attributes attributes) {
- String dbPath = attributes.getValue("dbAttributePath");
- if (dbPath == null) {
- dbPath = attributes.getValue("dbAttributeName");
- }
-
lastAttribute = new ObjAttribute(attributes.getValue("name"));
lastAttribute.setType(attributes.getValue("type"));
lastAttribute.setUsedForLocking(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lock")));
lastAttribute.setLazy(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lazy")));
- lastAttribute.setDbAttributePath(dbPath);
+ lastAttribute.setDbAttributePath(attributes.getValue("dbAttributePath"));
entity.addAttribute(lastAttribute);
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
index e680fa9e6c..07fbc19876 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
@@ -19,7 +19,6 @@
package org.apache.cayenne.project.xml;
-import org.apache.cayenne.exp.path.CayennePath;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DeleteRule;
import org.apache.cayenne.map.ObjEntity;
@@ -34,9 +33,6 @@ public class ObjRelationshipHandler extends NamespaceAwareNestedTagHandler {
public static final String OBJ_RELATIONSHIP_TAG = "objRelationship";
- @Deprecated
- public static final String DB_RELATIONSHIP_REF_TAG = "db-relationship-ref";
-
private DataMap map;
private ObjRelationship objRelationship;
@@ -46,37 +42,17 @@ public class ObjRelationshipHandler extends NamespaceAwareNestedTagHandler {
this.map = map;
}
- @SuppressWarnings("deprecation")
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
switch (localName) {
case OBJ_RELATIONSHIP_TAG:
addObjRelationship(attributes);
return true;
-
- case DB_RELATIONSHIP_REF_TAG:
- addDbRelationshipRef(attributes);
- return true;
}
return false;
}
- /**
- * <db-relationship-ref> tag deprecated
- */
- @Deprecated
- private void addDbRelationshipRef(Attributes attributes) throws SAXException {
- String name = attributes.getValue("name");
- if (name == null) {
- throw new SAXException("ObjRelationshipHandler::addDbRelationshipRef() - null DbRelationship name for "
- + objRelationship.getName());
- }
-
- CayennePath path = objRelationship.getDbRelationshipPath();
- objRelationship.setDbRelationshipPath(path.dot(name));
- }
-
private void addObjRelationship(Attributes attributes) throws SAXException {
String name = attributes.getValue("name");
if (null == name) {
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
index f4f3a74627..95702fcf95 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
@@ -50,7 +50,6 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
private QueryDescriptorLoader queryBuilder;
private QueryDescriptor descriptor;
- private boolean changed;
private String sqlKey;
private int semantics;
@@ -101,7 +100,6 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
case QUERY_QL_TAG:
queryBuilder.setSelect(data);
- changed = true;
break;
case QUERY_PREFETCH_TAG:
@@ -110,7 +108,6 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
case QUERY_CACHE_GROUP_TAG:
queryBuilder.setCacheGroup(data);
- changed = true;
break;
}
return true;
@@ -157,8 +154,6 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
queryBuilder.setFetchOffset(intAttribute(attributes, "fetchOffset"));
queryBuilder.setPageSize(intAttribute(attributes, "pageSize"));
queryBuilder.setStatementFetchSize(intAttribute(attributes, "statementFetchSize"));
-
- changed = true;
}
private int intAttribute(Attributes attributes, String name) {
@@ -178,9 +173,8 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
if(queryBuilder == null) {
return null;
}
- if(descriptor == null || changed) {
+ if(descriptor == null) {
descriptor = queryBuilder.buildQueryDescriptor();
- changed = false;
}
return descriptor;
}
(cayenne) 02/04: missing attribute in v14 schema
Posted by aa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit a618de44f05108d61d9bbf01868d6531ef7b3b35
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sun Oct 4 15:18:45 2026 -0400
missing attribute in v14 schema
---
cayenne/src/main/resources/org/apache/cayenne/schema/14/dataMap.xsd | 1 +
1 file changed, 1 insertion(+)
diff --git a/cayenne/src/main/resources/org/apache/cayenne/schema/14/dataMap.xsd b/cayenne/src/main/resources/org/apache/cayenne/schema/14/dataMap.xsd
index 76232f4df5..5e7bd2b757 100644
--- a/cayenne/src/main/resources/org/apache/cayenne/schema/14/dataMap.xsd
+++ b/cayenne/src/main/resources/org/apache/cayenne/schema/14/dataMap.xsd
@@ -115,6 +115,7 @@
<xs:attribute name="length" type="xs:integer"/>
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="scale" type="xs:integer"/>
+ <xs:attribute name="attributePrecision" type="xs:integer"/>
<xs:attribute name="type" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
(cayenne) 03/04: XML loaders cleanup
Posted by aa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit bfef44a04a0b212e2627891e380e6d39543433e6
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sun Oct 4 15:29:48 2026 -0400
XML loaders cleanup
---
.../project/upgrade/ProjectFileUpgrader.java | 30 +++++-
.../cayenne/project/upgrade/UpgradeContext.java | 28 ++++++
.../apache/cayenne/project/xml/DataMapHandler.java | 40 ++++----
.../cayenne/project/xml/DbEntityHandler.java | 52 +++++-----
.../cayenne/project/xml/DbKeyGeneratorHandler.java | 34 +++----
.../cayenne/project/xml/DbRelationshipHandler.java | 24 ++---
.../project/xml/EmbeddableAttributeHandler.java | 20 ++--
.../cayenne/project/xml/EmbeddableHandler.java | 20 ++--
.../cayenne/project/xml/ObjEntityHandler.java | 106 ++++++++-------------
.../project/xml/ObjRelationshipHandler.java | 9 +-
.../cayenne/project/xml/ProcedureHandler.java | 23 +++--
.../project/xml/ProjectChildrenHandler.java | 38 ++++----
.../apache/cayenne/project/xml/ProjectHandler.java | 13 ++-
.../project/xml/QueryDescriptorHandler.java | 88 +++++++----------
.../cayenne/project/xml/RootDataMapHandler.java | 23 ++++-
.../cayenne/project/xml/XMLDataMapLoader.java | 54 ++---------
.../cayenne/project/xml/XMLProjectLoader.java | 44 +--------
.../cayenne/project/xml/XMLDataMapLoaderTest.java | 16 ++++
.../cayenne/project/xml/testConfigMap11.map.xml | 27 ++++++
.../cayenne/project/xml/testConfigMap12.map.xml | 28 ++++++
20 files changed, 360 insertions(+), 357 deletions(-)
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/upgrade/ProjectFileUpgrader.java b/cayenne/src/main/java/org/apache/cayenne/project/upgrade/ProjectFileUpgrader.java
index 95dc5c5844..2614605b32 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/upgrade/ProjectFileUpgrader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/upgrade/ProjectFileUpgrader.java
@@ -133,10 +133,13 @@ public class ProjectFileUpgrader {
}
/**
- * Reads the project XML and upgrades its DOM from the given version. The referenced DataMaps are not touched,
- * see {@link #upgradeDataMapDOM(Resource, String)}.
+ * Reads the project XML and upgrades its DOM from the given version. The project file is not modified. The
+ * referenced DataMaps are not touched, see {@link #upgradeDataMapDOM(Resource, String)}.
+ *
+ * @throws ConfigurationException if the version is newer than the current one, or is too old to be upgraded
*/
public UpgradeContext upgradeProjectDOM(Resource resource, String fromVersion) {
+ checkUpgradable(resource, fromVersion);
UpgradeContext context = new UpgradeContext(resource, readDocument(resource.getURL()));
for (UpgradeHandler handler : handlersForVersion(fromVersion)) {
handler.upgradeProjectDOM(context);
@@ -145,9 +148,12 @@ public class ProjectFileUpgrader {
}
/**
- * Reads the DataMap XML and upgrades its DOM from the given version.
+ * Reads the DataMap XML and upgrades its DOM from the given version. The DataMap file is not modified.
+ *
+ * @throws ConfigurationException if the version is newer than the current one, or is too old to be upgraded
*/
public UpgradeContext upgradeDataMapDOM(Resource resource, String fromVersion) {
+ checkUpgradable(resource, fromVersion);
UpgradeContext context = new UpgradeContext(resource, readDocument(resource.getURL()));
for (UpgradeHandler handler : handlersForVersion(fromVersion)) {
handler.upgradeDataMapDOM(context);
@@ -155,6 +161,24 @@ public class ProjectFileUpgrader {
return context;
}
+ private void checkUpgradable(Resource resource, String fromVersion) {
+ UpgradeType upgradeType = checkUpgradeNeeded(fromVersion);
+
+ if (upgradeType == UpgradeType.DOWNGRADE_NEEDED) {
+ throw new ConfigurationException("""
+ Unable to load configuration from %s: project version %s is newer than the supported version %s. \
+ It was created with a newer version of Cayenne""",
+ resource.getURL(), fromVersion, UpgradeHandler.CURRENT_VERSION);
+ }
+
+ if (upgradeType == UpgradeType.INTERMEDIATE_UPGRADE_NEEDED) {
+ throw new ConfigurationException("""
+ Unable to load configuration from %s: project version %s is too old to be upgraded. \
+ Open the project in an older CayenneModeler to upgrade it to version %s first""",
+ resource.getURL(), fromVersion, UpgradeHandler.MIN_SUPPORTED_VERSION);
+ }
+ }
+
private static Document readDocument(URL url) {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(false);
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/upgrade/UpgradeContext.java b/cayenne/src/main/java/org/apache/cayenne/project/upgrade/UpgradeContext.java
index 6d9d8cf435..07ed8f065d 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/upgrade/UpgradeContext.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/upgrade/UpgradeContext.java
@@ -19,7 +19,10 @@
package org.apache.cayenne.project.upgrade;
+import org.apache.cayenne.ConfigurationException;
import org.apache.cayenne.resource.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import java.util.ArrayList;
@@ -32,6 +35,8 @@ import java.util.List;
*/
public class UpgradeContext {
+ private static final Logger LOGGER = LoggerFactory.getLogger(UpgradeContext.class);
+
private final Resource resource;
private final Document document;
private final List<String> changeNotifications;
@@ -50,6 +55,29 @@ public class UpgradeContext {
return document;
}
+ /**
+ * Returns the upgraded document to be loaded in runtime as is, without saving it or involving the user.
+ *
+ * @throws ConfigurationException if the upgrade made changes that may affect runtime, and so requires the
+ * project to be upgraded in CayenneModeler
+ * @since 5.0
+ */
+ public Document getRuntimeDocument() {
+ if (!changesAffectingRuntime.isEmpty()) {
+ throw new ConfigurationException("""
+ Unable to upgrade configuration from %s in memory, as the upgrade requires manual changes. \
+ Open the project in CayenneModeler to upgrade it. %s""",
+ resource.getURL(), String.join(" ", changesAffectingRuntime));
+ }
+
+ LOGGER.warn("""
+ Configuration {} was created with an older version of Cayenne and was upgraded to project \
+ version {} in memory. Open the project in CayenneModeler to upgrade its XML permanently""",
+ resource.getURL(), UpgradeHandler.CURRENT_VERSION);
+
+ return document;
+ }
+
public Resource getResource() {
return resource;
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/DataMapHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/DataMapHandler.java
index 2a9b97a278..1398d86691 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/DataMapHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/DataMapHandler.java
@@ -21,6 +21,7 @@ package org.apache.cayenne.project.xml;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.resource.Resource;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -30,29 +31,23 @@ import org.xml.sax.SAXException;
*/
public class DataMapHandler extends NamespaceAwareNestedTagHandler {
- /* This constants must be in sync with dataMap.xsd schema */
- private static final String DATA_MAP_TAG = "dataMap";
- private static final String DB_ENTITY_TAG = "dbEntity";
- private static final String OBJ_ENTITY_TAG = "objEntity";
- private static final String DB_RELATIONSHIP_TAG = "dbRelationship";
- private static final String OBJ_RELATIONSHIP_TAG = "objRelationship";
- private static final String EMBEDDABLE_TAG = "embeddable";
- private static final String PROCEDURE_TAG = "procedure";
- private static final String OBJECT_QUERY_TAG = "objectQuery";
- private static final String SQL_QUERY_TAG = "sqlQuery";
- private static final String PROCEDURE_QUERY_TAG = "procedureQuery";
-
- public static final String TRUE = "true";
+ static final String DATA_MAP_TAG = "dataMap";
+ private final Resource configurationSource;
private DataMap dataMap;
- public DataMapHandler(NamespaceAwareNestedTagHandler parentHandler) {
+ /**
+ * @param configurationSource the source of the DataMap being loaded, can be null
+ */
+ public DataMapHandler(NamespaceAwareNestedTagHandler parentHandler, Resource configurationSource) {
super(parentHandler);
+ this.configurationSource = configurationSource;
}
public DataMapHandler(LoaderContext loaderContext) {
super(loaderContext);
setTargetNamespace(DataMap.SCHEMA_XSD);
+ this.configurationSource = null;
}
@Override
@@ -61,6 +56,7 @@ public class DataMapHandler extends NamespaceAwareNestedTagHandler {
return switch (localName) {
case DATA_MAP_TAG -> {
this.dataMap = new DataMap();
+ dataMap.setConfigurationSource(configurationSource);
dataMap.setDefaultLockType("optimistic".equals(attributes.getValue("defaultLockType"))
? ObjEntity.LOCK_TYPE_OPTIMISTIC
: ObjEntity.LOCK_TYPE_NONE);
@@ -81,13 +77,15 @@ public class DataMapHandler extends NamespaceAwareNestedTagHandler {
if (namespaceURI.equals(targetNamespace)) {
return switch (localName) {
- case DB_ENTITY_TAG -> new DbEntityHandler(this, dataMap);
- case OBJ_ENTITY_TAG -> new ObjEntityHandler(this, dataMap);
- case DB_RELATIONSHIP_TAG -> new DbRelationshipHandler(this, dataMap);
- case OBJ_RELATIONSHIP_TAG -> new ObjRelationshipHandler(this, dataMap);
- case PROCEDURE_TAG -> new ProcedureHandler(this, dataMap);
- case OBJECT_QUERY_TAG, SQL_QUERY_TAG, PROCEDURE_QUERY_TAG -> new QueryDescriptorHandler(this, dataMap);
- case EMBEDDABLE_TAG -> new EmbeddableHandler(this, dataMap);
+ case DbEntityHandler.DB_ENTITY_TAG -> new DbEntityHandler(this, dataMap);
+ case ObjEntityHandler.OBJ_ENTITY_TAG -> new ObjEntityHandler(this, dataMap);
+ case DbRelationshipHandler.DB_RELATIONSHIP_TAG -> new DbRelationshipHandler(this, dataMap);
+ case ObjRelationshipHandler.OBJ_RELATIONSHIP_TAG -> new ObjRelationshipHandler(this, dataMap);
+ case ProcedureHandler.PROCEDURE_TAG -> new ProcedureHandler(this, dataMap);
+ case QueryDescriptorHandler.OBJECT_QUERY_TAG,
+ QueryDescriptorHandler.SQL_QUERY_TAG,
+ QueryDescriptorHandler.PROCEDURE_QUERY_TAG -> new QueryDescriptorHandler(this, dataMap);
+ case EmbeddableHandler.EMBEDDABLE_TAG -> new EmbeddableHandler(this, dataMap);
default -> super.createChildTagHandler(namespaceURI, localName, qName, attributes);
};
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
index 7bccec708e..fb6168d1af 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbEntityHandler.java
@@ -19,7 +19,9 @@
package org.apache.cayenne.project.xml;
+import org.apache.cayenne.ConfigurationException;
import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.exp.ExpressionException;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbAttribute;
@@ -35,9 +37,8 @@ import static org.apache.cayenne.util.Util.isBlank;
*/
public class DbEntityHandler extends NamespaceAwareNestedTagHandler {
- private static final String DB_ENTITY_TAG = "dbEntity";
+ static final String DB_ENTITY_TAG = "dbEntity";
private static final String DB_ATTRIBUTE_TAG = "dbAttribute";
- private static final String DB_KEY_GENERATOR_TAG = "dbKeyGenerator";
private static final String QUALIFIER_TAG = "qualifier";
private DataMap dataMap;
@@ -51,37 +52,32 @@ public class DbEntityHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case DB_ENTITY_TAG:
+ return switch (localName) {
+ case DB_ENTITY_TAG -> {
createDbEntity(attributes);
- return true;
-
- case DB_ATTRIBUTE_TAG:
+ yield true;
+ }
+ case DB_ATTRIBUTE_TAG -> {
createDbAttribute(attributes);
- return true;
-
- case QUALIFIER_TAG:
- return true;
- }
-
- return false;
+ yield true;
+ }
+ case QUALIFIER_TAG -> true;
+ default -> false;
+ };
}
@Override
protected boolean processCharData(String localName, String data) {
- switch (localName) {
- case QUALIFIER_TAG:
- createQualifier(data);
- break;
+ if (QUALIFIER_TAG.equals(localName)) {
+ createQualifier(data);
}
return true;
}
@Override
protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName, Attributes attributes) {
- switch (localName) {
- case DB_KEY_GENERATOR_TAG:
- return new DbKeyGeneratorHandler(this, entity);
+ if (DbKeyGeneratorHandler.DB_KEY_GENERATOR_TAG.equals(localName)) {
+ return new DbKeyGeneratorHandler(this, entity);
}
return super.createChildTagHandler(namespaceURI, localName, qName, attributes);
}
@@ -117,9 +113,9 @@ public class DbEntityHandler extends NamespaceAwareNestedTagHandler {
lastAttribute.setScale(Integer.parseInt(scale));
}
- lastAttribute.setPrimaryKey(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("primaryKey")));
- lastAttribute.setMandatory(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("mandatory")));
- lastAttribute.setGenerated(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("generated")));
+ lastAttribute.setPrimaryKey("true".equals(attributes.getValue("primaryKey")));
+ lastAttribute.setMandatory("true".equals(attributes.getValue("mandatory")));
+ lastAttribute.setGenerated("true".equals(attributes.getValue("generated")));
}
private void createQualifier(String qualifier) {
@@ -127,9 +123,13 @@ public class DbEntityHandler extends NamespaceAwareNestedTagHandler {
return;
}
- // qualifier can belong to ObjEntity, DbEntity or a query
if (entity != null) {
- entity.setQualifier(ExpressionFactory.exp(qualifier));
+ try {
+ entity.setQualifier(ExpressionFactory.exp(qualifier));
+ } catch (ExpressionException ex) {
+ throw new ConfigurationException("Invalid qualifier of DbEntity '%s': %s", ex, entity.getName(),
+ qualifier);
+ }
}
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbKeyGeneratorHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbKeyGeneratorHandler.java
index e41553b0e4..a0ce5cbb9f 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbKeyGeneratorHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbKeyGeneratorHandler.java
@@ -29,7 +29,7 @@ import org.xml.sax.SAXException;
*/
public class DbKeyGeneratorHandler extends NamespaceAwareNestedTagHandler {
- private static final String DB_KEY_GENERATOR_TAG = "dbKeyGenerator";
+ static final String DB_KEY_GENERATOR_TAG = "dbKeyGenerator";
private static final String DB_GENERATOR_TYPE_TAG = "dbGeneratorType";
private static final String DB_GENERATOR_NAME_TAG = "dbGeneratorName";
private static final String DB_KEY_CACHE_SIZE_TAG = "dbKeyCacheSize";
@@ -43,34 +43,22 @@ public class DbKeyGeneratorHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case DB_KEY_GENERATOR_TAG:
+ return switch (localName) {
+ case DB_KEY_GENERATOR_TAG -> {
createDbKeyGenerator();
- return true;
-
- case DB_GENERATOR_NAME_TAG:
- case DB_GENERATOR_TYPE_TAG:
- case DB_KEY_CACHE_SIZE_TAG:
- return true;
- }
-
- return false;
+ yield true;
+ }
+ case DB_GENERATOR_NAME_TAG, DB_GENERATOR_TYPE_TAG, DB_KEY_CACHE_SIZE_TAG -> true;
+ default -> false;
+ };
}
@Override
protected boolean processCharData(String localName, String data) {
switch (localName) {
- case DB_GENERATOR_TYPE_TAG:
- setDbGeneratorType(data);
- break;
-
- case DB_GENERATOR_NAME_TAG:
- setDbGeneratorName(data);
- break;
-
- case DB_KEY_CACHE_SIZE_TAG:
- setDbKeyCacheSize(data);
- break;
+ case DB_GENERATOR_TYPE_TAG -> setDbGeneratorType(data);
+ case DB_GENERATOR_NAME_TAG -> setDbGeneratorName(data);
+ case DB_KEY_CACHE_SIZE_TAG -> setDbKeyCacheSize(data);
}
return true;
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbRelationshipHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbRelationshipHandler.java
index 5227c95b5b..b5c8b12b7e 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/DbRelationshipHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/DbRelationshipHandler.java
@@ -31,7 +31,7 @@ import org.xml.sax.SAXException;
*/
public class DbRelationshipHandler extends NamespaceAwareNestedTagHandler {
- private static final String DB_RELATIONSHIP_TAG = "dbRelationship";
+ static final String DB_RELATIONSHIP_TAG = "dbRelationship";
public static final String DB_ATTRIBUTE_PAIR_TAG = "dbAttributePair";
private DataMap map;
@@ -46,17 +46,17 @@ public class DbRelationshipHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case DB_RELATIONSHIP_TAG:
+ return switch (localName) {
+ case DB_RELATIONSHIP_TAG -> {
createRelationship(attributes);
- return true;
-
- case DB_ATTRIBUTE_PAIR_TAG:
+ yield true;
+ }
+ case DB_ATTRIBUTE_PAIR_TAG -> {
createDbAttributePair(attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ default -> false;
+ };
}
private void createRelationship(Attributes attributes) throws SAXException {
@@ -78,8 +78,8 @@ public class DbRelationshipHandler extends NamespaceAwareNestedTagHandler {
dbRelationship = new DbRelationship(name);
dbRelationship.setSourceEntity(source);
dbRelationship.setTargetEntityName(attributes.getValue("target"));
- dbRelationship.setToMany(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("toMany")));
- dbRelationship.setToDependentPK(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("toDependentPK")));
+ dbRelationship.setToMany("true".equals(attributes.getValue("toMany")));
+ dbRelationship.setToDependentPK("true".equals(attributes.getValue("toDependentPK")));
source.addRelationship(dbRelationship);
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableAttributeHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableAttributeHandler.java
index 47e8671d0c..1762d75ea4 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableAttributeHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableAttributeHandler.java
@@ -29,7 +29,7 @@ import org.xml.sax.SAXException;
*/
public class EmbeddableAttributeHandler extends NamespaceAwareNestedTagHandler {
- private static final String EMBEDDED_ATTRIBUTE_TAG = "embeddedAttribute";
+ static final String EMBEDDED_ATTRIBUTE_TAG = "embeddedAttribute";
private static final String EMBEDDABLE_ATTRIBUTE_OVERRIDE_TAG = "embeddableAttributeOverride";
private ObjEntity entity;
@@ -43,17 +43,17 @@ public class EmbeddableAttributeHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case EMBEDDED_ATTRIBUTE_TAG:
+ return switch (localName) {
+ case EMBEDDED_ATTRIBUTE_TAG -> {
createEmbeddableAttribute(attributes);
- return true;
-
- case EMBEDDABLE_ATTRIBUTE_OVERRIDE_TAG:
+ yield true;
+ }
+ case EMBEDDABLE_ATTRIBUTE_OVERRIDE_TAG -> {
createEmbeddableAttributeOverride(attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ default -> false;
+ };
}
private void createEmbeddableAttribute(Attributes attributes) {
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableHandler.java
index 599f447fb6..36063fbb6a 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/EmbeddableHandler.java
@@ -30,7 +30,7 @@ import org.xml.sax.SAXException;
*/
public class EmbeddableHandler extends NamespaceAwareNestedTagHandler {
- private static final String EMBEDDABLE_TAG = "embeddable";
+ static final String EMBEDDABLE_TAG = "embeddable";
private static final String EMBEDDABLE_ATTRIBUTE_TAG = "embeddableAttribute";
private DataMap map;
@@ -44,17 +44,17 @@ public class EmbeddableHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case EMBEDDABLE_TAG:
+ return switch (localName) {
+ case EMBEDDABLE_TAG -> {
createEmbeddable(attributes);
- return true;
-
- case EMBEDDABLE_ATTRIBUTE_TAG:
+ yield true;
+ }
+ case EMBEDDABLE_ATTRIBUTE_TAG -> {
createEmbeddableAttribute(attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ default -> false;
+ };
}
private void createEmbeddable(Attributes attributes) {
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
index 2a583672e1..56827b6cdb 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjEntityHandler.java
@@ -19,14 +19,13 @@
package org.apache.cayenne.project.xml;
+import org.apache.cayenne.ConfigurationException;
import org.apache.cayenne.exp.ExpressionException;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.map.CallbackDescriptor;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.map.ObjEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -38,12 +37,9 @@ import static org.apache.cayenne.util.Util.isBlank;
*/
public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
- private static final Logger LOGGER = LoggerFactory.getLogger(ObjEntityHandler.class);
-
- private static final String OBJ_ENTITY_TAG = "objEntity";
+ static final String OBJ_ENTITY_TAG = "objEntity";
private static final String OBJ_ATTRIBUTE_TAG = "objAttribute";
private static final String OBJ_ATTRIBUTE_OVERRIDE_TAG = "attributeOverride";
- private static final String EMBEDDED_ATTRIBUTE_TAG = "embeddedAttribute";
private static final String QUALIFIER_TAG = "qualifier";
// lifecycle listeners and callbacks related
@@ -69,44 +65,34 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case OBJ_ENTITY_TAG:
+ return switch (localName) {
+ case OBJ_ENTITY_TAG -> {
createObjEntity(attributes);
- return true;
-
- case OBJ_ATTRIBUTE_TAG:
+ yield true;
+ }
+ case OBJ_ATTRIBUTE_TAG -> {
createObjAttribute(attributes);
- return true;
-
- case OBJ_ATTRIBUTE_OVERRIDE_TAG:
+ yield true;
+ }
+ case OBJ_ATTRIBUTE_OVERRIDE_TAG -> {
processStartAttributeOverride(attributes);
- return true;
-
- case QUALIFIER_TAG:
- return true;
-
- case POST_ADD_TAG:
- case PRE_PERSIST_TAG:
- case POST_PERSIST_TAG:
- case PRE_UPDATE_TAG:
- case POST_UPDATE_TAG:
- case PRE_REMOVE_TAG:
- case POST_REMOVE_TAG:
- case POST_LOAD_TAG:
+ yield true;
+ }
+ case QUALIFIER_TAG -> true;
+ case POST_ADD_TAG, PRE_PERSIST_TAG, POST_PERSIST_TAG, PRE_UPDATE_TAG, POST_UPDATE_TAG, PRE_REMOVE_TAG,
+ POST_REMOVE_TAG, POST_LOAD_TAG -> {
createCallback(localName, attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ default -> false;
+ };
}
@Override
protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName, Attributes attributes) {
- if(namespaceURI.equals(targetNamespace)) {
- switch (localName) {
- case EMBEDDED_ATTRIBUTE_TAG:
- return new EmbeddableAttributeHandler(this, entity);
- }
+ if (namespaceURI.equals(targetNamespace)
+ && EmbeddableAttributeHandler.EMBEDDED_ATTRIBUTE_TAG.equals(localName)) {
+ return new EmbeddableAttributeHandler(this, entity);
}
return super.createChildTagHandler(namespaceURI, localName, qName, attributes);
@@ -114,10 +100,8 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processCharData(String localName, String data) {
- switch (localName) {
- case QUALIFIER_TAG:
- createQualifier(data);
- break;
+ if (QUALIFIER_TAG.equals(localName)) {
+ createQualifier(data);
}
return true;
}
@@ -125,8 +109,8 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
private void createObjEntity(Attributes attributes) {
entity = new ObjEntity(attributes.getValue("name"));
entity.setClassName(attributes.getValue("className"));
- entity.setAbstract(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("abstract")));
- entity.setReadOnly(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("readOnly")));
+ entity.setAbstract("true".equals(attributes.getValue("abstract")));
+ entity.setReadOnly("true".equals(attributes.getValue("readOnly")));
if ("optimistic".equals(attributes.getValue("lockType"))) {
entity.setDeclaredLockType(ObjEntity.LOCK_TYPE_OPTIMISTIC);
}
@@ -145,8 +129,8 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
private void createObjAttribute(Attributes attributes) {
lastAttribute = new ObjAttribute(attributes.getValue("name"));
lastAttribute.setType(attributes.getValue("type"));
- lastAttribute.setUsedForLocking(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lock")));
- lastAttribute.setLazy(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lazy")));
+ lastAttribute.setUsedForLocking("true".equals(attributes.getValue("lock")));
+ lastAttribute.setLazy("true".equals(attributes.getValue("lazy")));
lastAttribute.setDbAttributePath(attributes.getValue("dbAttributePath"));
entity.addAttribute(lastAttribute);
}
@@ -161,26 +145,17 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
return null;
}
- switch (type) {
- case POST_ADD_TAG:
- return entity.getCallbackMap().getPostAdd();
- case PRE_PERSIST_TAG:
- return entity.getCallbackMap().getPrePersist();
- case POST_PERSIST_TAG:
- return entity.getCallbackMap().getPostPersist();
- case PRE_UPDATE_TAG:
- return entity.getCallbackMap().getPreUpdate();
- case POST_UPDATE_TAG:
- return entity.getCallbackMap().getPostUpdate();
- case PRE_REMOVE_TAG:
- return entity.getCallbackMap().getPreRemove();
- case POST_REMOVE_TAG:
- return entity.getCallbackMap().getPostRemove();
- case POST_LOAD_TAG:
- return entity.getCallbackMap().getPostLoad();
- }
-
- return null;
+ return switch (type) {
+ case POST_ADD_TAG -> entity.getCallbackMap().getPostAdd();
+ case PRE_PERSIST_TAG -> entity.getCallbackMap().getPrePersist();
+ case POST_PERSIST_TAG -> entity.getCallbackMap().getPostPersist();
+ case PRE_UPDATE_TAG -> entity.getCallbackMap().getPreUpdate();
+ case POST_UPDATE_TAG -> entity.getCallbackMap().getPostUpdate();
+ case PRE_REMOVE_TAG -> entity.getCallbackMap().getPreRemove();
+ case POST_REMOVE_TAG -> entity.getCallbackMap().getPostRemove();
+ case POST_LOAD_TAG -> entity.getCallbackMap().getPostLoad();
+ default -> null;
+ };
}
private void createCallback(String type, Attributes attributes) {
@@ -200,7 +175,8 @@ public class ObjEntityHandler extends NamespaceAwareNestedTagHandler {
try {
entity.setDeclaredQualifier(ExpressionFactory.exp(qualifier));
} catch (ExpressionException ex) {
- LOGGER.warn("Unable to parse entity {} qualifier", entity.getName(), ex);
+ throw new ConfigurationException("Invalid qualifier of ObjEntity '%s': %s", ex, entity.getName(),
+ qualifier);
}
}
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
index 07fbc19876..a33524f264 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ObjRelationshipHandler.java
@@ -44,10 +44,9 @@ public class ObjRelationshipHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case OBJ_RELATIONSHIP_TAG:
- addObjRelationship(attributes);
- return true;
+ if (OBJ_RELATIONSHIP_TAG.equals(localName)) {
+ addObjRelationship(attributes);
+ return true;
}
return false;
@@ -76,7 +75,7 @@ public class ObjRelationshipHandler extends NamespaceAwareNestedTagHandler {
if (deleteRule != null) {
objRelationship.setDeleteRule(DeleteRule.valueOf(deleteRule.toUpperCase()));
}
- objRelationship.setUsedForLocking(DataMapHandler.TRUE.equalsIgnoreCase(attributes.getValue("lock")));
+ objRelationship.setUsedForLocking("true".equals(attributes.getValue("lock")));
objRelationship.setDeferredDbRelationshipPath((attributes.getValue("dbRelationshipPath")));
objRelationship.setCollectionType(attributes.getValue("collectionType"));
objRelationship.setMapKey(attributes.getValue("mapKey"));
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProcedureHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProcedureHandler.java
index 84ac807364..bd51c84b80 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProcedureHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProcedureHandler.java
@@ -31,7 +31,7 @@ import org.xml.sax.SAXException;
*/
public class ProcedureHandler extends NamespaceAwareNestedTagHandler {
- private static final String PROCEDURE_TAG = "procedure";
+ static final String PROCEDURE_TAG = "procedure";
private static final String PROCEDURE_PARAMETER_TAG = "procedureParameter";
private DataMap map;
@@ -45,28 +45,27 @@ public class ProcedureHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case PROCEDURE_TAG:
+ return switch (localName) {
+ case PROCEDURE_TAG -> {
addProcedure(attributes);
- return true;
-
- case PROCEDURE_PARAMETER_TAG:
+ yield true;
+ }
+ case PROCEDURE_PARAMETER_TAG -> {
addProcedureParameter(attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ default -> false;
+ };
}
private void addProcedure(Attributes attributes) throws SAXException{
String name = attributes.getValue("name");
- String returningValue = attributes.getValue("returningValue");
if (null == name) {
throw new SAXException("ProcedureHandler::addProcedure() - no procedure name.");
}
procedure = new Procedure(name);
- procedure.setReturningValue(returningValue != null && returningValue.equalsIgnoreCase(DataMapHandler.TRUE));
+ procedure.setReturningValue("true".equals(attributes.getValue("returningValue")));
procedure.setSchema(attributes.getValue("schema"));
procedure.setCatalog(attributes.getValue("catalog"));
map.addProcedure(procedure);
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectChildrenHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectChildrenHandler.java
index 53720a56d8..8db8a372d8 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectChildrenHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectChildrenHandler.java
@@ -19,6 +19,8 @@
package org.apache.cayenne.project.xml;
+import org.apache.cayenne.project.ConfigurationNameMapper;
+import org.apache.cayenne.project.DataMapLoader;
import org.apache.cayenne.project.Project;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.resource.Resource;
@@ -34,38 +36,36 @@ final class ProjectChildrenHandler extends NamespaceAwareNestedTagHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(XMLProjectLoader.class);
- static final String OLD_MAP_TAG = "map";
- static final String DATA_MAP_TAG = "dataMap";
- static final String PROJECT_TAG = "project";
+ private static final String MAP_TAG = "map";
-
- private XMLProjectLoader xmlProjectLoader;
+ private final ConfigurationNameMapper nameMapper;
+ private final DataMapLoader dataMapLoader;
private Project project;
- ProjectChildrenHandler(XMLProjectLoader xmlProjectLoader, ProjectHandler parentHandler) {
+ ProjectChildrenHandler(ProjectHandler parentHandler, ConfigurationNameMapper nameMapper,
+ DataMapLoader dataMapLoader) {
super(parentHandler);
- this.xmlProjectLoader = xmlProjectLoader;
+ this.nameMapper = nameMapper;
+ this.dataMapLoader = dataMapLoader;
this.project = parentHandler.project;
}
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) {
- switch (localName) {
- case OLD_MAP_TAG:
+ return switch (localName) {
+ case MAP_TAG -> {
addMap(attributes);
- return true;
-
- case PROJECT_TAG:
- return true;
- }
-
- return false;
+ yield true;
+ }
+ case ProjectHandler.PROJECT_TAG -> true;
+ default -> false;
+ };
}
@Override
protected ContentHandler createChildTagHandler(String namespaceURI, String localName,
String name, Attributes attributes) {
- if (DATA_MAP_TAG.equals(localName)) {
+ if (DataMapHandler.DATA_MAP_TAG.equals(localName)) {
return new DataMapHandler(loaderContext);
}
@@ -76,13 +76,13 @@ final class ProjectChildrenHandler extends NamespaceAwareNestedTagHandler {
String dataMapName = attributes.getValue("name");
Resource baseResource = project.getConfigurationSource();
- String dataMapLocation = xmlProjectLoader.nameMapper.configurationLocation(DataMap.class, dataMapName);
+ String dataMapLocation = nameMapper.configurationLocation(DataMap.class, dataMapName);
Resource dataMapResource = baseResource.getRelativeResource(dataMapLocation);
LOGGER.info("Loading XML DataMap resource from {}", dataMapResource.getURL());
- DataMap dataMap = xmlProjectLoader.dataMapLoader.load(dataMapResource);
+ DataMap dataMap = dataMapLoader.load(dataMapResource);
dataMap.setName(dataMapName);
dataMap.setLocation(dataMapLocation);
dataMap.setProject(project);
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectHandler.java
index fcdf3c530f..58d150c344 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/ProjectHandler.java
@@ -19,6 +19,8 @@
package org.apache.cayenne.project.xml;
+import org.apache.cayenne.project.ConfigurationNameMapper;
+import org.apache.cayenne.project.DataMapLoader;
import org.apache.cayenne.project.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,12 +37,15 @@ public final class ProjectHandler extends VersionAwareHandler {
static final String PROJECT_TAG = "project";
- private XMLProjectLoader xmlProjectLoader;
+ private final ConfigurationNameMapper nameMapper;
+ private final DataMapLoader dataMapLoader;
Project project;
- public ProjectHandler(XMLProjectLoader xmlProjectLoader, Project project, LoaderContext loaderContext) {
+ public ProjectHandler(Project project, LoaderContext loaderContext, ConfigurationNameMapper nameMapper,
+ DataMapLoader dataMapLoader) {
super(loaderContext, PROJECT_TAG);
- this.xmlProjectLoader = xmlProjectLoader;
+ this.nameMapper = nameMapper;
+ this.dataMapLoader = dataMapLoader;
this.project = project;
setTargetNamespace(Project.SCHEMA_XSD);
}
@@ -66,7 +71,7 @@ public final class ProjectHandler extends VersionAwareHandler {
String name, Attributes attributes) {
if (localName.equals(PROJECT_TAG)) {
- return new ProjectChildrenHandler(xmlProjectLoader, this);
+ return new ProjectChildrenHandler(this, nameMapper, dataMapLoader);
}
LOGGER.info(unexpectedTagMessage(localName, PROJECT_TAG));
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
index 95702fcf95..6bfd1f78ad 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/QueryDescriptorHandler.java
@@ -23,6 +23,7 @@ import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.QueryDescriptor;
import org.apache.cayenne.map.QueryDescriptorLoader;
import org.apache.cayenne.query.CapsStrategy;
+import org.apache.cayenne.query.PrefetchTreeNode;
import org.apache.cayenne.query.QueryCacheStrategy;
import org.apache.cayenne.util.Util;
import org.xml.sax.Attributes;
@@ -38,9 +39,9 @@ import java.util.function.Supplier;
*/
public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
- private static final String OBJECT_QUERY_TAG = "objectQuery";
- private static final String SQL_QUERY_TAG = "sqlQuery";
- private static final String PROCEDURE_QUERY_TAG = "procedureQuery";
+ static final String OBJECT_QUERY_TAG = "objectQuery";
+ static final String SQL_QUERY_TAG = "sqlQuery";
+ static final String PROCEDURE_QUERY_TAG = "procedureQuery";
private static final String QUERY_SQL_TAG = "sql";
private static final String QUERY_QL_TAG = "ql";
private static final String QUERY_PREFETCH_TAG = "prefetch";
@@ -62,53 +63,39 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
@Override
protected boolean processElement(String namespaceURI, String localName, Attributes attributes) throws SAXException {
- switch (localName) {
- case OBJECT_QUERY_TAG:
+ return switch (localName) {
+ case OBJECT_QUERY_TAG -> {
addQueryDescriptor(SelectQueryDescriptor::new, attributes);
- return true;
-
- case SQL_QUERY_TAG:
+ yield true;
+ }
+ case SQL_QUERY_TAG -> {
addQueryDescriptor(SQLTemplateDescriptor::new, attributes);
- return true;
-
- case PROCEDURE_QUERY_TAG:
+ yield true;
+ }
+ case PROCEDURE_QUERY_TAG -> {
addQueryDescriptor(ProcedureQueryDescriptor::new, attributes);
- return true;
-
- case QUERY_CACHE_GROUP_TAG:
- return true;
-
- case QUERY_SQL_TAG:
+ yield true;
+ }
+ case QUERY_SQL_TAG -> {
this.sqlKey = attributes.getValue("adapterClass");
- return true;
-
- case QUERY_QL_TAG:
- case QUERY_PREFETCH_TAG:
+ yield true;
+ }
+ case QUERY_PREFETCH_TAG -> {
createPrefetchSemantics(attributes);
- return true;
- }
-
- return false;
+ yield true;
+ }
+ case QUERY_QL_TAG, QUERY_CACHE_GROUP_TAG -> true;
+ default -> false;
+ };
}
@Override
protected boolean processCharData(String localName, String data) {
switch (localName) {
- case QUERY_SQL_TAG:
- queryBuilder.addSql(data, sqlKey);
- break;
-
- case QUERY_QL_TAG:
- queryBuilder.setSelect(data);
- break;
-
- case QUERY_PREFETCH_TAG:
- addPrefetchWithSemantics(data);
- break;
-
- case QUERY_CACHE_GROUP_TAG:
- queryBuilder.setCacheGroup(data);
- break;
+ case QUERY_SQL_TAG -> queryBuilder.addSql(data, sqlKey);
+ case QUERY_QL_TAG -> queryBuilder.setSelect(data);
+ case QUERY_PREFETCH_TAG -> addPrefetchWithSemantics(data);
+ case QUERY_CACHE_GROUP_TAG -> queryBuilder.setCacheGroup(data);
}
return true;
}
@@ -149,7 +136,7 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
queryBuilder.setColumnNameCapitalization(CapsStrategy.valueOf(columnNameCapitalization.toUpperCase()));
}
- queryBuilder.setFetchingDataRows(Boolean.parseBoolean(attributes.getValue("dataRows")));
+ queryBuilder.setFetchingDataRows("true".equals(attributes.getValue("dataRows")));
queryBuilder.setFetchLimit(intAttribute(attributes, "fetchLimit"));
queryBuilder.setFetchOffset(intAttribute(attributes, "fetchOffset"));
queryBuilder.setPageSize(intAttribute(attributes, "pageSize"));
@@ -180,18 +167,11 @@ public class QueryDescriptorHandler extends NamespaceAwareNestedTagHandler {
}
private int convertPrefetchType(String type) {
- if (type != null) {
- switch (type) {
- case "joint":
- return 1;
- case "disjoint":
- return 2;
- case "disjointById":
- return 3;
- default:
- return 0;
- }
- }
- return 0;
+ return switch (type) {
+ case "joint" -> PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS;
+ case "disjoint" -> PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS;
+ case "disjointById" -> PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS;
+ case null, default -> PrefetchTreeNode.UNDEFINED_SEMANTICS;
+ };
}
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/RootDataMapHandler.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/RootDataMapHandler.java
index ddfb9dfb5d..ebbe4c6f1e 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/RootDataMapHandler.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/RootDataMapHandler.java
@@ -20,6 +20,7 @@
package org.apache.cayenne.project.xml;
import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.resource.Resource;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -29,9 +30,13 @@ import org.xml.sax.SAXException;
*/
public class RootDataMapHandler extends VersionAwareHandler {
- public RootDataMapHandler(LoaderContext loaderContext) {
- super(loaderContext, "dataMap");
+ private final Resource configurationSource;
+ private DataMapHandler dataMapHandler;
+
+ public RootDataMapHandler(LoaderContext loaderContext, Resource configurationSource) {
+ super(loaderContext, DataMapHandler.DATA_MAP_TAG);
setTargetNamespace(DataMap.SCHEMA_XSD);
+ this.configurationSource = configurationSource;
}
@Override
@@ -44,12 +49,20 @@ public class RootDataMapHandler extends VersionAwareHandler {
}
@Override
- protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName, Attributes attributes) {
- if(targetNamespace.equals(namespaceURI) && "dataMap".equals(localName)) {
- return new DataMapHandler(this);
+ protected ContentHandler createChildTagHandler(String namespaceURI, String localName, String qName,
+ Attributes attributes) {
+ if (targetNamespace.equals(namespaceURI) && DataMapHandler.DATA_MAP_TAG.equals(localName)) {
+ dataMapHandler = new DataMapHandler(this, configurationSource);
+ return dataMapHandler;
}
return super.createChildTagHandler(namespaceURI, localName, qName, attributes);
}
+ /**
+ * Returns the DataMap loaded by this handler, or null if there was none in the document.
+ */
+ public DataMap getDataMap() {
+ return dataMapHandler != null ? dataMapHandler.getDataMap() : null;
+ }
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
index 1ae6043c94..7755e6fb97 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
@@ -21,16 +21,12 @@ package org.apache.cayenne.project.xml;
import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.project.DataMapLoader;
-import org.apache.cayenne.project.upgrade.UpgradeContext;
import org.apache.cayenne.project.upgrade.ProjectFileUpgrader;
-import org.apache.cayenne.project.upgrade.UpgradeHandler;
-import org.apache.cayenne.project.upgrade.UpgradeType;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.di.Provider;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.resource.Resource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -43,8 +39,6 @@ import java.net.URL;
*/
public class XMLDataMapLoader implements DataMapLoader {
- private static final Logger LOGGER = LoggerFactory.getLogger(XMLDataMapLoader.class);
-
private static final String DATA_MAP_LOCATION_SUFFIX = ".map.xml";
@Inject
@@ -56,7 +50,7 @@ public class XMLDataMapLoader implements DataMapLoader {
@Inject
protected ProjectFileUpgrader upgrader;
- public synchronized DataMap load(Resource configurationResource) throws CayenneRuntimeException {
+ public DataMap load(Resource configurationResource) throws CayenneRuntimeException {
URL configurationURL = configurationResource.getURL();
DataMap map;
@@ -83,21 +77,15 @@ public class XMLDataMapLoader implements DataMapLoader {
}
protected DataMap parse(Resource configurationResource, InputSource input) throws Exception {
- DataMap[] maps = new DataMap[1];
-
XMLReader parser = xmlReaderProvider.get();
LoaderContext loaderContext = new LoaderContext(parser, handlerFactory);
- loaderContext.addDataMapListener(dataMap -> {
- dataMap.setConfigurationSource(configurationResource);
- maps[0] = dataMap;
- });
- RootDataMapHandler rootHandler = new RootDataMapHandler(loaderContext);
+ RootDataMapHandler rootHandler = new RootDataMapHandler(loaderContext, configurationResource);
parser.setContentHandler(rootHandler);
parser.setErrorHandler(rootHandler);
parser.parse(input);
- return maps[0];
+ return rootHandler.getDataMap();
}
/**
@@ -107,40 +95,10 @@ public class XMLDataMapLoader implements DataMapLoader {
* @since 5.0
*/
protected DataMap upgradeAndLoad(Resource configurationResource, String version) {
-
+ Document upgraded = upgrader.upgradeDataMapDOM(configurationResource, version).getRuntimeDocument();
URL configurationURL = configurationResource.getURL();
- UpgradeType upgradeType = upgrader.checkUpgradeNeeded(version);
-
- if (upgradeType == UpgradeType.DOWNGRADE_NEEDED) {
- throw new CayenneRuntimeException("""
- Unable to load DataMap from %s: project version %s is newer than the supported version %s. \
- The DataMap was created with a newer version of Cayenne""",
- configurationURL, version, UpgradeHandler.CURRENT_VERSION);
- }
-
- if (upgradeType == UpgradeType.INTERMEDIATE_UPGRADE_NEEDED) {
- throw new CayenneRuntimeException("""
- Unable to load DataMap from %s: project version %s is too old to be upgraded. \
- Open the project in an older CayenneModeler to upgrade it to version %s first""",
- configurationURL, version, UpgradeHandler.MIN_SUPPORTED_VERSION);
- }
-
- UpgradeContext context = upgrader.upgradeDataMapDOM(configurationResource, version);
- if (!context.getChangesAffectingRuntime().isEmpty()) {
- throw new CayenneRuntimeException("""
- Unable to upgrade DataMap from %s (project version %s) in memory, as the upgrade requires \
- manual changes. Open the project in CayenneModeler to upgrade it. %s""",
- configurationURL, version, String.join(" ", context.getChangesAffectingRuntime()));
- }
-
- LOGGER.warn("""
- DataMap {} has project version {} and was upgraded to version {} in memory. \
- Open the project in CayenneModeler to upgrade its XML permanently""",
- configurationURL, version, UpgradeHandler.CURRENT_VERSION);
-
try {
- return parse(configurationResource,
- DocumentInputSource.of(context.getDocument(), configurationURL.toString()));
+ return parse(configurationResource, DocumentInputSource.of(upgraded, configurationURL.toString()));
} catch (Exception e) {
throw new CayenneRuntimeException("Error loading configuration from %s", e, configurationURL);
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
index a65e7c85ac..0cdd2cc65c 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
@@ -24,16 +24,13 @@ import org.apache.cayenne.project.ConfigurationNameMapper;
import org.apache.cayenne.project.Project;
import org.apache.cayenne.project.ProjectLoader;
import org.apache.cayenne.project.DataMapLoader;
-import org.apache.cayenne.project.upgrade.UpgradeContext;
import org.apache.cayenne.project.upgrade.ProjectFileUpgrader;
-import org.apache.cayenne.project.upgrade.UpgradeHandler;
-import org.apache.cayenne.project.upgrade.UpgradeType;
-import org.apache.cayenne.di.AdhocObjectFactory;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.di.Provider;
import org.apache.cayenne.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -56,9 +53,6 @@ public class XMLProjectLoader implements ProjectLoader {
@Inject
protected ConfigurationNameMapper nameMapper;
- @Inject
- protected AdhocObjectFactory objectFactory;
-
@Inject
protected HandlerFactory handlerFactory;
@@ -98,7 +92,7 @@ public class XMLProjectLoader implements ProjectLoader {
LoaderContext loaderContext = new LoaderContext(parser, handlerFactory);
loaderContext.addDataMapListener(dataMap -> project.getDataMaps().add(dataMap));
- ProjectHandler rootHandler = new ProjectHandler(this, project, loaderContext);
+ ProjectHandler rootHandler = new ProjectHandler(project, loaderContext, nameMapper, dataMapLoader);
parser.setContentHandler(rootHandler);
parser.setErrorHandler(rootHandler);
parser.parse(input);
@@ -115,40 +109,10 @@ public class XMLProjectLoader implements ProjectLoader {
* @since 5.0
*/
protected Project upgradeAndLoad(Resource configurationResource, String version) {
-
+ Document upgraded = upgrader.upgradeProjectDOM(configurationResource, version).getRuntimeDocument();
URL configurationURL = configurationResource.getURL();
- UpgradeType upgradeType = upgrader.checkUpgradeNeeded(version);
-
- if (upgradeType == UpgradeType.DOWNGRADE_NEEDED) {
- throw new ConfigurationException("""
- Unable to load configuration from %s: project version %s is newer than the supported version %s. \
- The project was created with a newer version of Cayenne""",
- configurationURL, version, UpgradeHandler.CURRENT_VERSION);
- }
-
- if (upgradeType == UpgradeType.INTERMEDIATE_UPGRADE_NEEDED) {
- throw new ConfigurationException("""
- Unable to load configuration from %s: project version %s is too old to be upgraded. \
- Open the project in an older CayenneModeler to upgrade it to version %s first""",
- configurationURL, version, UpgradeHandler.MIN_SUPPORTED_VERSION);
- }
-
- UpgradeContext context = upgrader.upgradeProjectDOM(configurationResource, version);
- if (!context.getChangesAffectingRuntime().isEmpty()) {
- throw new ConfigurationException("""
- Unable to upgrade configuration from %s (project version %s) in memory, as the upgrade requires \
- manual changes. Open the project in CayenneModeler to upgrade it. %s""",
- configurationURL, version, String.join(" ", context.getChangesAffectingRuntime()));
- }
-
- LOGGER.warn("""
- Configuration {} has project version {} and was upgraded to version {} in memory. \
- Open the project in CayenneModeler to upgrade its XML permanently""",
- configurationURL, version, UpgradeHandler.CURRENT_VERSION);
-
try {
- return parse(configurationResource,
- DocumentInputSource.of(context.getDocument(), configurationURL.toString()));
+ return parse(configurationResource, DocumentInputSource.of(upgraded, configurationURL.toString()));
} catch (Exception e) {
throw new ConfigurationException("Error loading configuration from %s", e, configurationURL);
}
diff --git a/cayenne/src/test/java/org/apache/cayenne/project/xml/XMLDataMapLoaderTest.java b/cayenne/src/test/java/org/apache/cayenne/project/xml/XMLDataMapLoaderTest.java
index 89ce642695..0447436cc0 100644
--- a/cayenne/src/test/java/org/apache/cayenne/project/xml/XMLDataMapLoaderTest.java
+++ b/cayenne/src/test/java/org/apache/cayenne/project/xml/XMLDataMapLoaderTest.java
@@ -102,6 +102,22 @@ public class XMLDataMapLoaderTest {
assertEquals(CapsStrategy.UPPER, sql.getColumnNamesCapitalization());
}
+ @Test
+ public void loadInvalidObjEntityQualifier() {
+ URL url = getClass().getResource("testConfigMap11.map.xml");
+ CayenneRuntimeException e = assertThrows(CayenneRuntimeException.class, () -> loader.load(new URLResource(url)));
+ assertTrue(e.getCause().getMessage().contains("Invalid qualifier of ObjEntity 'Artist': name = ((("),
+ e.getCause().getMessage());
+ }
+
+ @Test
+ public void loadInvalidDbEntityQualifier() {
+ URL url = getClass().getResource("testConfigMap12.map.xml");
+ CayenneRuntimeException e = assertThrows(CayenneRuntimeException.class, () -> loader.load(new URLResource(url)));
+ assertTrue(e.getCause().getMessage().contains("Invalid qualifier of DbEntity 'ARTIST': NAME = ((("),
+ e.getCause().getMessage());
+ }
+
@Test
public void loadNewerVersionConfig() {
URL url = getClass().getResource("testConfigMap6.map.xml");
diff --git a/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap11.map.xml b/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap11.map.xml
new file mode 100644
index 0000000000..559da35aaf
--- /dev/null
+++ b/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap11.map.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ https://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<dataMap xmlns="http://cayenne.apache.org/schema/14/dataMap"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://cayenne.apache.org/schema/14/dataMap http://cayenne.apache.org/schema/14/dataMap.xsd">
+ <objEntity name="Artist" className="org.apache.cayenne.GenericPersistentObject">
+ <qualifier><![CDATA[name = (((]]></qualifier>
+ </objEntity>
+</dataMap>
diff --git a/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap12.map.xml b/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap12.map.xml
new file mode 100644
index 0000000000..75da6fcc80
--- /dev/null
+++ b/cayenne/src/test/resources/org/apache/cayenne/project/xml/testConfigMap12.map.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ https://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<dataMap xmlns="http://cayenne.apache.org/schema/14/dataMap"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://cayenne.apache.org/schema/14/dataMap http://cayenne.apache.org/schema/14/dataMap.xsd">
+ <dbEntity name="ARTIST">
+ <dbAttribute name="ID" type="INTEGER" primaryKey="true" mandatory="true"/>
+ <qualifier><![CDATA[NAME = (((]]></qualifier>
+ </dbEntity>
+</dataMap>
(cayenne) 04/04: cleanup
Posted by aa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 176a7594b0290cfeb20152455c96dd7ac43c0dfd
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sun Oct 4 15:55:15 2026 -0400
cleanup
---
.../org/apache/cayenne/crypto/map/CryptoDataMapLoader.java | 4 ++--
.../main/java/org/apache/cayenne/project/DataMapLoader.java | 2 +-
.../main/java/org/apache/cayenne/project/ProjectLoader.java | 7 +++----
.../java/org/apache/cayenne/project/xml/XMLDataMapLoader.java | 8 ++++----
.../java/org/apache/cayenne/project/xml/XMLProjectLoader.java | 10 +++++-----
5 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/CryptoDataMapLoader.java b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/CryptoDataMapLoader.java
index e9eac8f6b1..4bea8ca142 100644
--- a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/CryptoDataMapLoader.java
+++ b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/map/CryptoDataMapLoader.java
@@ -54,8 +54,8 @@ public class CryptoDataMapLoader implements DataMapLoader {
}
@Override
- public DataMap load(Resource configurationResource) throws CayenneRuntimeException {
- DataMap result = delegate.load(configurationResource);
+ public DataMap load(Resource source) throws CayenneRuntimeException {
+ DataMap result = delegate.load(source);
for (ObjEntity entity : result.getObjEntities()) {
if (entity.getLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC) {
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/DataMapLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/DataMapLoader.java
index 2bef9b0ee9..333eeee780 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/DataMapLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/DataMapLoader.java
@@ -29,5 +29,5 @@ import org.apache.cayenne.resource.Resource;
*/
public interface DataMapLoader {
- DataMap load(Resource configurationResource) throws CayenneRuntimeException;
+ DataMap load(Resource source) throws CayenneRuntimeException;
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/ProjectLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/ProjectLoader.java
index 723a82edc3..f8dc194941 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/ProjectLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/ProjectLoader.java
@@ -22,15 +22,14 @@ import org.apache.cayenne.ConfigurationException;
import org.apache.cayenne.resource.Resource;
/**
- * An object that can load a named {@link Project} from some configuration source.
+ * A loader of projects.
*
* @since 5.0
*/
public interface ProjectLoader {
/**
- * Loads a Project from some configuration resource, usually an XML file
- * found on classpath.
+ * Loads a Project from some resource, usually an XML file found on classpath.
*/
- Project load(Resource configurationResource) throws ConfigurationException;
+ Project load(Resource source) throws ConfigurationException;
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
index 7755e6fb97..c00941d438 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLDataMapLoader.java
@@ -50,17 +50,17 @@ public class XMLDataMapLoader implements DataMapLoader {
@Inject
protected ProjectFileUpgrader upgrader;
- public DataMap load(Resource configurationResource) throws CayenneRuntimeException {
+ public DataMap load(Resource source) throws CayenneRuntimeException {
- URL configurationURL = configurationResource.getURL();
+ URL configurationURL = source.getURL();
DataMap map;
try (InputStream in = configurationURL.openStream()) {
InputSource input = new InputSource(in);
input.setSystemId(configurationURL.toString());
- map = parse(configurationResource, input);
+ map = parse(source, input);
} catch (UnsupportedVersionException e) {
- map = upgradeAndLoad(configurationResource, e.getVersion());
+ map = upgradeAndLoad(source, e.getVersion());
} catch (Exception e) {
throw new CayenneRuntimeException("Error loading configuration from %s", e, configurationURL);
}
diff --git a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
index 0cdd2cc65c..f770d33529 100644
--- a/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
+++ b/cayenne/src/main/java/org/apache/cayenne/project/xml/XMLProjectLoader.java
@@ -60,22 +60,22 @@ public class XMLProjectLoader implements ProjectLoader {
protected ProjectFileUpgrader upgrader;
@Override
- public Project load(Resource configurationResource) throws ConfigurationException {
+ public Project load(Resource source) throws ConfigurationException {
- if (configurationResource == null) {
+ if (source == null) {
throw new NullPointerException("Null configurationResource");
}
- URL configurationURL = configurationResource.getURL();
+ URL configurationURL = source.getURL();
LOGGER.info("Loading XML configuration resource from {}", configurationURL);
try (InputStream in = configurationURL.openStream()) {
InputSource input = new InputSource(in);
input.setSystemId(configurationURL.toString());
- return parse(configurationResource, input);
+ return parse(source, input);
} catch (UnsupportedVersionException e) {
- return upgradeAndLoad(configurationResource, e.getVersion());
+ return upgradeAndLoad(source, e.getVersion());
} catch (Exception e) {
throw new ConfigurationException("Error loading configuration from %s", e, configurationURL);
}