cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject [14/16] cayenne git commit: CAY-2060 Move query descriptor classes to org.apache.cayenne.map package.
Date Fri, 19 Feb 2016 14:07:38 GMT
CAY-2060 Move query descriptor classes to org.apache.cayenne.map package.


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/3e2b0649
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/3e2b0649
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/3e2b0649

Branch: refs/heads/master
Commit: 3e2b0649ce503671dc9fd4809d97226f5ddffb42
Parents: aeabc69
Author: Dzmitry Kazimirchyk <dkazimirchyk@gmail.com>
Authored: Fri Feb 19 15:18:07 2016 +0300
Committer: Dzmitry Kazimirchyk <dkazimirchyk@gmail.com>
Committed: Fri Feb 19 16:57:52 2016 +0300

----------------------------------------------------------------------
 .../DefaultConfigurationNodeParentGetter.java   |   2 +-
 .../project/upgrade/v8/UpgradeHandler_V8.java   |   2 +-
 .../validation/DefaultProjectValidator.java     |  13 +-
 .../project/validation/EJBQLQueryValidator.java |   4 +-
 .../validation/EJBQLStatementValidator.java     |   2 +-
 .../validation/ProcedureQueryValidator.java     |   4 +-
 .../validation/SQLTemplateValidator.java        |   4 +-
 .../validation/SelectQueryValidator.java        |   2 +
 .../BaseConfigurationNodeVisitor.java           |   3 +-
 .../configuration/ConfigurationNodeVisitor.java |   3 +-
 .../java/org/apache/cayenne/map/DataMap.java    |   1 -
 .../cayenne/map/EJBQLQueryDescriptor.java       |  86 +++++++
 .../org/apache/cayenne/map/EntityResolver.java  |   1 -
 .../org/apache/cayenne/map/MappingCache.java    |   2 -
 .../apache/cayenne/map/MappingNamespace.java    |   2 -
 .../cayenne/map/ProcedureQueryDescriptor.java   | 107 +++++++++
 .../cayenne/map/ProxiedMappingNamespace.java    |   1 -
 .../org/apache/cayenne/map/QueryDescriptor.java | 238 +++++++++++++++++++
 .../cayenne/map/SQLTemplateDescriptor.java      | 176 ++++++++++++++
 .../cayenne/map/SelectQueryDescriptor.java      | 223 +++++++++++++++++
 .../cayenne/query/EJBQLQueryDescriptor.java     |  82 -------
 .../org/apache/cayenne/query/NamedQuery.java    |   1 +
 .../cayenne/query/ProcedureQueryDescriptor.java | 105 --------
 .../java/org/apache/cayenne/query/Query.java    |   1 +
 .../apache/cayenne/query/QueryDescriptor.java   | 238 -------------------
 .../cayenne/query/SQLTemplateDescriptor.java    | 173 --------------
 .../cayenne/query/SelectQueryDescriptor.java    | 221 -----------------
 .../cayenne/map/DataMapNamespaceTest.java       |   1 -
 .../org/apache/cayenne/map/DataMapTest.java     |   1 -
 .../apache/cayenne/map/EntityResolverIT.java    |   1 -
 .../cayenne/map/MockMappingNamespace.java       |   2 -
 .../cayenne/map/naming/NameCheckersTest.java    |   2 +-
 .../cayenne/gen/ClassGenerationAction.java      |   2 +-
 .../gen/ClientClassGenerationAction.java        |   3 +-
 .../cayenne/gen/ClientDataMapArtifact.java      |   2 +-
 .../org/apache/cayenne/gen/DataMapArtifact.java |   2 +-
 .../cayenne/gen/ClassGenerationActionTest.java  |   2 +-
 .../cayenne/configuration/event/QueryEvent.java |   2 +-
 .../cayenne/modeler/ProjectController.java      |   3 +-
 .../cayenne/modeler/ProjectTreeFactory.java     |   3 +-
 .../apache/cayenne/modeler/ProjectTreeView.java |   2 +-
 .../modeler/action/CreateQueryAction.java       |   2 +-
 .../cayenne/modeler/action/FindAction.java      |   2 +-
 .../modeler/action/ImportEOModelAction.java     |   2 +-
 .../cayenne/modeler/action/PasteAction.java     |   4 +-
 .../cayenne/modeler/action/RemoveAction.java    |   2 +-
 .../cayenne/modeler/dialog/FindDialog.java      |  13 +-
 .../cayenne/modeler/dialog/query/QueryType.java |   2 +-
 .../modeler/dialog/validator/QueryErrorMsg.java |   2 +-
 .../validator/ValidationDisplayHandler.java     |   3 +-
 .../cayenne/modeler/editor/EditorView.java      |   2 +-
 .../modeler/editor/EjbqlQueryMainTab.java       |   2 +-
 .../modeler/editor/EjbqlQueryScriptsTab.java    |   4 +-
 .../cayenne/modeler/editor/EjbqlTabbedView.java |   2 +-
 .../editor/ObjectQueryPropertiesPanel.java      |   2 +-
 .../modeler/editor/ProcedureQueryView.java      |   2 +
 .../modeler/editor/RawQueryPropertiesPanel.java |   2 +-
 .../modeler/editor/SQLTemplateMainTab.java      |   1 +
 .../modeler/editor/SQLTemplateScriptsTab.java   |   4 +-
 .../modeler/editor/SQLTemplateTabbedView.java   |   2 +-
 .../modeler/editor/SelectPropertiesPanel.java   |   2 +-
 .../modeler/editor/SelectQueryMainTab.java      |   2 +
 .../modeler/editor/SelectQueryOrderingTab.java  |   2 +
 .../modeler/editor/SelectQueryTabbedView.java   |   2 +-
 .../modeler/event/QueryDisplayEvent.java        |   3 +-
 .../modeler/undo/CreateQueryUndoableEdit.java   |   3 +-
 .../cayenne/modeler/undo/PasteUndoableEdit.java |   2 +-
 .../modeler/undo/RemoveUndoableEdit.java        |   3 +-
 .../cayenne/modeler/util/CellRenderers.java     |   2 +-
 .../cayenne/modeler/util/ProjectUtil.java       |   2 +-
 .../util/state/QueryDisplayEventType.java       |   3 +-
 .../cayenne/wocompat/EOModelProcessor.java      |   7 +-
 .../cayenne/wocompat/EOModelProcessorTest.java  |   5 +-
 73 files changed, 893 insertions(+), 925 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/DefaultConfigurationNodeParentGetter.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/DefaultConfigurationNodeParentGetter.java b/cayenne-project/src/main/java/org/apache/cayenne/project/DefaultConfigurationNodeParentGetter.java
