Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 13890 invoked from network); 14 Jun 2010 18:52:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Jun 2010 18:52:15 -0000 Received: (qmail 61391 invoked by uid 500); 14 Jun 2010 18:52:15 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 61332 invoked by uid 500); 14 Jun 2010 18:52:15 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 61324 invoked by uid 99); 14 Jun 2010 18:52:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jun 2010 18:52:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jun 2010 18:52:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D69A923889BB; Mon, 14 Jun 2010 18:51:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r954587 [1/4] - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ chemistry-opencmis-server/chemistry-opencmis-server-inm... Date: Mon, 14 Jun 2010 18:51:25 -0000 To: chemistry-commits@incubator.apache.org From: jens@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100614185125.D69A923889BB@eris.apache.org> Author: jens Date: Mon Jun 14 18:51:24 2010 New Revision: 954587 URL: http://svn.apache.org/viewvc?rev=954587&view=rev Log: CMIS-216 Implement basic query support for in-memory server Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLLexerStrict.g incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLParserStrict.g incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CmisQueryWalker.g incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/CmisSelector.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ColumnReference.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/FunctionReference.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/IQueryConditionProcessor.java 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/main/java/org/apache/chemistry/opencmis/inmemory/query/QueryObject.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryTest.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/EvalQueryTest.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-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryParseTest.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTestDataCreator.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/QueryTypesTest.java Removed: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/InMemoryQueryWalker.g Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryDiscoveryServiceImpl.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/StoreManagerImpl.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/PropertyCreationHelper.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/TypeValidationTest.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/UnitTestTypeSystemCreator.java Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java?rev=954587&r1=954586&r2=954587&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java Mon Jun 14 18:51:24 2010 @@ -42,6 +42,10 @@ public class PropertiesImpl extends Abst public PropertiesImpl() { } + public PropertiesImpl(Map> properties) { + fProperties = properties; + } + /** * Constructor. * Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLLexerStrict.g URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLLexerStrict.g?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLLexerStrict.g (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLLexerStrict.g Mon Jun 14 18:51:24 2010 @@ -0,0 +1,138 @@ +/* + * 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. + * + * Authors: + * Stefane Fermigier, Nuxeo + * Florent Guillaume, Nuxeo + */ +/** + * CMISQL lexer. + */ +lexer grammar CMISQLLexerStrict; + +tokens { + TABLE; + COL; + SEL_LIST; + IN_LIST; + IN_ANY; + NOT_IN_ANY; + EQ_ANY; + NOT_IN; + NOT_LIKE; + IS_NULL; + IS_NOT_NULL; + ORDER_BY; +} + +@header { +/* + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + * + * 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. + * + * Authors: + * Stefane Fermigier, Nuxeo + * Florent Guillaume, Nuxeo + * + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + */ +package org.apache.chemistry.opencmis.inmemory.query; +} + +// ----- Generic SQL ----- + +SELECT : ('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t'); +//DISTINCT : ('D'|'d')('I'|'i')('S'|'s')('T'|'t')('I'|'i')('N'|'n')('C'|'c')('T'|'t'); +FROM : ('F'|'f')('R'|'r')('O'|'o')('M'|'m'); +AS : ('A'|'a')('S'|'s'); +JOIN : ('J'|'j')('O'|'o')('I'|'i')('N'|'n'); +INNER : ('I'|'i')('N'|'n')('N'|'n')('E'|'e')('R'|'r'); +OUTER : ('O'|'o')('U'|'u')('T'|'t')('E'|'e')('R'|'r'); +LEFT : ('L'|'l')('E'|'e')('F'|'f')('T'|'t'); +RIGHT : ('R'|'r')('I'|'i')('G'|'g')('H'|'h')('T'|'t'); +ON : ('O'|'o')('N'|'n'); +WHERE : ('W'|'w')('H'|'h')('E'|'e')('R'|'r')('E'|'e'); +ORDER : ('O'|'o')('R'|'r')('D'|'d')('E'|'e')('R'|'r'); +BY : ('B'|'b')('Y'|'y'); +ASC : ('A'|'a')('S'|'s')('C'|'c'); +DESC : ('D'|'d')('E'|'e')('S'|'s')('C'|'c'); + +// ----- Operators ----- + +IS : ('I'|'i')('S'|'s'); +NULL : ('N'|'n')('U'|'u')('L'|'l')('L'|'l'); +AND : ('A'|'a')('N'|'n')('D'|'d'); +OR : ('O'|'o')('R'|'r'); +NOT : ('N'|'n')('O'|'o')('T'|'t'); +IN : ('I'|'i')('N'|'n'); +LIKE : ('L'|'l')('I'|'i')('K'|'k')('E'|'e'); +ANY : ('A'|'a')('N'|'n')('Y'|'y'); +CONTAINS : ('C'|'c')('O'|'o')('N'|'n')('T'|'t')('A'|'a')('I'|'i')('N'|'n')('S'|'s'); +SCORE : ('S'|'s')('C'|'c')('O'|'o')('R'|'r')('E'|'e'); +IN_FOLDER : ('I'|'i')('N'|'n')'_'('F'|'f')('O'|'o')('L'|'l')('D'|'d')('E'|'e')('R'|'r'); +IN_TREE : ('I'|'i')('N'|'n')'_'('T'|'t')('R'|'r')('E'|'e')('E'|'e'); +TIMESTAMP : 'TIMESTAMP'|'timestamp'; + +STAR : '*'; +LPAR : '('; +RPAR : ')'; +COMMA : ','; +DOT : '.'; +EQ : '='; +NEQ : '<>'; +LT : '<'; +GT : '>'; +LTEQ : '<='; +GTEQ : '>='; + +// ----- Literals ----- + +BOOL_LIT : 'TRUE' | 'true' | 'FALSE' | 'false'; + +fragment Sign : ('+'|'-')?; +fragment Digits : ('0'..'9')+; +fragment ExactNumLit : Digits DOT Digits | Digits DOT | DOT Digits | Digits; +fragment ApproxNumLit : ExactNumLit ('e'|'E') Sign Digits; +NUM_LIT : Sign (ExactNumLit | ApproxNumLit); + +STRING_LIT : '\'' (~'\''|'\'\'')* '\''; + +WS : ( ' ' | '\t' | '\r'? '\n' )+ { $channel=HIDDEN; }; + +TIME_LIT : TIMESTAMP WS STRING_LIT; + +ID : + ('a'..'z'|'A'..'Z'|'_') + ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|':')* + ; Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLParserStrict.g URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLParserStrict.g?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLParserStrict.g (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CMISQLParserStrict.g Mon Jun 14 18:51:24 2010 @@ -0,0 +1,290 @@ +/* + * 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. + * + * Authors: + * Stefane Fermigier, Nuxeo + * Florent Guillaume, Nuxeo + */ +/** + * CMISQL parser. + */ +parser grammar CMISQLParserStrict; + +options { + tokenVocab = CMISQLLexerStrict; + output = AST; +} + +@header { +/* + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + * + * 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. + * + * Authors: + * Stefane Fermigier, Nuxeo + * Florent Guillaume, Nuxeo + * + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + */ +package org.apache.chemistry.opencmis.inmemory.query; +} + +@members { + public String errorMessage; + + @Override + public void displayRecognitionError(String[] tokenNames, + RecognitionException e) { + if (errorMessage == null) { + String hdr = getErrorHeader(e); + String msg = getErrorMessage(e, tokenNames); + errorMessage = hdr + " " + msg; + } + } +} + +// For CMIS SQL it will be sufficient to stop on first error: +@rulecatch { +} + +query: + SELECT select_list from_clause where_clause? order_by_clause? + -> ^(SELECT select_list from_clause order_by_clause? where_clause?) + ; + +select_list + : STAR + | select_sublist ( COMMA select_sublist )* + -> ^(SEL_LIST select_sublist+) + ; + +select_sublist + : value_expression ( AS!? column_name )? + | qualifier DOT STAR + //| multi_valued_column_reference + ; + +value_expression: + column_reference + | numeric_value_function + ; + +column_reference: + ( qualifier DOT )? column_name + -> ^(COL qualifier? column_name) + ; + +multi_valued_column_reference: + ( qualifier DOT )? multi_valued_column_name + -> ^(COL qualifier? multi_valued_column_name) + ; + +numeric_value_function: + SCORE LPAR RPAR -> ^(SCORE); + +qualifier: + table_name + //| correlation_name + ; + +from_clause: FROM^ table_reference; + +table_reference: + one_table table_join* + ; + +table_join: + join_kind one_table join_specification? + -> ^(JOIN join_kind one_table join_specification?) + ; + +one_table: + LPAR! table_reference RPAR! + | table_name + -> ^(TABLE table_name) + | table_name AS? correlation_name + -> ^(TABLE table_name correlation_name) + ; + +join_kind: + JOIN + -> INNER + | INNER JOIN + -> INNER + | LEFT OUTER? JOIN + -> LEFT + | RIGHT OUTER? JOIN + -> RIGHT + ; + +join_specification: + ON^ column_reference EQ column_reference + ; + +/////////////////////////////////////////////////////////// +// Begin Where + +where_clause: WHERE^ search_condition; + +search_condition: + boolean_term (OR^ boolean_term)*; + +boolean_term: + boolean_factor (AND^ boolean_factor)*; + +boolean_factor: + NOT^ boolean_test + | boolean_test + ; + +boolean_test: + predicate + | LPAR search_condition RPAR -> search_condition + ; + +predicate: + comparison_predicate + | in_predicate + | like_predicate + | null_predicate + | quantified_comparison_predicate + | quantified_in_predicate + | text_search_predicate + | folder_predicate + ; + +comparison_predicate: + value_expression EQ literal + -> ^(EQ value_expression literal) + | value_expression NEQ literal + -> ^(NEQ value_expression literal) + | value_expression LT literal + -> ^(LT value_expression literal) + | value_expression GT literal + -> ^(GT value_expression literal) + | value_expression LTEQ literal + -> ^(LTEQ value_expression literal) + | value_expression GTEQ literal + -> ^(GTEQ value_expression literal) + ; + +literal: + NUM_LIT + | STRING_LIT + | TIME_LIT + | BOOL_LIT + ; + +in_predicate: + column_reference IN LPAR in_value_list RPAR + -> ^(IN column_reference in_value_list) + | column_reference NOT IN LPAR in_value_list RPAR + -> ^(NOT_IN column_reference in_value_list) + ; + +in_value_list: + literal ( COMMA literal )* + -> ^(IN_LIST literal+) + ; + +like_predicate: + column_reference LIKE STRING_LIT + -> ^(LIKE column_reference STRING_LIT) + | column_reference NOT LIKE STRING_LIT + -> ^(NOT_LIKE column_reference STRING_LIT) + ; + +null_predicate: + // second alternative commented out to remove left recursion for now. + //( column_reference | multi_valued_column_reference ) 'IS' 'NOT'? 'NULL'; + column_reference IS + ( NOT NULL -> ^(IS_NOT_NULL column_reference) + | NULL -> ^(IS_NULL column_reference) + ) + ; + +quantified_comparison_predicate: + literal EQ ANY multi_valued_column_reference + -> ^(EQ_ANY literal multi_valued_column_reference) + ; + +quantified_in_predicate: + ANY multi_valued_column_reference + ( NOT IN LPAR in_value_list RPAR + -> ^(NOT_IN_ANY multi_valued_column_reference in_value_list ) + | IN LPAR in_value_list RPAR + -> ^(IN_ANY multi_valued_column_reference in_value_list ) + ) + ; + +text_search_predicate: + CONTAINS LPAR (qualifier COMMA)? text_search_expression RPAR + -> ^(CONTAINS qualifier? text_search_expression) + ; + +// end where +///////////////////////////////////////////////////////////////// + +folder_predicate: + ( f=IN_FOLDER | f=IN_TREE ) LPAR (qualifier COMMA)? folder_id RPAR + -> ^($f qualifier? folder_id) + ; + +order_by_clause: + ORDER BY sort_specification ( COMMA sort_specification )* + -> ^(ORDER_BY sort_specification+) + ; + +sort_specification: + column_reference -> column_reference ASC + | column_reference ( ASC | DESC ) + ; + +correlation_name: + ID; + +table_name: + ID; + +column_name: + ID; + +multi_valued_column_name: + ID; + +folder_id: + STRING_LIT; + +text_search_expression: + STRING_LIT; Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CmisQueryWalker.g URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CmisQueryWalker.g?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CmisQueryWalker.g (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/antlr3/org/apache/chemistry/opencmis/inmemory/query/CmisQueryWalker.g Mon Jun 14 18:51:24 2010 @@ -0,0 +1,324 @@ +/* + * 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. + * + * Authors: + * Florent Guillaume, Nuxeo + */ +/** + * CMISQL tree grammar, walker for the inmemory implementation. + * This aims at implementing proper semantics without any speed + * optimization. + */ +tree grammar CmisQueryWalker; + +options { + tokenVocab = CMISQLParserStrict; + ASTLabelType = CommonTree; + output = AST; +} + +@header { +/* + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + * + * 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. + * + * Authors: + * Florent Guillaume, Nuxeo + * + * THIS FILE IS AUTO-GENERATED, DO NOT EDIT. + */ +package org.apache.chemistry.opencmis.inmemory.query; + +import java.math.BigDecimal; + +import java.util.Set; +import java.util.HashSet; +import java.util.Map; +import java.util.HashMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +} + +@members { + private static Log LOG = LogFactory.getLog(CmisQueryWalker.class); + + public QueryObject queryObj; + public String errorMessage; + + @Override + public void displayRecognitionError(String[] tokenNames, + RecognitionException e) { + if (errorMessage == null) { + String hdr = getErrorHeader(e); + String msg = getErrorMessage(e, tokenNames); + errorMessage = hdr + " " + msg; + } + } + + public String getErrorMessageString() { + return errorMessage; + } + + protected void mismatch(IntStream input, int ttype, BitSet follow) + throws RecognitionException + { + throw new MismatchedTokenException(ttype, input); + } + + public void recoverFromMismatchedSet(IntStream input, RecognitionException e, antlr.collections.impl.BitSet follow) + throws RecognitionException + { + throw e; + } +} + +// For CMIS SQL it will be sufficient to stop on first error: +@rulecatch { + catch (RecognitionException e) { + throw e; + } +} + +query [QueryObject qo] + @init { + queryObj = qo; + }: + ^(SELECT select_list from_clause order_by_clause? where_clause) + { + queryObj.resolveTypes(); + queryObj.processWhereClause($where_clause.tree); + } + ; + +select_list: + STAR + { + //queryObj.addSelectReference($STAR.getToken(), new ColumnReference($STAR.text)); + // LOG.debug("Adding * to col refs: " + $STAR); + queryObj.addSelectReference($STAR, new ColumnReference($STAR.text)); + } + | ^(SEL_LIST select_sublist+) + ; + +select_sublist + scope { String current; } + : + value_expression column_name? + { + // add selector + queryObj.addSelectReference($value_expression.start, $value_expression.result); + // add alias for column + if ($column_name.text != null) { + queryObj.addAlias($column_name.text, $value_expression.result); + } + } + | s=qualifier DOT STAR + { + // queryObj.addSelectReference($STAR.getToken(), new ColumnReference($qualifier.value, $STAR.text)); + // LOG.debug("Adding x.* to col refs: " + $s.start); + queryObj.addSelectReference($s.start, new ColumnReference($qualifier.value, $STAR.text)); + } + ; + + +value_expression returns [CmisSelector result]: + column_reference + { + $result = $column_reference.result; + } + | SCORE^ + { + $result = new FunctionReference(FunctionReference.CmisQlFunction.SCORE); + } + ; + +column_reference returns [ColumnReference result]: + ^(COL qualifier? column_name) + { + $result = new ColumnReference($qualifier.value, $column_name.text); + } + ; + +// multi_valued_column_reference returns [Object value]: +// ^(COL qualifier? column_name) + +qualifier returns [String value]: + table_name +// | correlation_name + { + $value = $table_name.text; + } + ; + +from_clause: + ^(FROM table_reference) + ; + +table_reference: + one_table table_join* + ; + +table_join: + ^(JOIN join_kind one_table join_specification?) + { + //throw new UnsupportedOperationException("JOIN"); + } + ; + +one_table: + ^(TABLE table_name correlation_name?) + { + queryObj.addType($correlation_name.text, $table_name.text); + } + ; + +join_kind: + INNER | LEFT | OUTER; + +join_specification: + ^(ON cr1=column_reference EQ cr2=column_reference) + { + queryObj.addJoinReference($cr1.start, $cr1.result); + queryObj.addJoinReference($cr2.start, $cr2.result); + } + ; + +where_clause: + ^(WHERE search_condition) + | /* nothing */ + ; + +search_condition +@init { + List listLiterals; +}: + ^(OR s1=search_condition s2=search_condition) + | ^(AND s1=search_condition s2=search_condition) + | ^(NOT search_condition) + | ^(EQ search_condition search_condition) + | ^(NEQ search_condition search_condition) + | ^(LT search_condition search_condition) + | ^(GT search_condition search_condition) + | ^(GTEQ search_condition search_condition) + | ^(LTEQ search_condition search_condition) + | ^(LIKE search_condition search_condition) + | ^(NOT_LIKE search_condition search_condition) + | ^(IS_NULL search_condition) + | ^(IS_NOT_NULL search_condition) + | ^(EQ_ANY search_condition search_condition) + | ^(IN_ANY search_condition in_value_list ) + | ^(NOT_IN_ANY search_condition in_value_list) + | ^(CONTAINS qualifier? text_search_expression) + | ^(IN_FOLDER qualifier? search_condition) + | ^(IN_TREE qualifier? search_condition) + | ^(IN column_reference in_value_list) + { + LOG.debug("IN list: " + $in_value_list.inList); + } + | ^(NOT_IN column_reference in_value_list) + | value_expression + { + LOG.debug(" add node to where: " + $value_expression.start + " id: " + System.identityHashCode($value_expression.start)); + queryObj.addWhereReference($value_expression.start, $value_expression.result); + } + | literal + ; + +in_value_list returns [Object inList] +@init { + List inLiterals = new ArrayList(); +}: + ^(IN_LIST (l=literal {inLiterals.add($l.value);})+ ) + { + $inList = inLiterals; + } + ; + +text_search_expression: + STRING_LIT; // TODO: extend grammar with full text part + + +literal returns [Object value]: + NUM_LIT + { + try { + $value = Long.valueOf($NUM_LIT.text); + } catch (NumberFormatException e) { + $value = new BigDecimal($NUM_LIT.text); + } + } + | STRING_LIT + { + String s = $STRING_LIT.text; + $value = s.substring(1, s.length() - 1); + } + | TIME_LIT + { + String s = $TIME_LIT.text; + s = s.substring(s.indexOf('\'') + 1, s.length() - 1); + try { + // $value = CalendarHelper.fromString(s); + } catch (IllegalArgumentException e) { + throw new UnwantedTokenException(Token.INVALID_TOKEN_TYPE, input); + } + } + | BOOL_LIT + { + $value = Boolean.valueOf($BOOL_LIT.text); + } + ; + +order_by_clause: + ^(ORDER_BY sort_specification+) + ; + +sort_specification: + column_reference ASC + { + queryObj.addSortCriterium($column_reference.start, $column_reference.result, true); + } + | column_reference DESC + { + queryObj.addSortCriterium($column_reference.start, $column_reference.result, false); + } + ; + +correlation_name: + ID; + +table_name: + ID; + +column_name: + ID; Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.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/DataObjectCreator.java?rev=954587&r1=954586&r2=954587&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/DataObjectCreator.java Mon Jun 14 18:51:24 2010 @@ -37,7 +37,6 @@ import org.apache.chemistry.opencmis.com import org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl; import org.apache.chemistry.opencmis.inmemory.storedobj.api.Content; import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder; -import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore; import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject; import org.apache.chemistry.opencmis.inmemory.storedobj.api.Version; import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument; Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.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/TypeManager.java?rev=954587&r1=954586&r2=954587&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManager.java Mon Jun 14 18:51:24 2010 @@ -18,39 +18,13 @@ */ package org.apache.chemistry.opencmis.inmemory; -import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer; -import org.apache.chemistry.opencmis.commons.impl.Converter; -import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition; -import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl; -import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertyDefinitionType; -import org.apache.chemistry.opencmis.inmemory.types.DocumentTypeCreationHelper; -import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition; -import org.apache.chemistry.opencmis.inmemory.types.InMemoryFolderTypeDefinition; -import org.apache.chemistry.opencmis.inmemory.types.InMemoryPolicyTypeDefinition; -import org.apache.chemistry.opencmis.inmemory.types.InMemoryRelationshipTypeDefinition; - -/** - * Class that manages a type system for a repository types can be added, the - * inheritance can be managed and type can be retrieved for a given type id. - * - * @author Jens - * - */ -public class TypeManager { - /** - * map from repository id to a types map - */ - private Map fTypesMap = new HashMap(); +public interface TypeManager { /** * return a type definition from the type definition id @@ -59,9 +33,7 @@ public class TypeManager { * id of the type definition * @return type definition for this id */ - public TypeDefinitionContainer getTypeById(String typeId) { - return fTypesMap.get(typeId); - } + public abstract TypeDefinitionContainer getTypeById(String typeId); /** * return a type definition from the type query name or null if not found @@ -70,30 +42,14 @@ public class TypeManager { * query name of the type definition * @return type definition for this query name */ - public TypeDefinition getTypeByQueryName(String typeQueryName) { - for (Entry entry : fTypesMap.entrySet()) { - if (entry.getValue().getTypeDefinition().getQueryName().equals(typeQueryName)) - return entry.getValue().getTypeDefinition(); - } - return null; - } + public abstract TypeDefinition getTypeByQueryName(String typeQueryName); /** * return a list of all types known in this repository * * @return */ - public synchronized Collection getTypeDefinitionList() { - - List typeRoots = new ArrayList(); - // iterate types map and return a list collecting the root types: - for (TypeDefinitionContainer typeDef : fTypesMap.values()) { - if (typeDef.getTypeDefinition().getParentTypeId() == null) - typeRoots.add(typeDef); - } - - return typeRoots; - } + public abstract Collection getTypeDefinitionList(); /** * return a list of the root types as defined in the CMIS spec (for @@ -101,84 +57,8 @@ public class TypeManager { * * @return */ - public List getRootTypes() { - // just take first repository - List rootTypes = new ArrayList(); - - for (TypeDefinitionContainer type : fTypesMap.values()) - if (isRootType(type)) - rootTypes.add(type); - - return rootTypes; - } - - /** - * Initialize the type system with the given types. This list must not - * contain the CMIS default types. The default type are always contained by - * default. - * - * @param typesList - * list of types to add to the repository - * - */ - public void initTypeSystem(List typesList) { + public abstract List getRootTypes(); - createCmisDefaultTypes(); - - // merge all types from the list and build the correct hierachy with - // children - // and property lists - if (null != typesList) { - for (TypeDefinition typeDef : typesList) - addTypeDefinition(typeDef); - } - - } - - /** - * Add a type to the type system. Add all properties from inherited types, - * add type to children of parent types. - * - * @param repositoryId - * repository to which the type is added - * @param cmisType - * new type to add - */ - public void addTypeDefinition(TypeDefinition cmisType) { - if (fTypesMap.containsKey(cmisType.getId())) - throw new RuntimeException("You cannot add type with id " + cmisType.getId() - + " because it already exists."); - - TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(cmisType); - - if (!fTypesMap.containsKey(cmisType.getParentTypeId())) - throw new RuntimeException("Cannot add type, because parent with id " + cmisType.getParentTypeId() - + " does not exist."); - - // add new type to children of parent types - TypeDefinitionContainer parentTypeContainer = fTypesMap.get(cmisType.getParentTypeId()); - parentTypeContainer.getChildren().add(typeContainer); - - // recursively add inherited properties - Map> propDefs = typeContainer.getTypeDefinition().getPropertyDefinitions(); - addInheritedProperties(propDefs, parentTypeContainer.getTypeDefinition()); - - // add type to type map - fTypesMap.put(cmisType.getId(), typeContainer); - } - - /** - * Remove all types from the type system. After this call only the default - * CMIS types are present in the type system. Use this method with care, its - * mainly intended for unit tests - * - * @param repositoryId - */ - public void clearTypeSystem() { - fTypesMap.clear(); - createCmisDefaultTypes(); - } - /** * retrieve the property id from a type for a given property query name * @@ -189,76 +69,6 @@ public class TypeManager { * @return * property id of property or null if not found */ - public String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName) { - for (PropertyDefinition pd : typeDefinition.getPropertyDefinitions().values()) { - if (pd.getQueryName().equals(propQueryName)) - return pd.getId(); - } - return null; - } - - private void addInheritedProperties(Map> propDefs, TypeDefinition typeDefinition) { - - if (null == typeDefinition) - return; - - if (null != typeDefinition.getPropertyDefinitions()) - addInheritedPropertyDefinitions(propDefs, typeDefinition.getPropertyDefinitions()); - // propDefs.putAll(typeDefinition.getPropertyDefinitions()); - - TypeDefinitionContainer parentTypeContainer = fTypesMap.get(typeDefinition.getParentTypeId()); - TypeDefinition parentType = (null == parentTypeContainer ? null : parentTypeContainer.getTypeDefinition()); - addInheritedProperties(propDefs, parentType); - } - - private void addInheritedPropertyDefinitions(Map> propDefs, - Map> superPropDefs) { - - for (Entry> superProp : superPropDefs.entrySet()) { - PropertyDefinition superPropDef = superProp.getValue(); - PropertyDefinition clone = clonePropertyDefinition(superPropDef); - ((AbstractPropertyDefinition) clone).setIsInherited(true); - propDefs.put(superProp.getKey(), clone); - } - } - - private void createCmisDefaultTypes() { - List typesList = DocumentTypeCreationHelper.createDefaultTypes(); - for (TypeDefinition typeDef : typesList) { - TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(typeDef); - fTypesMap.put(typeDef.getId(), typeContainer); - } - } - - private static boolean isRootType(TypeDefinitionContainer c) { - if (c.getTypeDefinition().equals(InMemoryFolderTypeDefinition.getRootFolderType()) - || c.getTypeDefinition().equals(InMemoryDocumentTypeDefinition.getRootDocumentType()) - || c.getTypeDefinition().equals(InMemoryRelationshipTypeDefinition.getRootRelationshipType()) - || c.getTypeDefinition().equals(InMemoryPolicyTypeDefinition.getRootPolicyType())) - return true; - else - return false; - } - - private static PropertyDefinition clonePropertyDefinition(PropertyDefinition src) { - // use JAXB converter to easily clone a property definition - CmisPropertyDefinitionType tmp = Converter.convert(src); - PropertyDefinition clone = Converter.convert(tmp); - return clone; - } - - // private static PropertyDefinition - // clonePropertyDefinition2(PropertyDefinition src) - // throws IOException, ClassNotFoundException { - // ByteArrayOutputStream bout = new ByteArrayOutputStream(); - // ObjectOutputStream oout = new ObjectOutputStream(bout); - // oout.writeObject(src); - // byte[] bytes = bout.toByteArray(); - // - // ByteArrayInputStream bin = new ByteArrayInputStream(bytes); - // ObjectInputStream oin = new ObjectInputStream(bin); - // PropertyDefinition clone = (PropertyDefinition) oin.readObject(); - // return clone; - // } + public abstract String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName); -} +} \ No newline at end of file Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.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/TypeManagerImpl.java?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeManagerImpl.java Mon Jun 14 18:51:24 2010 @@ -0,0 +1,244 @@ +/* + * 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.chemistry.opencmis.inmemory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition; +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer; +import org.apache.chemistry.opencmis.commons.impl.Converter; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl; +import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertyDefinitionType; +import org.apache.chemistry.opencmis.inmemory.types.DocumentTypeCreationHelper; +import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition; +import org.apache.chemistry.opencmis.inmemory.types.InMemoryFolderTypeDefinition; +import org.apache.chemistry.opencmis.inmemory.types.InMemoryPolicyTypeDefinition; +import org.apache.chemistry.opencmis.inmemory.types.InMemoryRelationshipTypeDefinition; + +/** + * Class that manages a type system for a repository types can be added, the + * inheritance can be managed and type can be retrieved for a given type id. + * + * @author Jens + * + */ +public class TypeManagerImpl implements TypeManager { + + /** + * map from repository id to a types map + */ + private Map fTypesMap = new HashMap(); + + /* (non-Javadoc) + * @see org.apache.chemistry.opencmis.inmemory.TypeManager#getTypeById(java.lang.String) + */ + public TypeDefinitionContainer getTypeById(String typeId) { + return fTypesMap.get(typeId); + } + + /* (non-Javadoc) + * @see org.apache.chemistry.opencmis.inmemory.TypeManager#getTypeByQueryName(java.lang.String) + */ + public TypeDefinition getTypeByQueryName(String typeQueryName) { + for (Entry entry : fTypesMap.entrySet()) { + if (entry.getValue().getTypeDefinition().getQueryName().equals(typeQueryName)) + return entry.getValue().getTypeDefinition(); + } + return null; + } + + /* (non-Javadoc) + * @see org.apache.chemistry.opencmis.inmemory.TypeManager#getTypeDefinitionList() + */ + public synchronized Collection getTypeDefinitionList() { + + List typeRoots = new ArrayList(); + // iterate types map and return a list collecting the root types: + for (TypeDefinitionContainer typeDef : fTypesMap.values()) { + if (typeDef.getTypeDefinition().getParentTypeId() == null) + typeRoots.add(typeDef); + } + + return typeRoots; + } + + /* (non-Javadoc) + * @see org.apache.chemistry.opencmis.inmemory.TypeManager#getRootTypes() + */ + public List getRootTypes() { + // just take first repository + List rootTypes = new ArrayList(); + + for (TypeDefinitionContainer type : fTypesMap.values()) + if (isRootType(type)) + rootTypes.add(type); + + return rootTypes; + } + + /** + * Initialize the type system with the given types. This list must not + * contain the CMIS default types. The default type are always contained by + * default. + * + * @param typesList + * list of types to add to the repository + * + */ + public void initTypeSystem(List typesList) { + + createCmisDefaultTypes(); + + // merge all types from the list and build the correct hierachy with + // children + // and property lists + if (null != typesList) { + for (TypeDefinition typeDef : typesList) + addTypeDefinition(typeDef); + } + + } + + /** + * Add a type to the type system. Add all properties from inherited types, + * add type to children of parent types. + * + * @param repositoryId + * repository to which the type is added + * @param cmisType + * new type to add + */ + public void addTypeDefinition(TypeDefinition cmisType) { + if (fTypesMap.containsKey(cmisType.getId())) + throw new RuntimeException("You cannot add type with id " + cmisType.getId() + + " because it already exists."); + + TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(cmisType); + + if (!fTypesMap.containsKey(cmisType.getParentTypeId())) + throw new RuntimeException("Cannot add type, because parent with id " + cmisType.getParentTypeId() + + " does not exist."); + + // add new type to children of parent types + TypeDefinitionContainer parentTypeContainer = fTypesMap.get(cmisType.getParentTypeId()); + parentTypeContainer.getChildren().add(typeContainer); + + // recursively add inherited properties + Map> propDefs = typeContainer.getTypeDefinition().getPropertyDefinitions(); + addInheritedProperties(propDefs, parentTypeContainer.getTypeDefinition()); + + // add type to type map + fTypesMap.put(cmisType.getId(), typeContainer); + } + + /** + * Remove all types from the type system. After this call only the default + * CMIS types are present in the type system. Use this method with care, its + * mainly intended for unit tests + * + * @param repositoryId + */ + public void clearTypeSystem() { + fTypesMap.clear(); + createCmisDefaultTypes(); + } + + /* (non-Javadoc) + * @see org.apache.chemistry.opencmis.inmemory.TypeManager#getPropertyIdForQueryName(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition, java.lang.String) + */ + public String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName) { + for (PropertyDefinition pd : typeDefinition.getPropertyDefinitions().values()) { + if (pd.getQueryName().equals(propQueryName)) + return pd.getId(); + } + return null; + } + + private void addInheritedProperties(Map> propDefs, TypeDefinition typeDefinition) { + + if (null == typeDefinition) + return; + + if (null != typeDefinition.getPropertyDefinitions()) + addInheritedPropertyDefinitions(propDefs, typeDefinition.getPropertyDefinitions()); + // propDefs.putAll(typeDefinition.getPropertyDefinitions()); + + TypeDefinitionContainer parentTypeContainer = fTypesMap.get(typeDefinition.getParentTypeId()); + TypeDefinition parentType = (null == parentTypeContainer ? null : parentTypeContainer.getTypeDefinition()); + addInheritedProperties(propDefs, parentType); + } + + private void addInheritedPropertyDefinitions(Map> propDefs, + Map> superPropDefs) { + + for (Entry> superProp : superPropDefs.entrySet()) { + PropertyDefinition superPropDef = superProp.getValue(); + PropertyDefinition clone = clonePropertyDefinition(superPropDef); + ((AbstractPropertyDefinition) clone).setIsInherited(true); + propDefs.put(superProp.getKey(), clone); + } + } + + private void createCmisDefaultTypes() { + List typesList = DocumentTypeCreationHelper.createDefaultTypes(); + for (TypeDefinition typeDef : typesList) { + TypeDefinitionContainerImpl typeContainer = new TypeDefinitionContainerImpl(typeDef); + fTypesMap.put(typeDef.getId(), typeContainer); + } + } + + private static boolean isRootType(TypeDefinitionContainer c) { + if (c.getTypeDefinition().equals(InMemoryFolderTypeDefinition.getRootFolderType()) + || c.getTypeDefinition().equals(InMemoryDocumentTypeDefinition.getRootDocumentType()) + || c.getTypeDefinition().equals(InMemoryRelationshipTypeDefinition.getRootRelationshipType()) + || c.getTypeDefinition().equals(InMemoryPolicyTypeDefinition.getRootPolicyType())) + return true; + else + return false; + } + + private static PropertyDefinition clonePropertyDefinition(PropertyDefinition src) { + // use JAXB converter to easily clone a property definition + CmisPropertyDefinitionType tmp = Converter.convert(src); + PropertyDefinition clone = Converter.convert(tmp); + return clone; + } + + // private static PropertyDefinition + // clonePropertyDefinition2(PropertyDefinition src) + // throws IOException, ClassNotFoundException { + // ByteArrayOutputStream bout = new ByteArrayOutputStream(); + // ObjectOutputStream oout = new ObjectOutputStream(bout); + // oout.writeObject(src); + // byte[] bytes = bout.toByteArray(); + // + // ByteArrayInputStream bin = new ByteArrayInputStream(bytes); + // ObjectInputStream oin = new ObjectInputStream(bin); + // PropertyDefinition clone = (PropertyDefinition) oin.readObject(); + // return clone; + // } + +} Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/CmisSelector.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/CmisSelector.java?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/CmisSelector.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/CmisSelector.java Mon Jun 14 18:51:24 2010 @@ -0,0 +1,32 @@ +/* + * 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.chemistry.opencmis.inmemory.query; + +public abstract class CmisSelector { + private String aliasName; // Alias name for a column (only in SELECT part set) + + public void setAliasName(String alias) { + aliasName = alias; + } + + public String getAliasName() { + return aliasName; + } + public abstract String getName(); +} Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ColumnReference.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/ColumnReference.java?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ColumnReference.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/ColumnReference.java Mon Jun 14 18:51:24 2010 @@ -0,0 +1,71 @@ +/* + * 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.chemistry.opencmis.inmemory.query; + +import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition; + +public class ColumnReference extends CmisSelector { + + private String typeQueryName; // type query name coming from query statement + private String propQueryName; // property query name coming from query statement + + // The following fields are set when the types are resolved: + private String propertyId; + private TypeDefinition typeDef; + + public ColumnReference(String typeQueryName, String propQueryName) { + this.typeQueryName = typeQueryName; + this.propQueryName = propQueryName; + } + + public ColumnReference(String propQueryName) { + this.typeQueryName = null; + this.propQueryName = propQueryName; + } + + public String getTypeQueryName() { + return typeQueryName; + } + + public String getPropertyQueryName() { + return propQueryName; + } + + @Override + public String getName() { + return propQueryName; + } + + void setTypeDefinition(String propertyId, TypeDefinition typeDef) { + this.typeDef = typeDef; + this.propertyId = propertyId; + } + + public TypeDefinition getTypeDefinition() { + return typeDef; + } + + public String getPropertyId() { + return propertyId; + } + + public String toString() { + return "Column Reference for column " + propQueryName + " in type " + typeQueryName; + } +} Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/FunctionReference.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/FunctionReference.java?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/FunctionReference.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/FunctionReference.java Mon Jun 14 18:51:24 2010 @@ -0,0 +1,44 @@ +/* + * 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.chemistry.opencmis.inmemory.query; + +public class FunctionReference extends CmisSelector { + + public enum CmisQlFunction { SCORE, }; + + private CmisQlFunction function; + + public FunctionReference(CmisQlFunction func) { + this.function = func; + } + + public CmisQlFunction getFunction() { + return function; + } + + public String toString() { + return "FunctionReference for " + function.toString(); + } + + @Override + public String getName() { + return function.toString(); + } + +} Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/IQueryConditionProcessor.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/IQueryConditionProcessor.java?rev=954587&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/IQueryConditionProcessor.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/query/IQueryConditionProcessor.java Mon Jun 14 18:51:24 2010 @@ -0,0 +1,68 @@ +/* + * 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.chemistry.opencmis.inmemory.query; + +import org.antlr.runtime.tree.Tree; + +/** + * An interface used by the walker when traversing the AST from the grammar. + * The interface consists of callback methods that are called when a rule + * is processed (as part of the WHERE statement) + * @author Jens + * + */ +public interface IQueryConditionProcessor { + + void onStartProcessing(Tree whereNode); + void onStopProcessing(); + + // Compare operators + void onEquals(Tree eqNode, Tree leftNode, Tree rightNode); + void onNotEquals(Tree neNode, Tree leftNode, Tree rightNode); + void onGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode); + void onGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode); + void onLessThan(Tree ltNode, Tree leftNode, Tree rightNode); + void onLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode); + + // Boolean operators + void onNot(Tree opNode, Tree leftNode); + void onAnd(Tree opNode, Tree leftNode, Tree rightNode); + void onOr(Tree opNode, Tree leftNode, Tree rightNode); + + // Multi-value: + void onIn(Tree node, Tree colNode, Tree listNode); + void onNotIn(Tree node, Tree colNode, Tree listNode); + void onInAny(Tree node, Tree colNode, Tree listNode); + void onNotInAny(Tree node, Tree colNode, Tree listNode); + void onEqAny(Tree node, Tree literalNode, Tree colNode); + + // Null comparisons: + public void onIsNull(Tree nullNode, Tree colNode); + public void onIsNotNull(Tree notNullNode, Tree colNode); + + // String matching: + void onIsLike(Tree node, Tree colNode, Tree stringNode); + void onIsNotLike(Tree node, Tree colNode, Tree stringNode); + + // Functions: + void onContains(Tree node, Tree colNode, Tree paramNode); + void onInFolder(Tree node, Tree colNode, Tree paramNode); + void onInTree(Tree node, Tree colNode, Tree paramNode); + void onScore(Tree node, Tree paramNode); +}