You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/09/28 18:57:39 UTC
svn commit: r1002262 - in
/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server:
chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/
chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistr...
Author: fguillaume
Date: Tue Sep 28 16:57:39 2010
New Revision: 1002262
URL: http://svn.apache.org/viewvc?rev=1002262&view=rev
Log:
Make QueryObject/CmisSelector more reusable, add new ClauseWalker-based interface, use it in InMemoryQueryProcessor
Added:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java (with props)
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java (with props)
Modified:
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisSelector.java
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java?rev=1002262&r1=1002261&r2=1002262&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryProcessor.java Tue Sep 28 16:57:39 2010
@@ -15,6 +15,10 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
+ *
+ * Contributors:
+ * Jens Huebel
+ * Florent Guillaume, Nuxeo
*/
package org.apache.chemistry.opencmis.inmemory.query;
@@ -51,7 +55,7 @@ import org.apache.chemistry.opencmis.inm
import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
import org.apache.chemistry.opencmis.server.support.TypeManager;
import org.apache.chemistry.opencmis.server.support.query.AbstractQueryConditionProcessor;
-import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictLexer;
+import org.apache.chemistry.opencmis.server.support.query.AbstractClauseWalker;
import org.apache.chemistry.opencmis.server.support.query.CmisQueryWalker;
import org.apache.chemistry.opencmis.server.support.query.CmisSelector;
import org.apache.chemistry.opencmis.server.support.query.ColumnReference;
@@ -67,9 +71,6 @@ import org.apache.commons.logging.LogFac
* with all objects. In a first pass one time setup is performed, in a custom
* walk across the query expression tree an object is checked if it matches. In
* case of a match it is appended to a list of matching objects.
- *
- * @author Jens
- *
*/
public class InMemoryQueryProcessor extends AbstractQueryConditionProcessor {
@@ -377,345 +378,282 @@ public class InMemoryQueryProcessor exte
* @return true if it matches, false if it not matches
*/
boolean evalWhereNode(StoredObject so, Tree node) {
- boolean matches = true;
-
- switch (node.getType()) {
- case CmisQlStrictLexer.WHERE:
- matches = evalWhereNode(so, node.getChild(0));
- break; // ignore
- case CmisQlStrictLexer.EQ:
- matches = evalWhereEquals(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.NEQ:
- matches = evalWhereNotEquals(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.GT:
- matches = evalWhereGreaterThan(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.GTEQ:
- matches = evalWhereGreaterOrEquals(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.LT:
- matches = evalWhereLessThan(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.LTEQ:
- matches = evalWhereLessOrEquals(so, node, node.getChild(0), node.getChild(1));
- break;
-
- case CmisQlStrictLexer.NOT:
- matches = evalWhereNot(so, node, node.getChild(0));
- break;
- case CmisQlStrictLexer.AND:
- matches = evalWhereAnd(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.OR:
- matches = evalWhereOr(so, node, node.getChild(0), node.getChild(1));
- break;
-
- // Multi-value:
- case CmisQlStrictLexer.IN:
- matches = evalWhereIn(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.NOT_IN:
- matches = evalWhereNotIn(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.IN_ANY:
- matches = evalWhereInAny(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.NOT_IN_ANY:
- matches = evalWhereNotInAny(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.EQ_ANY:
- matches = evalWhereEqAny(so, node, node.getChild(0), node.getChild(1));
- break;
+ return new InMemoryWhereClauseWalker(so).walkClause(node);
+ }
- // Null comparisons:
- case CmisQlStrictLexer.IS_NULL:
- matches = evalWhereIsNull(so, node, node.getChild(0));
- break;
- case CmisQlStrictLexer.IS_NOT_NULL:
- matches = evalWhereIsNotNull(so, node, node.getChild(0));
- break;
+ public class InMemoryWhereClauseWalker extends AbstractClauseWalker {
- // String matching
- case CmisQlStrictLexer.LIKE:
- matches = evalWhereIsLike(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.NOT_LIKE:
- matches = evalWhereIsNotLike(so, node, node.getChild(0), node.getChild(1));
- break;
+ protected StoredObject so;
- // Functions
- case CmisQlStrictLexer.CONTAINS:
- if (node.getChildCount() == 1)
- matches = evalWhereContains(so, node, null, node.getChild(0));
- else
- matches = evalWhereContains(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.IN_FOLDER:
- if (node.getChildCount() == 1)
- matches = evalWhereInFolder(so, node, null, node.getChild(0));
- else
- matches = evalWhereInFolder(so, node, node.getChild(0), node.getChild(1));
- break;
- case CmisQlStrictLexer.IN_TREE:
- if (node.getChildCount() == 1)
- matches = evalWhereInTree(so, node, null, node.getChild(0));
- else
- matches = evalWhereInTree(so, node, node.getChild(0), node.getChild(1));
- break;
+ public InMemoryWhereClauseWalker(StoredObject so) {
+ this.so = so;
+ }
- default:
- // do nothing;
+ @Override
+ public boolean walkNot(Tree opNode, Tree node) {
+ boolean matches = walkClause(node);
+ return !matches;
}
- return matches;
- }
+ @Override
+ public boolean walkAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+ boolean matches1 = walkClause(leftNode);
+ boolean matches2 = walkClause(rightNode);
+ return matches1 && matches2;
+ }
- private boolean evalWhereEquals(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp == 0;
- }
+ @Override
+ public boolean walkOr(Tree opNode, Tree leftNode, Tree rightNode) {
+ boolean matches1 = walkClause(leftNode);
+ boolean matches2 = walkClause(rightNode);
+ return matches1 || matches2;
+ }
- private boolean evalWhereNotEquals(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp != 0;
- }
+ @Override
+ public boolean walkEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp == 0;
+ }
- private boolean evalWhereGreaterThan(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp > 0;
- }
+ @Override
+ public boolean walkNotEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp != 0;
+ }
- private boolean evalWhereGreaterOrEquals(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp >= 0;
- }
+ @Override
+ public boolean walkGreaterThan(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp > 0;
+ }
- private boolean evalWhereLessThan(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp < 0;
- }
+ @Override
+ public boolean walkGreaterOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp >= 0;
+ }
- private boolean evalWhereLessOrEquals(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- Integer cmp = compareTo(so, leftChild, rightChild);
- if (null == cmp)
- return false; // property is not set
- else
- return cmp <= 0;
- }
+ @Override
+ public boolean walkLessThan(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp < 0;
+ }
- private boolean evalWhereNot(StoredObject so, Tree node, Tree child) {
- boolean matches = evalWhereNode(so, child);
- return !matches;
- }
+ @Override
+ public boolean walkLessOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ Integer cmp = compareTo(leftNode, rightNode);
+ return cmp == null ? false : cmp <= 0;
+ }
- private boolean evalWhereAnd(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- boolean matches1 = evalWhereNode(so, leftChild);
- boolean matches2 = evalWhereNode(so, rightChild);
- return matches1 && matches2;
- }
+ @Override
+ public boolean walkIn(Tree opNode, Tree colNode, Tree listNode) {
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ List<Object> literals = onLiteralList(listNode);
+ if (pd.getCardinality() != Cardinality.SINGLE)
+ throw new RuntimeException("Operator IN only is allowed on single-value properties ");
+ else if (lVal == null)
+ return false;
+ else {
+ Object prop = lVal.getFirstValue();
+ if (literals.contains(prop))
+ return true;
+ else
+ return false;
+ }
+ }
- private boolean evalWhereOr(StoredObject so, Tree node, Tree leftChild, Tree rightChild) {
- boolean matches1 = evalWhereNode(so, leftChild);
- boolean matches2 = evalWhereNode(so, rightChild);
- return matches1 || matches2;
- }
+ @Override
+ public boolean walkNotIn(Tree opNode, Tree colNode, Tree listNode) {
+ // Note just return !walkIn(node, colNode, listNode) is wrong,
+ // because
+ // then it evaluates to true for null values (not set properties).
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ List<Object> literals = onLiteralList(listNode);
+ if (pd.getCardinality() != Cardinality.SINGLE)
+ throw new RuntimeException("Operator IN only is allowed on single-value properties ");
+ else if (lVal == null)
+ return false;
+ else {
+ Object prop = lVal.getFirstValue();
+ if (literals.contains(prop))
+ return false;
+ else
+ return true;
+ }
+ }
- private boolean evalWhereIn(StoredObject so, Tree node, Tree colNode, Tree listNode) {
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- List<Object> literals = onLiteralList(listNode);
- if (pd.getCardinality() != Cardinality.SINGLE)
- throw new RuntimeException("Operator IN only is allowed on single-value properties ");
- else if (lVal == null)
- return false;
- else {
- Object prop = lVal.getFirstValue();
- if (literals.contains(prop))
- return true;
- else
+ @Override
+ public boolean walkInAny(Tree opNode, Tree colNode, Tree listNode) {
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ List<Object> literals = onLiteralList(listNode);
+ if (pd.getCardinality() != Cardinality.MULTI)
+ throw new RuntimeException("Operator ANY...IN only is allowed on multi-value properties ");
+ else if (lVal == null)
+ return false;
+ else {
+ List<?> props = lVal.getValues();
+ for (Object prop : props) {
+ LOG.debug("comparing with: " + prop);
+ if (literals.contains(prop))
+ return true;
+ }
return false;
+ }
}
- }
- private boolean evalWhereNotIn(StoredObject so, Tree node, Tree colNode, Tree listNode) {
- // Note just return !evalWhereIn(so, node, colNode, listNode) is wrong,
- // because
- // then it evaluates to true for null values (not set properties).
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- List<Object> literals = onLiteralList(listNode);
- if (pd.getCardinality() != Cardinality.SINGLE)
- throw new RuntimeException("Operator IN only is allowed on single-value properties ");
- else if (lVal == null)
- return false;
- else {
- Object prop = lVal.getFirstValue();
- if (literals.contains(prop))
+ @Override
+ public boolean walkNotInAny(Tree opNode, Tree colNode, Tree listNode) {
+ // Note just return !walkNotInAny(node, colNode, listNode) is
+ // wrong, because
+ // then it evaluates to true for null values (not set properties).
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ List<Object> literals = onLiteralList(listNode);
+ if (pd.getCardinality() != Cardinality.MULTI)
+ throw new RuntimeException("Operator ANY...IN only is allowed on multi-value properties ");
+ else if (lVal == null)
return false;
- else
+ else {
+ List<?> props = lVal.getValues();
+ for (Object prop : props) {
+ LOG.debug("comparing with: " + prop);
+ if (literals.contains(prop))
+ return false;
+ }
return true;
+ }
}
- }
- private boolean evalWhereInAny(StoredObject so, Tree node, Tree colNode, Tree listNode) {
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- List<Object> literals = onLiteralList(listNode);
- if (pd.getCardinality() != Cardinality.MULTI)
- throw new RuntimeException("Operator ANY...IN only is allowed on multi-value properties ");
- else if (lVal == null)
- return false;
- else {
- List<?> props = lVal.getValues();
- for (Object prop : props) {
- LOG.debug("comparing with: " + prop);
- if (literals.contains(prop))
+ @Override
+ public boolean walkEqAny(Tree opNode, Tree literalNode, Tree colNode) {
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ Object literal = onLiteral(literalNode);
+ if (pd.getCardinality() != Cardinality.MULTI)
+ throw new RuntimeException("Operator = ANY only is allowed on multi-value properties ");
+ else if (lVal == null)
+ return false;
+ else {
+ List<?> props = lVal.getValues();
+ if (props.contains(literal))
return true;
+ else
+ return false;
}
- return false;
}
- }
- private boolean evalWhereNotInAny(StoredObject so, Tree node, Tree colNode, Tree listNode) {
- // Note just return !evalWhereInAny(so, node, colNode, listNode) is
- // wrong, because
- // then it evaluates to true for null values (not set properties).
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- List<Object> literals = onLiteralList(listNode);
- if (pd.getCardinality() != Cardinality.MULTI)
- throw new RuntimeException("Operator ANY...IN only is allowed on multi-value properties ");
- else if (lVal == null)
- return false;
- else {
- List<?> props = lVal.getValues();
- for (Object prop : props) {
- LOG.debug("comparing with: " + prop);
- if (literals.contains(prop))
- return false;
+ @Override
+ public boolean walkIsNull(Tree opNode, Tree colNode) {
+ Object propVal = getPropertyValue(colNode, so);
+ return propVal == null;
+ }
+
+ @Override
+ public boolean walkIsNotNull(Tree opNode, Tree colNode) {
+ Object propVal = getPropertyValue(colNode, so);
+ return propVal != null;
+ }
+
+ @Override
+ public boolean walkLike(Tree opNode, Tree colNode, Tree stringNode) {
+ Object rVal = onLiteral(stringNode);
+ if (!(rVal instanceof String))
+ throw new RuntimeException("LIKE operator requires String literal on right hand side.");
+
+ ColumnReference colRef = getColumnReference(colNode);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyType propType = pd.getPropertyType();
+ if (propType != PropertyType.STRING && propType != PropertyType.HTML && propType != PropertyType.ID
+ && propType != PropertyType.URI)
+ throw new RuntimeException("Property type " + propType.value() + " is not allowed FOR LIKE");
+ if (pd.getCardinality() != Cardinality.SINGLE)
+ throw new RuntimeException("LIKE is not allowed for multi-value properties ");
+
+ String propVal = (String) so.getProperties().get(colRef.getPropertyId()).getFirstValue();
+ String pattern = translatePattern((String) rVal); // SQL to Java
+ // regex
+ // syntax
+ Pattern p = Pattern.compile(pattern);
+ return p.matcher(propVal).matches();
+ }
+
+ @Override
+ public boolean walkNotLike(Tree opNode, Tree colNode, Tree stringNode) {
+ return !walkLike(opNode, colNode, stringNode);
+ }
+
+ @Override
+ public boolean walkContains(Tree opNode, Tree colNode, Tree queryNode) {
+ throw new RuntimeException("Operator CONTAINS not supported in InMemory server.");
+ }
+
+ @Override
+ public boolean walkInFolder(Tree opNode, Tree colNode, Tree paramNode) {
+ if (null != colNode) {
+ getTableReference(colNode);
+ // just for error checking we do not evaluate this, there is
+ // only one from without join support
}
- return true;
+ Object lit = onLiteral(paramNode);
+ if (!(lit instanceof String))
+ throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
+ String folderId = (String) lit;
+
+ // check if object is in folder
+ if (so instanceof Filing)
+ return hasParent((Filing) so, folderId);
+ else
+ return false;
}
- }
- private boolean evalWhereEqAny(StoredObject so, Tree node, Tree literalNode, Tree colNode) {
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- Object literal = onLiteral(literalNode);
- if (pd.getCardinality() != Cardinality.MULTI)
- throw new RuntimeException("Operator = ANY only is allowed on multi-value properties ");
- else if (lVal == null)
- return false;
- else {
- List<?> props = lVal.getValues();
- if (props.contains(literal))
- return true;
+ @Override
+ public boolean walkInTree(Tree opNode, Tree colNode, Tree paramNode) {
+ if (null != colNode) {
+ getTableReference(colNode);
+ // just for error checking we do not evaluate this, there is
+ // only
+ // one from without join support
+ }
+ Object lit = onLiteral(paramNode);
+ if (!(lit instanceof String))
+ throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
+ String folderId = (String) lit;
+
+ // check if object is in folder
+ if (so instanceof Filing)
+ return hasAncestor((Filing) so, folderId);
else
return false;
}
- }
-
- private boolean evalWhereIsNull(StoredObject so, Tree node, Tree child) {
- Object propVal = getPropertyValue(child, so);
- return null == propVal;
- }
-
- private boolean evalWhereIsNotNull(StoredObject so, Tree node, Tree child) {
- Object propVal = getPropertyValue(child, so);
- return null != propVal;
- }
-
- private boolean evalWhereIsLike(StoredObject so, Tree node, Tree colNode, Tree StringNode) {
- Object rVal = onLiteral(StringNode);
- if (!(rVal instanceof String))
- throw new RuntimeException("LIKE operator requires String literal on right hand side.");
- ColumnReference colRef = getColumnReference(colNode);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyType propType = pd.getPropertyType();
- if (propType != PropertyType.STRING && propType != PropertyType.HTML && propType != PropertyType.ID
- && propType != PropertyType.URI)
- throw new RuntimeException("Property type " + propType.value() + " is not allowed FOR LIKE");
- if (pd.getCardinality() != Cardinality.SINGLE)
- throw new RuntimeException("LIKE is not allowed for multi-value properties ");
-
- String propVal = (String) so.getProperties().get(colRef.getPropertyId()).getFirstValue();
- String pattern = translatePattern((String) rVal); // SQL to Java regex
- // syntax
- Pattern p = Pattern.compile(pattern);
- return p.matcher(propVal).matches();
- }
-
- private boolean evalWhereIsNotLike(StoredObject so, Tree node, Tree colNode, Tree stringNode) {
- return !evalWhereIsLike(so, node, colNode, stringNode);
- }
-
- private boolean evalWhereContains(StoredObject so, Tree node, Tree colNode, Tree paramNode) {
- throw new RuntimeException("Operator CONTAINS not supported in InMemory server.");
- }
-
- private boolean evalWhereInFolder(StoredObject so, Tree node, Tree colNode, Tree paramNode) {
- if (null != colNode) {
- getTableReference(colNode);
- // just for error checking we do not evaluate this, there is only
- // one from without join support
- }
- Object lit = onLiteral(paramNode);
- if (!(lit instanceof String))
- throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
- String folderId = (String) lit;
-
- // check if object is in folder
- if (so instanceof Filing)
- return hasParent((Filing) so, folderId);
- else
- return false;
- }
+ protected Integer compareTo(Tree leftChild, Tree rightChild) {
+ Object rVal = onLiteral(rightChild);
- private boolean evalWhereInTree(StoredObject so, Tree node, Tree colNode, Tree paramNode) {
- if (null != colNode) {
- getTableReference(colNode);
- // just for error checking we do not evaluate this, there is only
- // one from without join support
- }
- Object lit = onLiteral(paramNode);
- if (!(lit instanceof String))
- throw new RuntimeException("Folder id in IN_FOLDER must be of type String");
- String folderId = (String) lit;
-
- // check if object is in folder
- if (so instanceof Filing)
- return hasAncestor((Filing) so, folderId);
- else
- return false;
+ // log.debug("retrieve node from where: " +
+ // System.identityHashCode(leftChild) + " is " + leftChild);
+ ColumnReference colRef = getColumnReference(leftChild);
+ TypeDefinition td = colRef.getTypeDefinition();
+ PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
+ PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
+ if (lVal instanceof List<?>)
+ throw new RuntimeException("You can't query operators <, <=, ==, !=, >=, > on multi-value properties ");
+ else
+ return InMemoryQueryProcessor.this.compareTo(pd, lVal, rVal);
+ }
}
private boolean hasParent(Filing objInFolder, String folderId) {
@@ -739,22 +677,7 @@ public class InMemoryQueryProcessor exte
return false;
}
- private Integer compareTo(StoredObject so, Tree leftChild, Tree rightChild) {
- Object rVal = onLiteral(rightChild);
-
- // log.debug("retrieve node from where: " +
- // System.identityHashCode(leftChild) + " is " + leftChild);
- ColumnReference colRef = getColumnReference(leftChild);
- TypeDefinition td = colRef.getTypeDefinition();
- PropertyDefinition<?> pd = td.getPropertyDefinitions().get(colRef.getPropertyId());
- PropertyData<?> lVal = so.getProperties().get(colRef.getPropertyId());
- if (lVal instanceof List<?>)
- throw new RuntimeException("You can't query operators <, <=, ==, !=, >=, > on multi-value properties ");
- else
- return compareTo(pd, lVal, rVal);
- }
-
- private int compareTo(PropertyDefinition<?> td, PropertyData<?> lVal, Object rVal) {
+ protected int compareTo(PropertyDefinition<?> td, PropertyData<?> lVal, Object rVal) {
Object lValue = lVal.getFirstValue();
switch (td.getPropertyType()) {
case BOOLEAN:
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java?rev=1002262&r1=1002261&r2=1002262&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java Tue Sep 28 16:57:39 2010
@@ -31,9 +31,9 @@ import java.util.Map.Entry;
import org.antlr.runtime.tree.Tree;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.inmemory.TypeManagerImpl;
+import org.apache.chemistry.opencmis.server.support.query.AbstractQueryConditionProcessor;
import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictLexer;
-import org.apache.chemistry.opencmis.server.support.query.QueryConditionProcessor;
import org.apache.chemistry.opencmis.server.support.query.QueryObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,7 +45,7 @@ public class ProcessQueryTest extends Ab
private static Log log = LogFactory.getLog(ProcessQueryTest.class);
- static private class TestQueryProcessor implements QueryConditionProcessor {
+ static private class TestQueryProcessor extends AbstractQueryConditionProcessor {
private static final String ON_START = "onStartWasCalled";
private static final String ON_STOP = "onStopWasCalled";
@@ -334,42 +334,6 @@ public class ProcessQueryTest extends Ab
}
}
-
- public void onPostAnd(Tree opNode, Tree leftNode, Tree rightNode) {
- // TODO Auto-generated method stub
-
- }
-
-
- public void onPostNot(Tree opNode, Tree leftNode) {
- // TODO Auto-generated method stub
-
- }
-
-
- public void onPostOr(Tree opNode, Tree leftNode, Tree rightNode) {
- // TODO Auto-generated method stub
-
- }
-
-
- public void onPreAnd(Tree opNode, Tree leftNode, Tree rightNode) {
- // TODO Auto-generated method stub
-
- }
-
-
- public void onPreNot(Tree opNode, Tree leftNode) {
- // TODO Auto-generated method stub
-
- }
-
-
- public void onPreOr(Tree opNode, Tree leftNode, Tree rightNode) {
- // TODO Auto-generated method stub
-
- }
-
}
private TypeManagerImpl tm;
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java?rev=1002262&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java Tue Sep 28 16:57:39 2010
@@ -0,0 +1,271 @@
+/*
+ * 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.
+ *
+ * Contributors:
+ * Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.opencmis.server.support.query;
+
+import org.antlr.runtime.tree.Tree;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+
+/**
+ * Basic implementation walking a WHERE clause in lexical order.
+ * <p>
+ * The {@code walkXYZ} methods can be overridden to change the walking order.
+ */
+public abstract class AbstractClauseWalker implements ClauseWalker {
+
+ public boolean walkClause(Tree node) {
+ switch (node.getType()) {
+ case CmisQlStrictLexer.NOT:
+ return walkNot(node, node.getChild(0));
+ case CmisQlStrictLexer.AND:
+ return walkAnd(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.OR:
+ return walkOr(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.EQ:
+ return walkEquals(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.NEQ:
+ return walkNotEquals(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.GT:
+ return walkGreaterThan(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.GTEQ:
+ return walkGreaterOrEquals(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.LT:
+ return walkLessThan(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.LTEQ:
+ return walkLessOrEquals(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.IN:
+ return walkIn(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.NOT_IN:
+ return walkNotIn(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.IN_ANY:
+ return walkInAny(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.NOT_IN_ANY:
+ return walkNotInAny(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.EQ_ANY:
+ return walkEqAny(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.IS_NULL:
+ return walkIsNull(node, node.getChild(0));
+ case CmisQlStrictLexer.IS_NOT_NULL:
+ return walkIsNotNull(node, node.getChild(0));
+ case CmisQlStrictLexer.LIKE:
+ return walkLike(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.NOT_LIKE:
+ return walkNotLike(node, node.getChild(0), node.getChild(1));
+ case CmisQlStrictLexer.CONTAINS:
+ if (node.getChildCount() == 1) {
+ return walkContains(node, null, node.getChild(0));
+ } else {
+ return walkContains(node, node.getChild(0), node.getChild(1));
+ }
+ case CmisQlStrictLexer.IN_FOLDER:
+ if (node.getChildCount() == 1) {
+ return walkInFolder(node, null, node.getChild(0));
+ } else {
+ return walkInFolder(node, node.getChild(0), node.getChild(1));
+ }
+ case CmisQlStrictLexer.IN_TREE:
+ if (node.getChildCount() == 1) {
+ return walkInTree(node, null, node.getChild(0));
+ } else {
+ return walkInTree(node, node.getChild(0), node.getChild(1));
+ }
+ default:
+ return walkOtherClause(node);
+ }
+ }
+
+ /** For extensibility. */
+ protected boolean walkOtherClause(Tree node) {
+ throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
+ }
+
+ public boolean walkNot(Tree opNode, Tree node) {
+ walkClause(node);
+ return false;
+ }
+
+ public boolean walkAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkClause(leftNode);
+ walkClause(rightNode);
+ return false;
+ }
+
+ public boolean walkOr(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkClause(leftNode);
+ walkClause(rightNode);
+ return false;
+ }
+
+ public Object walkValue(Tree node) {
+ switch (node.getType()) {
+ case CmisQlStrictLexer.BOOL_LIT:
+ return walkBoolean(node);
+ case CmisQlStrictLexer.NUM_LIT:
+ return walkNumber(node);
+ case CmisQlStrictLexer.STRING_LIT:
+ return walkString(node);
+ case CmisQlStrictLexer.TIME_LIT:
+ return walkTimestamp(node);
+ case CmisQlStrictLexer.IN_LIST:
+ return walkInList(node);
+ case CmisQlStrictLexer.COL:
+ return walkCol(node);
+ default:
+ return walkOtherValue(node);
+ }
+ }
+
+ /** For extensibility. */
+ protected Object walkOtherValue(Tree node) {
+ throw new CmisRuntimeException("Unknown node type: " + node.getType() + " (" + node.getText() + ")");
+ }
+
+ public boolean walkEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkNotEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkGreaterThan(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkGreaterOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkLessThan(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkLessOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+ walkValue(leftNode);
+ walkValue(rightNode);
+ return false;
+ }
+
+ public boolean walkIn(Tree opNode, Tree colNode, Tree listNode) {
+ walkValue(colNode);
+ walkValue(listNode);
+ return false;
+ }
+
+ public boolean walkNotIn(Tree opNode, Tree colNode, Tree listNode) {
+ walkValue(colNode);
+ walkValue(listNode);
+ return false;
+ }
+
+ public boolean walkInAny(Tree opNode, Tree colNode, Tree listNode) {
+ walkValue(colNode);
+ walkValue(listNode);
+ return false;
+ }
+
+ public boolean walkNotInAny(Tree opNode, Tree colNode, Tree listNode) {
+ walkValue(colNode);
+ walkValue(listNode);
+ return false;
+ }
+
+ public boolean walkEqAny(Tree opNode, Tree literalNode, Tree colNode) {
+ walkValue(literalNode);
+ walkValue(colNode);
+ return false;
+ }
+
+ public boolean walkIsNull(Tree opNode, Tree colNode) {
+ walkValue(colNode);
+ return false;
+ }
+
+ public boolean walkIsNotNull(Tree opNode, Tree colNode) {
+ walkValue(colNode);
+ return false;
+ }
+
+ public boolean walkLike(Tree opNode, Tree colNode, Tree stringNode) {
+ walkValue(colNode);
+ walkValue(stringNode);
+ return false;
+ }
+
+ public boolean walkNotLike(Tree opNode, Tree colNode, Tree stringNode) {
+ walkValue(colNode);
+ walkValue(stringNode);
+ return false;
+ }
+
+ public boolean walkContains(Tree opNode, Tree colNode, Tree queryNode) {
+ walkValue(colNode);
+ walkValue(queryNode);
+ return false;
+ }
+
+ public boolean walkInFolder(Tree opNode, Tree colNode, Tree paramNode) {
+ walkValue(colNode);
+ walkValue(paramNode);
+ return false;
+ }
+
+ public boolean walkInTree(Tree opNode, Tree colNode, Tree paramNode) {
+ walkValue(colNode);
+ walkValue(paramNode);
+ return false;
+ }
+
+ public Object walkBoolean(Tree node) {
+ return null;
+ }
+
+ public Object walkNumber(Tree node) {
+ return null;
+ }
+
+ public Object walkString(Tree node) {
+ return null;
+ }
+
+ public Object walkTimestamp(Tree node) {
+ return null;
+ }
+
+ public Object walkInList(Tree node) {
+ return null;
+ }
+
+ public Object walkCol(Tree node) {
+ return null;
+ }
+
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractClauseWalker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java?rev=1002262&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java Tue Sep 28 16:57:39 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ *
+ * Contributors:
+ * Florent Guillaume, Nuxeo
+ */
+package org.apache.chemistry.opencmis.server.support.query;
+
+import org.antlr.runtime.tree.Tree;
+
+/**
+ * Interface for a tree walker of a WHERE clause.
+ * <p>
+ * Can be used to build another datastructure, or for direct value evaluation
+ * (thus the boolean return values for clauses, and Object for values).
+ * <p>
+ * The method {@link walkClause} is the entry point.
+ */
+public interface ClauseWalker {
+
+ boolean walkClause(Tree node);
+
+ boolean walkNot(Tree opNode, Tree leftNode);
+
+ boolean walkAnd(Tree opNode, Tree leftNode, Tree rightNode);
+
+ boolean walkOr(Tree opNode, Tree leftNode, Tree rightNode);
+
+ Object walkValue(Tree node);
+
+ boolean walkEquals(Tree eqNode, Tree leftNode, Tree rightNode);
+
+ boolean walkNotEquals(Tree neNode, Tree leftNode, Tree rightNode);
+
+ boolean walkGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode);
+
+ boolean walkGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode);
+
+ boolean walkLessThan(Tree ltNode, Tree leftNode, Tree rightNode);
+
+ boolean walkLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode);
+
+ boolean walkIn(Tree node, Tree colNode, Tree listNode);
+
+ boolean walkNotIn(Tree node, Tree colNode, Tree listNode);
+
+ boolean walkInAny(Tree node, Tree colNode, Tree listNode);
+
+ boolean walkNotInAny(Tree node, Tree colNode, Tree listNode);
+
+ boolean walkEqAny(Tree node, Tree literalNode, Tree colNode);
+
+ boolean walkIsNull(Tree nullNode, Tree colNode);
+
+ boolean walkIsNotNull(Tree notNullNode, Tree colNode);
+
+ boolean walkLike(Tree node, Tree colNode, Tree stringNode);
+
+ boolean walkNotLike(Tree node, Tree colNode, Tree stringNode);
+
+ boolean walkContains(Tree node, Tree colNode, Tree paramNode);
+
+ boolean walkInFolder(Tree node, Tree colNode, Tree paramNode);
+
+ boolean walkInTree(Tree node, Tree colNode, Tree paramNode);
+
+ Object walkBoolean(Tree node);
+
+ Object walkNumber(Tree node);
+
+ Object walkString(Tree node);
+
+ Object walkTimestamp(Tree node);
+
+ Object walkInList(Tree node);
+
+ Object walkCol(Tree node);
+
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/ClauseWalker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisSelector.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisSelector.java?rev=1002262&r1=1002261&r2=1002262&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisSelector.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisSelector.java Tue Sep 28 16:57:39 2010
@@ -19,14 +19,29 @@
package org.apache.chemistry.opencmis.server.support.query;
public abstract class CmisSelector {
- private String aliasName; // Alias name for a column (only in SELECT part set)
+
+ /** Alias name for a column (only in SELECT part set). */
+ public String aliasName;
+
+ /** Arbitrary info for this selector (used by servers during parsing). */
+ public Object info;
public void setAliasName(String alias) {
aliasName = alias;
}
-
+
public String getAliasName() {
return aliasName;
}
+
+ public void setInfo(Object info) {
+ this.info = info;
+ }
+
+ public Object getInfo() {
+ return info;
+ }
+
public abstract String getName();
+
}
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1002262&r1=1002261&r2=1002262&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java Tue Sep 28 16:57:39 2010
@@ -47,29 +47,29 @@ public class QueryObject {
// For error handling see:
// http://www.antlr.org/pipermail/antlr-interest/2008-April/027600.html
// select part
- private TypeManager typeMgr;
- private List<CmisSelector> selectReferences = new ArrayList<CmisSelector>();
- private List<CmisSelector> whereReferences = new ArrayList<CmisSelector>();
- private List<CmisSelector> joinReferences = new ArrayList<CmisSelector>();
+ protected TypeManager typeMgr;
+ protected List<CmisSelector> selectReferences = new ArrayList<CmisSelector>();
+ protected List<CmisSelector> whereReferences = new ArrayList<CmisSelector>();
+ protected List<CmisSelector> joinReferences = new ArrayList<CmisSelector>();
// --> Join not implemented yet
- private Map<String, CmisSelector> colOrFuncAlias = new HashMap<String, CmisSelector>();
- private QueryConditionProcessor queryProcessor;
+ protected Map<String, CmisSelector> colOrFuncAlias = new HashMap<String, CmisSelector>();
+ protected QueryConditionProcessor queryProcessor;
// from part
/**
* map from alias name to type query name
*/
- private Map<String, String> froms = new LinkedHashMap<String, String>();
+ protected Map<String, String> froms = new LinkedHashMap<String, String>();
// where part
- private Map<Integer, CmisSelector> columnReferences = new HashMap<Integer, CmisSelector>();
+ protected Map<Integer, CmisSelector> columnReferences = new HashMap<Integer, CmisSelector>();
// order by part
- private List<SortSpec> sortSpecs = new ArrayList<SortSpec>();
+ protected List<SortSpec> sortSpecs = new ArrayList<SortSpec>();
public class SortSpec {
- private boolean ascending;
- private Integer colRefKey; // key in columnReferencesMap point to column
+ public boolean ascending;
+ public Integer colRefKey; // key in columnReferencesMap point to column
// descriptions
public SortSpec(Integer key, boolean ascending) {
@@ -110,12 +110,12 @@ public class QueryObject {
return selectReferences;
}
- void addSelectReference(Object node, CmisSelector selRef) {
+ public void addSelectReference(Tree node, CmisSelector selRef) {
selectReferences.add(selRef);
- columnReferences.put(((Tree) node).getTokenStartIndex(), selRef);
+ columnReferences.put(node.getTokenStartIndex(), selRef);
}
- void addAlias(String aliasName, CmisSelector aliasRef) {
+ public void addAlias(String aliasName, CmisSelector aliasRef) {
LOG.debug("add alias: " + aliasName + " for: " + aliasRef);
if (colOrFuncAlias.containsKey(aliasName)) {
throw new CmisInvalidArgumentException("You cannot use name " + aliasName
@@ -126,14 +126,14 @@ public class QueryObject {
}
}
- CmisSelector getSelectAlias(String aliasName) {
+ public CmisSelector getSelectAlias(String aliasName) {
return colOrFuncAlias.get(aliasName);
}
// ///////////////////////////////////////////////////////
// FROM part
- void addType(String aliasName, String typeQueryName) {
+ public void addType(String aliasName, String typeQueryName) {
LOG.debug("add alias: " + aliasName + " for: " + typeQueryName);
if (froms.containsKey(aliasName)) {
throw new CmisInvalidArgumentException("You cannot use name " + aliasName
@@ -223,8 +223,8 @@ public class QueryObject {
// ///////////////////////////////////////////////////////
// JOINS
- void addJoinReference(Object node, CmisSelector reference) {
- columnReferences.put(((Tree) node).getTokenStartIndex(), reference);
+ public void addJoinReference(Tree node, CmisSelector reference) {
+ columnReferences.put(node.getTokenStartIndex(), reference);
joinReferences.add(reference);
}
@@ -235,10 +235,10 @@ public class QueryObject {
// ///////////////////////////////////////////////////////
// WHERE part
- void addWhereReference(Object node, CmisSelector reference) {
+ public void addWhereReference(Tree node, CmisSelector reference) {
LOG.debug("add node to where: " + System.identityHashCode(node));
- columnReferences.put(((Tree) node).getTokenStartIndex(), reference);
+ columnReferences.put(node.getTokenStartIndex(), reference);
whereReferences.add(reference);
}
@@ -325,7 +325,7 @@ public class QueryObject {
}
}
- private void resolveTypeForAlias(ColumnReference colRef) {
+ protected void resolveTypeForAlias(ColumnReference colRef) {
String aliasName = colRef.getAliasName();
if (colOrFuncAlias.containsKey(aliasName)) {
@@ -345,7 +345,7 @@ public class QueryObject {
}
// for a select x from y, z ... find the type in type manager for x
- private void resolveTypeForColumnReference(ColumnReference colRef) {
+ protected void resolveTypeForColumnReference(ColumnReference colRef) {
String propName = colRef.getPropertyQueryName();
boolean isStar = propName.equals("*");
@@ -378,7 +378,7 @@ public class QueryObject {
// for a select x.y from x ... check that x has property y and that x is in
// from
- private void validateColumnReferenceAndResolveType(ColumnReference colRef) {
+ protected void validateColumnReferenceAndResolveType(ColumnReference colRef) {
// either same name or mapped alias
String typeQueryName = getReferencedTypeQueryName(colRef.getTypeQueryName());
TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
@@ -389,7 +389,7 @@ public class QueryObject {
validateColumnReferenceAndResolveType(td, colRef);
}
- private void validateColumnReferenceAndResolveType(TypeDefinition td, ColumnReference colRef) {
+ protected void validateColumnReferenceAndResolveType(TypeDefinition td, ColumnReference colRef) {
// type found, check if property exists
boolean hasProp;
@@ -406,7 +406,7 @@ public class QueryObject {
// return type query name for a referenced column (which can be the name
// itself or an alias
- private String getReferencedTypeQueryName(String typeQueryNameOrAlias) {
+ protected String getReferencedTypeQueryName(String typeQueryNameOrAlias) {
String typeQueryName = froms.get(typeQueryNameOrAlias);
if (null == typeQueryName) {
// if an alias was defined but still the original is used we have to
@@ -428,7 +428,7 @@ public class QueryObject {
}
}
- private void processWhereNode(Tree root) {
+ protected void processWhereNode(Tree root) {
int count = root.getChildCount();
for (int i = 0; i < count; i++) {
Tree child = root.getChild(i);
@@ -440,7 +440,7 @@ public class QueryObject {
// ///////////////////////////////////////////////////////
// Processing the WHERE clause
- private void evalWhereNode(Tree node) {
+ protected void evalWhereNode(Tree node) {
// Ensure that we receive only valid tokens and nodes in the where
// clause:
LOG.debug("evaluating node: " + node.toString());