index 6dbe6ef..3458c73 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/DefaultConfigurationNodeParentGetter.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/DefaultConfigurationNodeParentGetter.java
@@ -33,7 +33,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 
 public class DefaultConfigurationNodeParentGetter implements ConfigurationNodeParentGetter {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/upgrade/v8/UpgradeHandler_V8.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/upgrade/v8/UpgradeHandler_V8.java b/cayenne-project/src/main/java/org/apache/cayenne/project/upgrade/v8/UpgradeHandler_V8.java
index 939a6e4..592569d 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/upgrade/v8/UpgradeHandler_V8.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/upgrade/v8/UpgradeHandler_V8.java
@@ -32,7 +32,7 @@ import org.apache.cayenne.project.upgrade.UpgradeHandler;
 import org.apache.cayenne.project.upgrade.UpgradeMetaData;
 import org.apache.cayenne.project.upgrade.UpgradeType;
 import org.apache.cayenne.project.upgrade.v7.ProjectUpgrader_V7;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.resource.Resource;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
index 5835a5d..f50ecc5 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
@@ -24,18 +24,7 @@ import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataNodeDescriptor;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.Embeddable;
-import org.apache.cayenne.map.EmbeddableAttribute;
-import org.apache.cayenne.map.ObjAttribute;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.map.Procedure;
-import org.apache.cayenne.map.ProcedureParameter;
-import org.apache.cayenne.query.*;
+import org.apache.cayenne.map.*;
 import org.apache.cayenne.validation.ValidationResult;
 
 /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
index 20a7b61..d44fb50 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
@@ -20,9 +20,7 @@ package org.apache.cayenne.project.validation;
 
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.project.validation.EJBQLStatementValidator.PositionException;
-import org.apache.cayenne.query.EJBQLQuery;
-import org.apache.cayenne.query.EJBQLQueryDescriptor;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.EJBQLQueryDescriptor;
 import org.apache.cayenne.validation.ValidationResult;
 
 class EJBQLQueryValidator extends ConfigurationNodeValidator {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
index 40a98c9..acd5064 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
@@ -24,7 +24,7 @@ import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ejbql.EJBQLException;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.EJBQLQuery;
-import org.apache.cayenne.query.EJBQLQueryDescriptor;
+import org.apache.cayenne.map.EJBQLQueryDescriptor;
 
 public class EJBQLStatementValidator {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ProcedureQueryValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ProcedureQueryValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ProcedureQueryValidator.java
index 5a259d1..9f031a5 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ProcedureQueryValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ProcedureQueryValidator.java
@@ -20,8 +20,8 @@ package org.apache.cayenne.project.validation;
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Procedure;
-import org.apache.cayenne.query.ProcedureQueryDescriptor;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.ProcedureQueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.validation.ValidationResult;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SQLTemplateValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SQLTemplateValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SQLTemplateValidator.java
index 2899351..8b55418 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SQLTemplateValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SQLTemplateValidator.java
@@ -19,8 +19,8 @@
 package org.apache.cayenne.project.validation;
 
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.query.QueryDescriptor;
-import org.apache.cayenne.query.SQLTemplateDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.cayenne.map.SQLTemplateDescriptor;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.validation.ValidationResult;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SelectQueryValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SelectQueryValidator.java b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SelectQueryValidator.java
index 7a1425c..c0bb5bc 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SelectQueryValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/SelectQueryValidator.java
@@ -24,6 +24,8 @@ import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionException;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.QueryDescriptor;
+import org.apache.cayenne.map.SelectQueryDescriptor;
 import org.apache.cayenne.query.*;
 import org.apache.cayenne.util.CayenneMapEntry;
 import org.apache.cayenne.util.Util;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/configuration/BaseConfigurationNodeVisitor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/BaseConfigurationNodeVisitor.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/BaseConfigurationNodeVisitor.java
index e8badcd..65365b2 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/BaseConfigurationNodeVisitor.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/BaseConfigurationNodeVisitor.java
@@ -29,8 +29,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 
 /**
  * A {@link ConfigurationNodeVisitor} that does nothing, used as a convenience superclass

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/configuration/ConfigurationNodeVisitor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/configuration/ConfigurationNodeVisitor.java b/cayenne-server/src/main/java/org/apache/cayenne/configuration/ConfigurationNodeVisitor.java
index 201bfa7..60d2900 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/configuration/ConfigurationNodeVisitor.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/configuration/ConfigurationNodeVisitor.java
@@ -29,8 +29,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 
 /**
  * A visitor interface for implementing operations on different types of

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
index 7c04504..b19ad79 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/DataMap.java
@@ -28,7 +28,6 @@ import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.map.event.DbEntityListener;
 import org.apache.cayenne.map.event.EntityEvent;
 import org.apache.cayenne.map.event.ObjEntityListener;
-import org.apache.cayenne.query.QueryDescriptor;
 import org.apache.cayenne.resource.Resource;
 import org.apache.cayenne.util.ToStringBuilder;
 import org.apache.cayenne.util.Util;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/EJBQLQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/EJBQLQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/EJBQLQueryDescriptor.java
new file mode 100644
index 0000000..bb550fe
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/EJBQLQueryDescriptor.java
@@ -0,0 +1,86 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.util.XMLEncoder;
+
+import java.util.Map;
+
+/**
+ * @since 4.0
+ */
+public class EJBQLQueryDescriptor extends QueryDescriptor {
+
+    protected String ejbql;
+
+    public EJBQLQueryDescriptor() {
+        this.type = EJBQL_QUERY;
+    }
+
+    /**
+     * Returns EJBQL query string for this query.
+     */
+    public String getEjbql() {
+        return ejbql;
+    }
+
+    /**
+     * Sets EJBQL query string for this query.
+     */
+    public void setEjbql(String ejbql) {
+        this.ejbql = ejbql;
+    }
+
+    @Override
+    public EJBQLQuery buildQuery() {
+        EJBQLQuery ejbqlQuery = new EJBQLQuery(this.getEjbql());
+        ejbqlQuery.setName(this.getName());
+        ejbqlQuery.setDataMap(dataMap);
+        ejbqlQuery.initWithProperties(this.getProperties());
+
+        return ejbqlQuery;
+    }
+
+    @Override
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" type=\"");
+        encoder.print(type);
+        encoder.println("\">");
+
+        encoder.indent(1);
+
+        // print properties
+        for (Map.Entry<String, String> property : properties.entrySet()) {
+            encoder.printProperty(property.getKey(), property.getValue());
+        }
+
+
+        if (ejbql != null) {
+            encoder.print("<ejbql><![CDATA[");
+            encoder.print(ejbql);
+            encoder.println("]]></ejbql>");
+        }
+
+        encoder.indent(-1);
+        encoder.println("</query>");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
index 0f4c837..9e59735 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
@@ -22,7 +22,6 @@ package org.apache.cayenne.map;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.ClassDescriptorMap;
 import org.apache.cayenne.reflect.FaultFactory;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/MappingCache.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/MappingCache.java b/cayenne-server/src/main/java/org/apache/cayenne/map/MappingCache.java
index 4ddbe9c..d2704fd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/MappingCache.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/MappingCache.java
@@ -26,8 +26,6 @@ import java.util.Map;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
 import org.apache.commons.collections.collection.CompositeCollection;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/MappingNamespace.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/MappingNamespace.java b/cayenne-server/src/main/java/org/apache/cayenne/map/MappingNamespace.java
index d4f7697..7fd4362 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/MappingNamespace.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/MappingNamespace.java
@@ -22,8 +22,6 @@ package org.apache.cayenne.map;
 import java.util.Collection;
 
 import org.apache.cayenne.Persistent;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
 
 /**
  * Defines API of a container of DbEntities, ObjEntities, Procedures, Queries

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/ProcedureQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/ProcedureQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/ProcedureQueryDescriptor.java
new file mode 100644
index 0000000..1ea3ea8
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/ProcedureQueryDescriptor.java
@@ -0,0 +1,107 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.util.XMLEncoder;
+
+import java.util.Map;
+
+/**
+ * @since 4.0
+ */
+public class ProcedureQueryDescriptor extends QueryDescriptor {
+
+    protected String resultEntityName;
+
+    public ProcedureQueryDescriptor() {
+        this.type = PROCEDURE_QUERY;
+    }
+
+    /**
+     * Returns result entity name.
+     */
+    public String getResultEntityName() {
+        return resultEntityName;
+    }
+
+    /**
+     * Sets result entity name.
+     */
+    public void setResultEntityName(String resultEntityName) {
+        this.resultEntityName = resultEntityName;
+    }
+
+    @Override
+    public ProcedureQuery buildQuery() {
+        ProcedureQuery procedureQuery = new ProcedureQuery();
+
+        if (root != null) {
+            procedureQuery.setRoot(root);
+        }
+
+        procedureQuery.setName(this.getName());
+        procedureQuery.setDataMap(dataMap);
+        procedureQuery.setResultEntityName(this.getResultEntityName());
+        procedureQuery.initWithProperties(this.getProperties());
+
+        return procedureQuery;
+    }
+
+    @Override
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" type=\"");
+        encoder.print(type);
+
+        encoder.print("\" root=\"");
+        encoder.print(MapLoader.PROCEDURE_ROOT);
+
+        String rootString = null;
+
+        if (root instanceof String) {
+            rootString = root.toString();
+        }
+        else if (root instanceof Procedure) {
+            rootString = ((Procedure) root).getName();
+        }
+
+        if (rootString != null) {
+            encoder.print("\" root-name=\"");
+            encoder.print(rootString);
+        }
+
+        if (resultEntityName != null) {
+            encoder.print("\" result-entity=\"");
+            encoder.print(resultEntityName);
+        }
+
+        encoder.println("\">");
+        encoder.indent(1);
+
+        // print properties
+        for (Map.Entry<String, String> property : properties.entrySet()) {
+            encoder.printProperty(property.getKey(), property.getValue());
+        }
+
+        encoder.indent(-1);
+        encoder.println("</query>");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/ProxiedMappingNamespace.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/ProxiedMappingNamespace.java b/cayenne-server/src/main/java/org/apache/cayenne/map/ProxiedMappingNamespace.java
index 79b89a1..3d5a879 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/ProxiedMappingNamespace.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/ProxiedMappingNamespace.java
@@ -21,7 +21,6 @@ package org.apache.cayenne.map;
 import java.util.Collection;
 
 import org.apache.cayenne.Persistent;
-import org.apache.cayenne.query.QueryDescriptor;
 
 /**
  * A proxy for lazy on-demand initialization of the mapping cache.

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/QueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/QueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/QueryDescriptor.java
new file mode 100644
index 0000000..64fd404
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/QueryDescriptor.java
@@ -0,0 +1,238 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.configuration.ConfigurationNode;
+import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.util.XMLEncoder;
+import org.apache.cayenne.util.XMLSerializable;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Generic descriptor of a Cayenne query.
+ *
+ * @since 4.0
+ */
+public class QueryDescriptor implements Serializable, ConfigurationNode, XMLSerializable {
+
+    public static final String SELECT_QUERY = "SelectQuery";
+    public static final String SQL_TEMPLATE = "SQLTemplate";
+    public static final String EJBQL_QUERY = "EJBQLQuery";
+    public static final String PROCEDURE_QUERY = "ProcedureQuery";
+
+    /**
+     * Creates new SelectQuery query descriptor.
+     */
+    public static SelectQueryDescriptor selectQueryDescriptor() {
+        return new SelectQueryDescriptor();
+    }
+
+    /**
+     * Creates new SQLTemplate query descriptor.
+     */
+    public static SQLTemplateDescriptor sqlTemplateDescriptor() {
+        return new SQLTemplateDescriptor();
+    }
+
+    /**
+     * Creates new ProcedureQuery query descriptor.
+     */
+    public static ProcedureQueryDescriptor procedureQueryDescriptor() {
+        return new ProcedureQueryDescriptor();
+    }
+
+    /**
+     * Creates new EJBQLQuery query descriptor.
+     */
+    public static EJBQLQueryDescriptor ejbqlQueryDescriptor() {
+        return new EJBQLQueryDescriptor();
+    }
+
+    /**
+     * Creates query descriptor of a given type.
+     */
+    public static QueryDescriptor descriptor(String type) {
+        switch (type) {
+            case SELECT_QUERY:
+                return selectQueryDescriptor();
+            case SQL_TEMPLATE:
+                return sqlTemplateDescriptor();
+            case EJBQL_QUERY:
+                return ejbqlQueryDescriptor();
+            case PROCEDURE_QUERY:
+                return procedureQueryDescriptor();
+            default:
+                QueryDescriptor descriptor = new QueryDescriptor();
+                descriptor.setType(type);
+                return descriptor;
+        }
+    }
+
+    protected String name;
+    protected String type;
+    protected DataMap dataMap;
+    protected Object root;
+
+    protected Map<String, String> properties = new HashMap<>();
+
+    protected QueryDescriptor() {
+
+    }
+
+    /**
+     * Returns name of the query.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets name of the query.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Returns type of the query.
+     */
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * Sets type of the query.
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public DataMap getDataMap() {
+        return dataMap;
+    }
+
+    public void setDataMap(DataMap dataMap) {
+        this.dataMap = dataMap;
+    }
+
+    /**
+     * Returns the root of this query.
+     */
+    public Object getRoot() {
+        return root;
+    }
+
+    /**
+     * Sets the root of this query.
+     */
+    public void setRoot(Object root) {
+        this.root = root;
+    }
+
+    /**
+     * Returns map of query properties set up for this query.
+     */
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+
+    /**
+     * Returns query property by its name.
+     */
+    public String getProperty(String name) {
+        return properties.get(name);
+    }
+
+    /**
+     * Sets map of query properties for this query.
+     */
+    public void setProperties(Map<String, String> properties) {
+        this.properties = properties;
+    }
+
+    /**
+     * Sets single query property.
+     */
+    public void setProperty(String name, String value) {
+        this.properties.put(name, value);
+    }
+
+    /**
+     * Assembles Cayenne query instance of appropriate type from this descriptor.
+     */
+    public Query buildQuery() {
+        throw new CayenneRuntimeException("Unable to build query object of this type.");
+    }
+
+    @Override
+    public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor) {
+        return visitor.visitQuery(this);
+    }
+
+    @Override
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" type=\"");
+        encoder.print(type);
+
+        String rootString = null;
+        String rootType = null;
+
+        if (root instanceof String) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = root.toString();
+        } else if (root instanceof ObjEntity) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = ((ObjEntity) root).getName();
+        } else if (root instanceof DbEntity) {
+            rootType = MapLoader.DB_ENTITY_ROOT;
+            rootString = ((DbEntity) root).getName();
+        } else if (root instanceof Procedure) {
+            rootType = MapLoader.PROCEDURE_ROOT;
+            rootString = ((Procedure) root).getName();
+        } else if (root instanceof Class<?>) {
+            rootType = MapLoader.JAVA_CLASS_ROOT;
+            rootString = ((Class<?>) root).getName();
+        }
+
+        if (rootType != null) {
+            encoder.print("\" root=\"");
+            encoder.print(rootType);
+            encoder.print("\" root-name=\"");
+            encoder.print(rootString);
+        }
+
+        encoder.println("\">");
+
+        encoder.indent(1);
+
+        for (Map.Entry<String, String> property : properties.entrySet()) {
+            encoder.printProperty(property.getKey(), property.getValue());
+        }
+
+        encoder.indent(-1);
+        encoder.println("</query>");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java
new file mode 100644
index 0000000..7ceea4c
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/SQLTemplateDescriptor.java
@@ -0,0 +1,176 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.util.XMLEncoder;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeSet;
+
+/**
+ * @since 4.0
+ */
+public class SQLTemplateDescriptor extends QueryDescriptor {
+
+    protected String sql;
+
+    protected Map<String, String> adapterSql = new HashMap<>();
+
+    public SQLTemplateDescriptor() {
+        this.type = SQL_TEMPLATE;
+    }
+
+    /**
+     * Returns default SQL statement for this query.
+     */
+    public String getSql() {
+        return sql;
+    }
+
+    /**
+     * Sets default SQL statement for this query.
+     */
+    public void setSql(String sql) {
+        this.sql = sql;
+    }
+
+    /**
+     * Returns map of db adapter specific SQL statements.
+     */
+    public Map<String, String> getAdapterSql() {
+        return adapterSql;
+    }
+
+    /**
+     * Sets a map db adapter specific SQL statements for this query.
+     */
+    public void setAdapterSql(Map<String, String> adapterSql) {
+        this.adapterSql = adapterSql;
+    }
+
+    @Override
+    public SQLTemplate buildQuery() {
+        SQLTemplate template = new SQLTemplate();
+
+        if (root != null) {
+            template.setRoot(root);
+        }
+
+        template.setName(name);
+        template.setDataMap(dataMap);
+        template.initWithProperties(this.getProperties());
+
+        // init SQL
+        template.setDefaultTemplate(this.getSql());
+
+        Map<String, String> adapterSql = this.getAdapterSql();
+
+        if (adapterSql != null) {
+            for (Map.Entry<String, String> entry : adapterSql.entrySet()) {
+                String key = entry.getKey();
+                String value = entry.getValue();
+                if (key != null && value != null) {
+                    template.setTemplate(key, value);
+                }
+            }
+        }
+
+        return template;
+    }
+
+    @Override
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" type=\"");
+        encoder.print(type);
+
+        String rootString = null;
+        String rootType = null;
+
+        if (root instanceof String) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = root.toString();
+        } else if (root instanceof ObjEntity) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = ((ObjEntity) root).getName();
+        } else if (root instanceof DbEntity) {
+            rootType = MapLoader.DB_ENTITY_ROOT;
+            rootString = ((DbEntity) root).getName();
+        } else if (root instanceof Procedure) {
+            rootType = MapLoader.PROCEDURE_ROOT;
+            rootString = ((Procedure) root).getName();
+        } else if (root instanceof Class<?>) {
+            rootType = MapLoader.JAVA_CLASS_ROOT;
+            rootString = ((Class<?>) root).getName();
+        } else if (root instanceof DataMap) {
+            rootType = MapLoader.DATA_MAP_ROOT;
+            rootString = ((DataMap) root).getName();
+        }
+
+        if (rootType != null) {
+            encoder.print("\" root=\"");
+            encoder.print(rootType);
+            encoder.print("\" root-name=\"");
+            encoder.print(rootString);
+        }
+
+        encoder.println("\">");
+
+        encoder.indent(1);
+
+        // print properties
+        for (Map.Entry<String, String> property : properties.entrySet()) {
+            encoder.printProperty(property.getKey(), property.getValue());
+        }
+
+        // encode default SQL
+        if (sql != null) {
+            encoder.print("<sql><![CDATA[");
+            encoder.print(sql);
+            encoder.println("]]></sql>");
+        }
+
+        // encode adapter SQL
+        if (adapterSql != null && !adapterSql.isEmpty()) {
+
+            // sorting entries by adapter name
+            TreeSet<String> keys = new TreeSet<String>(adapterSql.keySet());
+            for (String key : keys) {
+                String value = adapterSql.get(key);
+
+                if (key != null && value != null) {
+                    String sql = value.trim();
+                    if (sql.length() > 0) {
+                        encoder.print("<sql adapter-class=\"");
+                        encoder.print(key);
+                        encoder.print("\"><![CDATA[");
+                        encoder.print(sql);
+                        encoder.println("]]></sql>");
+                    }
+                }
+            }
+        }
+
+        encoder.indent(-1);
+        encoder.println("</query>");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java
new file mode 100644
index 0000000..fafe15b
--- /dev/null
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/SelectQueryDescriptor.java
@@ -0,0 +1,223 @@
+/*****************************************************************
+ *   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
+ *
+ *    http://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.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.query.Ordering;
+import org.apache.cayenne.query.PrefetchTreeNode;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.util.XMLEncoder;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @since 4.0
+ */
+public class SelectQueryDescriptor extends QueryDescriptor {
+
+    protected Expression qualifier;
+
+    protected List<Ordering> orderings = new ArrayList<>();
+    protected List<String> prefetches = new ArrayList<>();
+
+    public SelectQueryDescriptor() {
+        this.type = SELECT_QUERY;
+    }
+
+    public void setDistinct(boolean value) {
+        setProperty(SelectQuery.DISTINCT_PROPERTY, String.valueOf(value));
+    }
+
+    public boolean isDistinct() {
+        String distinct = getProperty(SelectQuery.DISTINCT_PROPERTY);
+
+        return distinct != null ? Boolean.valueOf(distinct) : false;
+    }
+
+    /**
+     * Returns qualifier of this query.
+     */
+    public Expression getQualifier() {
+        return qualifier;
+    }
+
+    /**
+     * Sets qualifier for this query.
+     */
+    public void setQualifier(Expression qualifier) {
+        this.qualifier = qualifier;
+    }
+
+    /**
+     * Returns list of orderings for this query.
+     */
+    public List<Ordering> getOrderings() {
+        return orderings;
+    }
+
+    /**
+     * Sets list of orderings for this query.
+     */
+    public void setOrderings(List<Ordering> orderings) {
+        this.orderings = orderings;
+    }
+
+    /**
+     * Adds single ordering for this query.
+     */
+    public void addOrdering(Ordering ordering) {
+        this.orderings.add(ordering);
+    }
+
+    /**
+     * Removes single ordering from this query.
+     */
+    public void removeOrdering(Ordering ordering) {
+        this.orderings.remove(ordering);
+    }
+
+    /**
+     * Returns list of prefetch paths for this query.
+     */
+    public List<String> getPrefetches() {
+        return prefetches;
+    }
+
+    /**
+     * Sets list of prefetch paths for this query.
+     */
+    public void setPrefetches(List<String> prefetches) {
+        this.prefetches = prefetches;
+    }
+
+    /**
+     * Adds single prefetch path to this query.
+     */
+    public void addPrefetch(String prefetchPath) {
+        this.prefetches.add(prefetchPath);
+    }
+
+    /**
+     * Removes single prefetch path from this query.
+     */
+    public void removePrefetch(String prefetchPath) {
+        this.prefetches.remove(prefetchPath);
+    }
+
+    @Override
+    public SelectQuery<?> buildQuery() {
+        SelectQuery<Object> selectQuery = new SelectQuery<>();
+        selectQuery.setRoot(this.getRoot());
+        selectQuery.setName(this.getName());
+        selectQuery.setDataMap(dataMap);
+        selectQuery.setQualifier(this.getQualifier());
+
+        List<Ordering> orderings = this.getOrderings();
+
+        if (orderings != null && !orderings.isEmpty()) {
+            selectQuery.addOrderings(orderings);
+        }
+
+        List<String> prefetches = this.getPrefetches();
+
+        if (prefetches != null && !prefetches.isEmpty()) {
+            for (String prefetch : prefetches) {
+                selectQuery.addPrefetch(prefetch);
+            }
+        }
+
+        // init properties
+        selectQuery.initWithProperties(this.getProperties());
+
+        return selectQuery;
+    }
+
+    @Override
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<query name=\"");
+        encoder.print(getName());
+        encoder.print("\" type=\"");
+        encoder.print(type);
+
+        String rootString = null;
+        String rootType = null;
+
+        if (root instanceof String) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = root.toString();
+        } else if (root instanceof ObjEntity) {
+            rootType = MapLoader.OBJ_ENTITY_ROOT;
+            rootString = ((ObjEntity) root).getName();
+        } else if (root instanceof DbEntity) {
+            rootType = MapLoader.DB_ENTITY_ROOT;
+            rootString = ((DbEntity) root).getName();
+        } else if (root instanceof Procedure) {
+            rootType = MapLoader.PROCEDURE_ROOT;
+            rootString = ((Procedure) root).getName();
+        } else if (root instanceof Class<?>) {
+            rootType = MapLoader.JAVA_CLASS_ROOT;
+            rootString = ((Class<?>) root).getName();
+        }
+
+        if (rootType != null) {
+            encoder.print("\" root=\"");
+            encoder.print(rootType);
+            encoder.print("\" root-name=\"");
+            encoder.print(rootString);
+        }
+
+        encoder.println("\">");
+
+        encoder.indent(1);
+
+        // print properties
+        for (Map.Entry<String, String> property : properties.entrySet()) {
+            encoder.printProperty(property.getKey(), property.getValue());
+        }
+
+        // encode qualifier
+        if (qualifier != null) {
+            encoder.print("<qualifier>");
+            qualifier.encodeAsXML(encoder);
+            encoder.println("</qualifier>");
+        }
+
+        // encode orderings
+        if (orderings != null && !orderings.isEmpty()) {
+            for (Ordering ordering : orderings) {
+                ordering.encodeAsXML(encoder);
+            }
+        }
+
+        PrefetchTreeNode prefetchTree = new PrefetchTreeNode();
+
+        for (String prefetchPath : prefetches) {
+            PrefetchTreeNode node = prefetchTree.addPath(prefetchPath);
+            node.setSemantics(PrefetchTreeNode.UNDEFINED_SEMANTICS);
+            node.setPhantom(false);
+        }
+
+        prefetchTree.encodeAsXML(encoder);
+
+        encoder.indent(-1);
+        encoder.println("</query>");
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/EJBQLQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/EJBQLQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/query/EJBQLQueryDescriptor.java
deleted file mode 100644
index bc0f550..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/EJBQLQueryDescriptor.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    http://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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.util.XMLEncoder;
-
-import java.util.Map;
-
-public class EJBQLQueryDescriptor extends QueryDescriptor {
-
-    protected String ejbql;
-
-    public EJBQLQueryDescriptor() {
-        this.type = EJBQL_QUERY;
-    }
-
-    /**
-     * Returns EJBQL query string for this query.
-     */
-    public String getEjbql() {
-        return ejbql;
-    }
-
-    /**
-     * Sets EJBQL query string for this query.
-     */
-    public void setEjbql(String ejbql) {
-        this.ejbql = ejbql;
-    }
-
-    @Override
-    public EJBQLQuery buildQuery() {
-        EJBQLQuery ejbqlQuery = new EJBQLQuery(this.getEjbql());
-        ejbqlQuery.setName(this.getName());
-        ejbqlQuery.setDataMap(dataMap);
-        ejbqlQuery.initWithProperties(this.getProperties());
-
-        return ejbqlQuery;
-    }
-
-    @Override
-    public void encodeAsXML(XMLEncoder encoder) {
-        encoder.print("<query name=\"");
-        encoder.print(getName());
-        encoder.print("\" type=\"");
-        encoder.print(type);
-        encoder.println("\">");
-
-        encoder.indent(1);
-
-        // print properties
-        for (Map.Entry<String, String> property : properties.entrySet()) {
-            encoder.printProperty(property.getKey(), property.getValue());
-        }
-
-
-        if (ejbql != null) {
-            encoder.print("<ejbql><![CDATA[");
-            encoder.print(ejbql);
-            encoder.println("]]></ejbql>");
-        }
-
-        encoder.indent(-1);
-        encoder.println("</query>");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/NamedQuery.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/NamedQuery.java b/cayenne-server/src/main/java/org/apache/cayenne/query/NamedQuery.java
index 7218c41..d24a4ce 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/NamedQuery.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/NamedQuery.java
@@ -24,6 +24,7 @@ import java.util.*;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.util.EqualsBuilder;
 import org.apache.cayenne.util.HashCodeBuilder;
 import org.apache.cayenne.util.Util;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/ProcedureQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ProcedureQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ProcedureQueryDescriptor.java
deleted file mode 100644
index ce95e06..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/ProcedureQueryDescriptor.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    http://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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.map.Procedure;
-import org.apache.cayenne.util.XMLEncoder;
-
-import java.util.Map;
-
-public class ProcedureQueryDescriptor extends QueryDescriptor {
-
-    protected String resultEntityName;
-
-    public ProcedureQueryDescriptor() {
-        this.type = PROCEDURE_QUERY;
-    }
-
-    /**
-     * Returns result entity name.
-     */
-    public String getResultEntityName() {
-        return resultEntityName;
-    }
-
-    /**
-     * Sets result entity name.
-     */
-    public void setResultEntityName(String resultEntityName) {
-        this.resultEntityName = resultEntityName;
-    }
-
-    @Override
-    public ProcedureQuery buildQuery() {
-        ProcedureQuery procedureQuery = new ProcedureQuery();
-
-        if (root != null) {
-            procedureQuery.setRoot(root);
-        }
-
-        procedureQuery.setName(this.getName());
-        procedureQuery.setDataMap(dataMap);
-        procedureQuery.setResultEntityName(this.getResultEntityName());
-        procedureQuery.initWithProperties(this.getProperties());
-
-        return procedureQuery;
-    }
-
-    @Override
-    public void encodeAsXML(XMLEncoder encoder) {
-        encoder.print("<query name=\"");
-        encoder.print(getName());
-        encoder.print("\" type=\"");
-        encoder.print(type);
-
-        encoder.print("\" root=\"");
-        encoder.print(MapLoader.PROCEDURE_ROOT);
-
-        String rootString = null;
-
-        if (root instanceof String) {
-            rootString = root.toString();
-        }
-        else if (root instanceof Procedure) {
-            rootString = ((Procedure) root).getName();
-        }
-
-        if (rootString != null) {
-            encoder.print("\" root-name=\"");
-            encoder.print(rootString);
-        }
-
-        if (resultEntityName != null) {
-            encoder.print("\" result-entity=\"");
-            encoder.print(resultEntityName);
-        }
-
-        encoder.println("\">");
-        encoder.indent(1);
-
-        // print properties
-        for (Map.Entry<String, String> property : properties.entrySet()) {
-            encoder.printProperty(property.getKey(), property.getValue());
-        }
-
-        encoder.indent(-1);
-        encoder.println("</query>");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/Query.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/Query.java b/cayenne-server/src/main/java/org/apache/cayenne/query/Query.java
index 62341d8..0dbfc92 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/Query.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/Query.java
@@ -24,6 +24,7 @@ import java.io.Serializable;
 import org.apache.cayenne.access.QueryEngine;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.QueryDescriptor;
 
 /**
  * Defines minimal API of a query descriptor that is executable via Cayenne.

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/QueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/QueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/query/QueryDescriptor.java
deleted file mode 100644
index d058820..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/QueryDescriptor.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    http://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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.configuration.ConfigurationNode;
-import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
-import org.apache.cayenne.map.*;
-import org.apache.cayenne.util.XMLEncoder;
-import org.apache.cayenne.util.XMLSerializable;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Generic descriptor of a Cayenne query.
- *
- * @since 4.0
- */
-public class QueryDescriptor implements Serializable, ConfigurationNode, XMLSerializable {
-
-    public static final String SELECT_QUERY = "SelectQuery";
-    public static final String SQL_TEMPLATE = "SQLTemplate";
-    public static final String EJBQL_QUERY = "EJBQLQuery";
-    public static final String PROCEDURE_QUERY = "ProcedureQuery";
-
-    /**
-     * Creates new SelectQuery query descriptor.
-     */
-    public static SelectQueryDescriptor selectQueryDescriptor() {
-        return new SelectQueryDescriptor();
-    }
-
-    /**
-     * Creates new SQLTemplate query descriptor.
-     */
-    public static SQLTemplateDescriptor sqlTemplateDescriptor() {
-        return new SQLTemplateDescriptor();
-    }
-
-    /**
-     * Creates new ProcedureQuery query descriptor.
-     */
-    public static ProcedureQueryDescriptor procedureQueryDescriptor() {
-        return new ProcedureQueryDescriptor();
-    }
-
-    /**
-     * Creates new EJBQLQuery query descriptor.
-     */
-    public static EJBQLQueryDescriptor ejbqlQueryDescriptor() {
-        return new EJBQLQueryDescriptor();
-    }
-
-    /**
-     * Creates query descriptor of a given type.
-     */
-    public static QueryDescriptor descriptor(String type) {
-        switch (type) {
-            case SELECT_QUERY:
-                return selectQueryDescriptor();
-            case SQL_TEMPLATE:
-                return sqlTemplateDescriptor();
-            case EJBQL_QUERY:
-                return ejbqlQueryDescriptor();
-            case PROCEDURE_QUERY:
-                return procedureQueryDescriptor();
-            default:
-                QueryDescriptor descriptor = new QueryDescriptor();
-                descriptor.setType(type);
-                return descriptor;
-        }
-    }
-
-    protected String name;
-    protected String type;
-    protected DataMap dataMap;
-    protected Object root;
-
-    protected Map<String, String> properties = new HashMap<>();
-
-    protected QueryDescriptor() {
-
-    }
-
-    /**
-     * Returns name of the query.
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
-     * Sets name of the query.
-     */
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    /**
-     * Returns type of the query.
-     */
-    public String getType() {
-        return type;
-    }
-
-    /**
-     * Sets type of the query.
-     */
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public DataMap getDataMap() {
-        return dataMap;
-    }
-
-    public void setDataMap(DataMap dataMap) {
-        this.dataMap = dataMap;
-    }
-
-    /**
-     * Returns the root of this query.
-     */
-    public Object getRoot() {
-        return root;
-    }
-
-    /**
-     * Sets the root of this query.
-     */
-    public void setRoot(Object root) {
-        this.root = root;
-    }
-
-    /**
-     * Returns map of query properties set up for this query.
-     */
-    public Map<String, String> getProperties() {
-        return properties;
-    }
-
-    /**
-     * Returns query property by its name.
-     */
-    public String getProperty(String name) {
-        return properties.get(name);
-    }
-
-    /**
-     * Sets map of query properties for this query.
-     */
-    public void setProperties(Map<String, String> properties) {
-        this.properties = properties;
-    }
-
-    /**
-     * Sets single query property.
-     */
-    public void setProperty(String name, String value) {
-        this.properties.put(name, value);
-    }
-
-    /**
-     * Assembles Cayenne query instance of appropriate type from this descriptor.
-     */
-    public Query buildQuery() {
-        throw new CayenneRuntimeException("Unable to build query object of this type.");
-    }
-
-    @Override
-    public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor) {
-        return visitor.visitQuery(this);
-    }
-
-    @Override
-    public void encodeAsXML(XMLEncoder encoder) {
-        encoder.print("<query name=\"");
-        encoder.print(getName());
-        encoder.print("\" type=\"");
-        encoder.print(type);
-
-        String rootString = null;
-        String rootType = null;
-
-        if (root instanceof String) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = root.toString();
-        } else if (root instanceof ObjEntity) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = ((ObjEntity) root).getName();
-        } else if (root instanceof DbEntity) {
-            rootType = MapLoader.DB_ENTITY_ROOT;
-            rootString = ((DbEntity) root).getName();
-        } else if (root instanceof Procedure) {
-            rootType = MapLoader.PROCEDURE_ROOT;
-            rootString = ((Procedure) root).getName();
-        } else if (root instanceof Class<?>) {
-            rootType = MapLoader.JAVA_CLASS_ROOT;
-            rootString = ((Class<?>) root).getName();
-        }
-
-        if (rootType != null) {
-            encoder.print("\" root=\"");
-            encoder.print(rootType);
-            encoder.print("\" root-name=\"");
-            encoder.print(rootString);
-        }
-
-        encoder.println("\">");
-
-        encoder.indent(1);
-
-        for (Map.Entry<String, String> property : properties.entrySet()) {
-            encoder.printProperty(property.getKey(), property.getValue());
-        }
-
-        encoder.indent(-1);
-        encoder.println("</query>");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/SQLTemplateDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLTemplateDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLTemplateDescriptor.java
deleted file mode 100644
index 9728565..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLTemplateDescriptor.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    http://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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.map.*;
-import org.apache.cayenne.util.XMLEncoder;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeSet;
-
-public class SQLTemplateDescriptor extends QueryDescriptor {
-
-    protected String sql;
-
-    protected Map<String, String> adapterSql = new HashMap<>();
-
-    public SQLTemplateDescriptor() {
-        this.type = SQL_TEMPLATE;
-    }
-
-    /**
-     * Returns default SQL statement for this query.
-     */
-    public String getSql() {
-        return sql;
-    }
-
-    /**
-     * Sets default SQL statement for this query.
-     */
-    public void setSql(String sql) {
-        this.sql = sql;
-    }
-
-    /**
-     * Returns map of db adapter specific SQL statements.
-     */
-    public Map<String, String> getAdapterSql() {
-        return adapterSql;
-    }
-
-    /**
-     * Sets a map db adapter specific SQL statements for this query.
-     */
-    public void setAdapterSql(Map<String, String> adapterSql) {
-        this.adapterSql = adapterSql;
-    }
-
-    @Override
-    public SQLTemplate buildQuery() {
-        SQLTemplate template = new SQLTemplate();
-
-        if (root != null) {
-            template.setRoot(root);
-        }
-
-        template.setName(name);
-        template.setDataMap(dataMap);
-        template.initWithProperties(this.getProperties());
-
-        // init SQL
-        template.setDefaultTemplate(this.getSql());
-
-        Map<String, String> adapterSql = this.getAdapterSql();
-
-        if (adapterSql != null) {
-            for (Map.Entry<String, String> entry : adapterSql.entrySet()) {
-                String key = entry.getKey();
-                String value = entry.getValue();
-                if (key != null && value != null) {
-                    template.setTemplate(key, value);
-                }
-            }
-        }
-
-        return template;
-    }
-
-    @Override
-    public void encodeAsXML(XMLEncoder encoder) {
-        encoder.print("<query name=\"");
-        encoder.print(getName());
-        encoder.print("\" type=\"");
-        encoder.print(type);
-
-        String rootString = null;
-        String rootType = null;
-
-        if (root instanceof String) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = root.toString();
-        } else if (root instanceof ObjEntity) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = ((ObjEntity) root).getName();
-        } else if (root instanceof DbEntity) {
-            rootType = MapLoader.DB_ENTITY_ROOT;
-            rootString = ((DbEntity) root).getName();
-        } else if (root instanceof Procedure) {
-            rootType = MapLoader.PROCEDURE_ROOT;
-            rootString = ((Procedure) root).getName();
-        } else if (root instanceof Class<?>) {
-            rootType = MapLoader.JAVA_CLASS_ROOT;
-            rootString = ((Class<?>) root).getName();
-        } else if (root instanceof DataMap) {
-            rootType = MapLoader.DATA_MAP_ROOT;
-            rootString = ((DataMap) root).getName();
-        }
-
-        if (rootType != null) {
-            encoder.print("\" root=\"");
-            encoder.print(rootType);
-            encoder.print("\" root-name=\"");
-            encoder.print(rootString);
-        }
-
-        encoder.println("\">");
-
-        encoder.indent(1);
-
-        // print properties
-        for (Map.Entry<String, String> property : properties.entrySet()) {
-            encoder.printProperty(property.getKey(), property.getValue());
-        }
-
-        // encode default SQL
-        if (sql != null) {
-            encoder.print("<sql><![CDATA[");
-            encoder.print(sql);
-            encoder.println("]]></sql>");
-        }
-
-        // encode adapter SQL
-        if (adapterSql != null && !adapterSql.isEmpty()) {
-
-            // sorting entries by adapter name
-            TreeSet<String> keys = new TreeSet<String>(adapterSql.keySet());
-            for (String key : keys) {
-                String value = adapterSql.get(key);
-
-                if (key != null && value != null) {
-                    String sql = value.trim();
-                    if (sql.length() > 0) {
-                        encoder.print("<sql adapter-class=\"");
-                        encoder.print(key);
-                        encoder.print("\"><![CDATA[");
-                        encoder.print(sql);
-                        encoder.println("]]></sql>");
-                    }
-                }
-            }
-        }
-
-        encoder.indent(-1);
-        encoder.println("</query>");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryDescriptor.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryDescriptor.java
deleted file mode 100644
index bd50f6f..0000000
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryDescriptor.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    http://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.
- ****************************************************************/
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.MapLoader;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.Procedure;
-import org.apache.cayenne.util.XMLEncoder;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class SelectQueryDescriptor extends QueryDescriptor {
-
-    protected Expression qualifier;
-
-    protected List<Ordering> orderings = new ArrayList<>();
-    protected List<String> prefetches = new ArrayList<>();
-
-    public SelectQueryDescriptor() {
-        this.type = SELECT_QUERY;
-    }
-
-    public void setDistinct(boolean value) {
-        setProperty(SelectQuery.DISTINCT_PROPERTY, String.valueOf(value));
-    }
-
-    public boolean isDistinct() {
-        String distinct = getProperty(SelectQuery.DISTINCT_PROPERTY);
-
-        return distinct != null ? Boolean.valueOf(distinct) : false;
-    }
-
-    /**
-     * Returns qualifier of this query.
-     */
-    public Expression getQualifier() {
-        return qualifier;
-    }
-
-    /**
-     * Sets qualifier for this query.
-     */
-    public void setQualifier(Expression qualifier) {
-        this.qualifier = qualifier;
-    }
-
-    /**
-     * Returns list of orderings for this query.
-     */
-    public List<Ordering> getOrderings() {
-        return orderings;
-    }
-
-    /**
-     * Sets list of orderings for this query.
-     */
-    public void setOrderings(List<Ordering> orderings) {
-        this.orderings = orderings;
-    }
-
-    /**
-     * Adds single ordering for this query.
-     */
-    public void addOrdering(Ordering ordering) {
-        this.orderings.add(ordering);
-    }
-
-    /**
-     * Removes single ordering from this query.
-     */
-    public void removeOrdering(Ordering ordering) {
-        this.orderings.remove(ordering);
-    }
-
-    /**
-     * Returns list of prefetch paths for this query.
-     */
-    public List<String> getPrefetches() {
-        return prefetches;
-    }
-
-    /**
-     * Sets list of prefetch paths for this query.
-     */
-    public void setPrefetches(List<String> prefetches) {
-        this.prefetches = prefetches;
-    }
-
-    /**
-     * Adds single prefetch path to this query.
-     */
-    public void addPrefetch(String prefetchPath) {
-        this.prefetches.add(prefetchPath);
-    }
-
-    /**
-     * Removes single prefetch path from this query.
-     */
-    public void removePrefetch(String prefetchPath) {
-        this.prefetches.remove(prefetchPath);
-    }
-
-    @Override
-    public SelectQuery<?> buildQuery() {
-        SelectQuery<Object> selectQuery = new SelectQuery<>();
-        selectQuery.setRoot(this.getRoot());
-        selectQuery.setName(this.getName());
-        selectQuery.setDataMap(dataMap);
-        selectQuery.setQualifier(this.getQualifier());
-
-        List<Ordering> orderings = this.getOrderings();
-
-        if (orderings != null && !orderings.isEmpty()) {
-            selectQuery.addOrderings(orderings);
-        }
-
-        List<String> prefetches = this.getPrefetches();
-
-        if (prefetches != null && !prefetches.isEmpty()) {
-            for (String prefetch : prefetches) {
-                selectQuery.addPrefetch(prefetch);
-            }
-        }
-
-        // init properties
-        selectQuery.initWithProperties(this.getProperties());
-
-        return selectQuery;
-    }
-
-    @Override
-    public void encodeAsXML(XMLEncoder encoder) {
-        encoder.print("<query name=\"");
-        encoder.print(getName());
-        encoder.print("\" type=\"");
-        encoder.print(type);
-
-        String rootString = null;
-        String rootType = null;
-
-        if (root instanceof String) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = root.toString();
-        } else if (root instanceof ObjEntity) {
-            rootType = MapLoader.OBJ_ENTITY_ROOT;
-            rootString = ((ObjEntity) root).getName();
-        } else if (root instanceof DbEntity) {
-            rootType = MapLoader.DB_ENTITY_ROOT;
-            rootString = ((DbEntity) root).getName();
-        } else if (root instanceof Procedure) {
-            rootType = MapLoader.PROCEDURE_ROOT;
-            rootString = ((Procedure) root).getName();
-        } else if (root instanceof Class<?>) {
-            rootType = MapLoader.JAVA_CLASS_ROOT;
-            rootString = ((Class<?>) root).getName();
-        }
-
-        if (rootType != null) {
-            encoder.print("\" root=\"");
-            encoder.print(rootType);
-            encoder.print("\" root-name=\"");
-            encoder.print(rootString);
-        }
-
-        encoder.println("\">");
-
-        encoder.indent(1);
-
-        // print properties
-        for (Map.Entry<String, String> property : properties.entrySet()) {
-            encoder.printProperty(property.getKey(), property.getValue());
-        }
-
-        // encode qualifier
-        if (qualifier != null) {
-            encoder.print("<qualifier>");
-            qualifier.encodeAsXML(encoder);
-            encoder.println("</qualifier>");
-        }
-
-        // encode orderings
-        if (orderings != null && !orderings.isEmpty()) {
-            for (Ordering ordering : orderings) {
-                ordering.encodeAsXML(encoder);
-            }
-        }
-
-        PrefetchTreeNode prefetchTree = new PrefetchTreeNode();
-
-        for (String prefetchPath : prefetches) {
-            PrefetchTreeNode node = prefetchTree.addPath(prefetchPath);
-            node.setSemantics(PrefetchTreeNode.UNDEFINED_SEMANTICS);
-            node.setPhantom(false);
-        }
-
-        prefetchTree.encodeAsXML(encoder);
-
-        encoder.indent(-1);
-        encoder.println("</query>");
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapNamespaceTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapNamespaceTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapNamespaceTest.java
index 30ed699..b60dcd1 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapNamespaceTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapNamespaceTest.java
@@ -19,7 +19,6 @@
 
 package org.apache.cayenne.map;
 
-import org.apache.cayenne.query.QueryDescriptor;
 import org.junit.Before;
 import org.junit.Test;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapTest.java
index 4fa8d33..87be992 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/DataMapTest.java
@@ -19,7 +19,6 @@
 
 package org.apache.cayenne.map;
 
-import org.apache.cayenne.query.QueryDescriptor;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.util.XMLEncoder;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
index 058a970..56f28ca 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
@@ -23,7 +23,6 @@ import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.QueryDescriptor;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java b/cayenne-server/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
index 8c932e8..73cc8ff 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/MockMappingNamespace.java
@@ -24,8 +24,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.cayenne.Persistent;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
 
 public class MockMappingNamespace implements MappingNamespace {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-server/src/test/java/org/apache/cayenne/map/naming/NameCheckersTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/naming/NameCheckersTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/naming/NameCheckersTest.java
index 03102f5..ad67222 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/naming/NameCheckersTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/naming/NameCheckersTest.java
@@ -35,7 +35,7 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.junit.Assert;
 import org.junit.Test;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index d333919..f7471a6 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -33,7 +33,7 @@ import org.apache.cayenne.access.loader.NamePatternMatcher;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.commons.logging.Log;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
index 1953e34..0b9a555 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientClassGenerationAction.java
@@ -21,8 +21,7 @@ package org.apache.cayenne.gen;
 import java.util.Collection;
 
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 
 /**
  * @since 3.0

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientDataMapArtifact.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientDataMapArtifact.java b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientDataMapArtifact.java
index e5d90d5..0e6da3e 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientDataMapArtifact.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/gen/ClientDataMapArtifact.java
@@ -23,7 +23,7 @@ import java.util.Collection;
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.naming.NameConverter;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.util.Util;
 
 public class ClientDataMapArtifact extends DataMapArtifact {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-tools/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java b/cayenne-tools/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
index 294a381..838f1c6 100644
--- a/cayenne-tools/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
+++ b/cayenne-tools/src/main/java/org/apache/cayenne/gen/DataMapArtifact.java
@@ -23,7 +23,7 @@ import java.util.Collection;
 import java.util.LinkedList;
 
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.query.*;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.apache.cayenne.map.naming.NameConverter;
 import org.apache.velocity.VelocityContext;
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
index 0bf1058..9379e21 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
@@ -23,7 +23,7 @@ import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3e2b0649/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/configuration/event/QueryEvent.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/configuration/event/QueryEvent.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/configuration/event/QueryEvent.java
index 2cff378..58150e6 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/configuration/event/QueryEvent.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/configuration/event/QueryEvent.java
@@ -21,7 +21,7 @@ package org.apache.cayenne.configuration.event;
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.event.MapEvent;
-import org.apache.cayenne.query.QueryDescriptor;
+import org.apache.cayenne.map.QueryDescriptor;
 
 /**
  * An event generated when a Query object is added to a DataMap, 


Mime
View raw message