Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2EC51119A7 for ; Fri, 21 Feb 2014 18:21:40 +0000 (UTC) Received: (qmail 39044 invoked by uid 500); 21 Feb 2014 18:21:23 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 38861 invoked by uid 500); 21 Feb 2014 18:21:18 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 38644 invoked by uid 99); 21 Feb 2014 18:21:15 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Feb 2014 18:21:15 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 798BF82EAD7; Fri, 21 Feb 2014 18:21:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: snoopdave@apache.org To: commits@usergrid.apache.org Date: Fri, 21 Feb 2014 18:21:26 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [13/21] Rename index to query index, add working query parser code. http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/index/src/test/resources/sample-small.json ---------------------------------------------------------------------- diff --git a/stack/corepersistence/index/src/test/resources/sample-small.json b/stack/corepersistence/index/src/test/resources/sample-small.json deleted file mode 100644 index 91f336c..0000000 --- a/stack/corepersistence/index/src/test/resources/sample-small.json +++ /dev/null @@ -1,222 +0,0 @@ -[ - { - "id": 0, - "guid": "41a6482a-f8d5-4b28-a2f1-90b110b25167", - "isActive": false, - "balance": "$1,600.00", - "picture": "http://placehold.it/32x32", - "age": 33, - "name": "Molly Fitzpatrick", - "gender": "female", - "company": "Geologix", - "contact": { - "email": "mollyfitzpatrick@geologix.com", - "phone": "+1 (968) 560-2206", - "address": "895 Karweg Place, Lookingglass, Utah, 1989" - }, - "about": "Eu nisi Lorem ad exercitation enim cupidatat culpa consectetur voluptate fugiat pariatur. Irure reprehenderit est quis aliquip fugiat enim. Elit ex qui cupidatat velit nisi cillum sunt dolor eu aute duis et. Culpa anim proident veniam occaecat eiusmod non adipisicing consequat fugiat eu irure laborum. Ea est sint deserunt laboris. Enim pariatur in ut magna ipsum fugiat ullamco dolor est voluptate veniam velit.\r\n", - "registered": "2013-02-02T16:18:24 +05:00", - "latitude": 10.237003, - "longitude": -86.677799, - "tags": [ - "sint", - "laboris", - "laboris", - "enim", - "irure", - "dolore", - "non" - ], - "friends": [ - { - "id": 0, - "name": "Concepcion Michael" - }, - { - "id": 1, - "name": "Harris Mcdonald" - }, - { - "id": 2, - "name": "Marshall Cote" - } - ], - "randomArrayItem": "lemon" - }, - { - "id": 1, - "guid": "13158ddc-c6fe-4dc6-84ad-1a20b2bc8494", - "isActive": false, - "balance": "$3,898.00", - "picture": "http://placehold.it/32x32", - "age": 40, - "name": "Tami Mccullough", - "gender": "female", - "company": "Eventex", - "contact": { - "email": "tamimccullough@eventex.com", - "phone": "+1 (875) 421-2839", - "address": "367 Orange Street, Wright, Michigan, 913" - }, - "about": "Occaecat Lorem dolore in consectetur enim Lorem minim. Do eu aliqua aliquip consequat adipisicing Lorem qui reprehenderit do nisi nisi incididunt velit consequat. Aliqua anim dolor est cillum dolore et ullamco. Adipisicing dolore sunt sunt tempor nisi.\r\n", - "registered": "2013-06-10T03:06:40 +04:00", - "latitude": -38.108123, - "longitude": -128.352006, - "tags": [ - "ipsum", - "magna", - "eu", - "anim", - "magna", - "nisi", - "nisi" - ], - "friends": [ - { - "id": 0, - "name": "Elva Whitfield" - }, - { - "id": 1, - "name": "King Waters" - }, - { - "id": 2, - "name": "Sandra Rodriguez" - } - ], - "randomArrayItem": "apple" - }, - { - "id": 2, - "guid": "cc4541b1-d8e3-4f2d-924f-ad1f78ca994a", - "isActive": false, - "balance": "$1,715.00", - "picture": "http://placehold.it/32x32", - "age": 34, - "name": "Tina Dudley", - "gender": "female", - "company": "Reversus", - "contact": { - "email": "tinadudley@reversus.com", - "phone": "+1 (873) 549-2696", - "address": "772 Arion Place, Tibbie, Virginia, 8573" - }, - "about": "Do laboris fugiat qui est mollit aliqua esse non duis ex non eiusmod consequat. Tempor eu et voluptate adipisicing. Nostrud veniam laborum officia eiusmod esse commodo culpa. Officia cupidatat officia consequat laboris duis cillum fugiat nostrud in.\r\n", - "registered": "1998-04-01T23:20:58 +05:00", - "latitude": 0.298655, - "longitude": -91.268836, - "tags": [ - "enim", - "ut", - "elit", - "officia", - "ut", - "nostrud", - "ullamco" - ], - "friends": [ - { - "id": 0, - "name": "Haney Spears" - }, - { - "id": 1, - "name": "Erna Trevino" - }, - { - "id": 2, - "name": "Trisha Vaughan" - } - ], - "randomArrayItem": "apple" - }, - { - "id": 3, - "guid": "2bb6de28-5d2d-4cf6-bde0-b3cf60bf6bb3", - "isActive": true, - "balance": "$2,016.00", - "picture": "http://placehold.it/32x32", - "age": 23, - "name": "Norman Hester", - "gender": "male", - "company": "Playce", - "contact": { - "email": "normanhester@playce.com", - "phone": "+1 (856) 431-2945", - "address": "406 Minna Street, Glenville, Connecticut, 3785" - }, - "about": "Qui labore nostrud id occaecat culpa irure ad. Dolore non laborum occaecat occaecat ad sunt amet officia nisi in ullamco est officia. Lorem officia pariatur sit aute ea incididunt do. Consectetur id ad id mollit amet cupidatat dolor consectetur ipsum aute amet do. Reprehenderit consectetur amet esse fugiat et exercitation eiusmod. Labore nostrud sit quis sit qui id. Culpa pariatur aliquip sint magna irure occaecat officia magna sit proident pariatur.\r\n", - "registered": "1988-08-11T12:52:13 +04:00", - "latitude": -21.888779, - "longitude": 65.493829, - "tags": [ - "Lorem", - "officia", - "nostrud", - "eu", - "do", - "eu", - "duis" - ], - "friends": [ - { - "id": 0, - "name": "Georgina Hess" - }, - { - "id": 1, - "name": "Parsons Wilson" - }, - { - "id": 2, - "name": "Harmon Wise" - } - ], - "randomArrayItem": "apple" - }, - { - "id": 4, - "guid": "32fedc30-8e37-4b65-abb3-8faa829f4ad3", - "isActive": true, - "balance": "$2,642.00", - "picture": "http://placehold.it/32x32", - "age": 33, - "name": "Orr Byers", - "gender": "male", - "company": "Bittor", - "contact": { - "email": "orrbyers@bittor.com", - "phone": "+1 (997) 569-2415", - "address": "730 Lloyd Street, Marshall, Vermont, 3170" - }, - "about": "Lorem culpa adipisicing consequat eu incididunt ullamco sunt id est. Aliquip labore ex sit culpa aliqua ex occaecat aliquip voluptate non labore culpa irure. Consequat tempor consequat laboris sint nulla commodo sit. Est velit dolor ut quis veniam aliqua amet dolore mollit labore. Magna commodo deserunt anim est velit laboris. Commodo sunt sit qui eu mollit eu esse excepteur ea sit incididunt.\r\n", - "registered": "1996-08-30T07:13:22 +04:00", - "latitude": 76.747258, - "longitude": -114.875056, - "tags": [ - "ut", - "esse", - "reprehenderit", - "aute", - "laborum", - "esse", - "dolore" - ], - "friends": [ - { - "id": 0, - "name": "Spencer Hurley" - }, - { - "id": 1, - "name": "Adrienne Griffith" - }, - { - "id": 2, - "name": "Peck Haley" - } - ], - "randomArrayItem": "apple" - } -] http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/query/pom.xml ---------------------------------------------------------------------- diff --git a/stack/corepersistence/query/pom.xml b/stack/corepersistence/query/pom.xml new file mode 100644 index 0000000..d4bff43 --- /dev/null +++ b/stack/corepersistence/query/pom.xml @@ -0,0 +1,233 @@ + + + + + 3.0 + 3.3 + 1.7.2 + 1.2.17 + 1.0 + + + + persistence + org.apache.usergrid + 1.0-SNAPSHOT + + 4.0.0 + Module provates query for Entities via ElasticSearch + + query + + + + + + src/test/resources + true + + **/* + + + + + + + + org.safehaus.chop + chop-maven-plugin + ${chop.version} + + + + + ${aws.s3.key} + ${aws.s3.secret} + ${availabilityZone} + ${aws.s3.bucket} + admin + ${manager.app.password} + org.apache.usergrid + ${runner.ssh.key.file} + false + ${ami.id} + m1.large + ${resultsDirectory} + ${dumpType} + true + ${security.group} + ${runner.keypair.name} + 6 + + + ${myip.address}/32:24981 + ${myip.address}/32:22 + + + + + + + + org.antlr + antlr3-maven-plugin + + + + src/main/java + + + antlr + + + + + + + + + + + + org.safehaus.chop + chop-api + ${chop.version} + + + + + + ${project.parent.groupId} + model + ${project.version} + + + + org.elasticsearch + elasticsearch + 1.0.0.RC1 + + + + org.safehaus.guicyfig + guicyfig + ${guicyfig.version} + + + + org.jukito + jukito + ${jukito.version} + test + + + + + + org.apache.commons + commons-lang3 + 3.1 + + + + + + com.google.inject + guice + ${guice.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + + log4j + log4j + ${log4j.version} + + + + org.apache.usergrid + model + 1.0-SNAPSHOT + jar + + + + commons-codec + commons-codec + 1.6 + jar + + + + commons-io + commons-io + 2.4 + jar + + + + commons-collections + commons-collections + 3.2.1 + jar + + + + org.codehaus.jackson + jackson-smile + 1.9.13 + jar + + + + org.antlr + antlr-runtime + 3.5 + jar + + + + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/query/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/stack/corepersistence/query/src/test/resources/log4j.properties b/stack/corepersistence/query/src/test/resources/log4j.properties new file mode 100644 index 0000000..75bbc31 --- /dev/null +++ b/stack/corepersistence/query/src/test/resources/log4j.properties @@ -0,0 +1,30 @@ +# 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. + +# for production, you should probably set the root to INFO +# and the pattern to %c instead of %l. (%l is slower.) + +# output messages into a rolling log file as well as stdout +log4j.rootLogger=INFO,stdout + +# stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) [%c] - %m%n + +log4j.category.org.apache=ERROR +log4j.category.org.apache.usergrid=INFO + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/pom.xml ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/pom.xml b/stack/corepersistence/queryindex/pom.xml new file mode 100644 index 0000000..87a7ebf --- /dev/null +++ b/stack/corepersistence/queryindex/pom.xml @@ -0,0 +1,228 @@ + + + + 4.0.0 + + queryindex + queryindex + Module provates indexing and query of Entities via ElasticSearch + + + 3.0 + 3.3 + 1.7.2 + 1.2.17 + 1.0 + + + + persistence + org.apache.usergrid + 1.0-SNAPSHOT + + + + + + + src/test/resources + true + + **/* + + + + + + + + org.safehaus.chop + chop-maven-plugin + ${chop.version} + + + + + ${aws.s3.key} + ${aws.s3.secret} + ${availabilityZone} + ${aws.s3.bucket} + admin + ${manager.app.password} + org.apache.usergrid + ${runner.ssh.key.file} + false + ${ami.id} + m1.large + ${resultsDirectory} + ${dumpType} + true + ${security.group} + ${runner.keypair.name} + 6 + + + ${myip.address}/32:24981 + ${myip.address}/32:22 + + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.6 + + + 85 + 85 + true + 85 + 85 + 85 + 85 + + + + + + clean + check + + + + + + + + + + + + org.apache.usergrid + model + 1.0-SNAPSHOT + jar + + + + org.apache.usergrid + collection + 1.0-SNAPSHOT + jar + + + + org.safehaus.chop + chop-api + ${chop.version} + + + + + + ${project.parent.groupId} + model + ${project.version} + + + + org.elasticsearch + elasticsearch + 1.0.0.RC1 + + + + org.safehaus.guicyfig + guicyfig + ${guicyfig.version} + + + + org.jukito + jukito + ${jukito.version} + test + + + + + + org.apache.commons + commons-lang3 + 3.1 + + + + + + com.google.inject + guice + ${guice.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + + log4j + log4j + ${log4j.version} + + + + commons-codec + commons-codec + 1.6 + jar + + + + commons-io + commons-io + 2.4 + jar + + + + commons-collections + commons-collections + 3.2.1 + jar + + + + org.codehaus.jackson + jackson-smile + 1.9.13 + jar + + + + org.antlr + antlr-runtime + 3.5 + jar + + + + + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g b/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g new file mode 100644 index 0000000..c566ef9 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/antlr3/org/apache/usergrid/persistence/query/tree/QueryFilter.g @@ -0,0 +1,311 @@ +grammar QueryFilter; +//NOTES: '^' denotes operator, all others in the string become operands + +options { + output=AST; +// ASTLabelType=CommonTree; +} + +@rulecatch { } + + +@header { +package org.apache.usergrid.persistence.query.tree; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.usergrid.persistence.Query; +import org.apache.usergrid.persistence.Query.SortPredicate; + +} + + +@members { + Query query = new Query(); + + private static final Logger logger = LoggerFactory + .getLogger(QueryFilterLexer.class); + + @Override + public void emitErrorMessage(String msg) { + logger.info(msg); + } +} + + +@lexer::header { +package org.apache.usergrid.persistence.query.tree; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.usergrid.persistence.exceptions.QueryTokenException; + +} + +@lexer::members { + + + + private static final Logger logger = LoggerFactory + .getLogger(QueryFilterLexer.class); + + + + + @Override + public void emitErrorMessage(String msg) { + logger.info(msg); + } + + @Override + public void recover(RecognitionException e) { + //We don't want to recover, we want to re-throw to the user since they passed us invalid input + throw new QueryTokenException(e); + } + + +} + +//these must come before ID. Otherwise lt, lte, eq, etc will be returned as id tokens +LT : '<' | 'lt'; + +LTE : '<=' | 'lte'; + +EQ : '=' | 'eq'; + +GT : '>' | 'gt'; + +GTE : '>=' | 'gte'; + + +//keywords before var ids +BOOLEAN : (TRUE|FALSE); + +AND : ('A'|'a')('N'|'n')('D'|'d') | '&&'; + +OR : ('O'|'o')('R'|'r') | '||' ; + +NOT : ('N'|'n')('O'|'o')('T'|'t'); + +ASC : ('A'|'a')('S'|'s')('C'|'c'); + +DESC : ('D'|'d')('E'|'e')('S'|'s')('C'|'c'); + +CONTAINS : ('C'|'c')('O'|'o')('N'|'n')('T'|'t')('A'|'a')('I'|'i')('N'|'n')('S'|'s'); + +WITHIN : ('W'|'w')('I'|'i')('T'|'t')('H'|'h')('I'|'i')('N'|'n'); + +OF : ('O'|'o')('F'|'f'); + +UUID : HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT '-' + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + ; + +//ids and values +ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'.'|'-')* + ; + +LONG : ('-')? '0'..'9'+ + ; + +FLOAT + : ('-')? ( ('0'..'9')+ '.' ('0'..'9')* EXPONENT? + | '.' ('0'..'9')+ EXPONENT? + | ('0'..'9')+ EXPONENT) + ; + +STRING + : '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\'' + ; + + + +WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel=HIDDEN;}; + + + + + + + +fragment TRUE : ('T'|'t')('R'|'r')('U'|'u')('E'|'e'); + +fragment FALSE : ('F'|'f')('A'|'a')('L'|'l')('S'|'s')('E'|'e'); + + +fragment +EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; + +fragment +HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; + +fragment +ESC_SEQ + : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') + | UNICODE_ESC + | OCTAL_ESC + ; + +fragment +OCTAL_ESC + : '\\' ('0'..'3') ('0'..'7') ('0'..'7') + | '\\' ('0'..'7') ('0'..'7') + | '\\' ('0'..'7') + ; + +fragment +UNICODE_ESC + : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT + ; + + + + +//NE : '!='; + + + +property : ID; + +containsproperty : ID; + +withinproperty : ID; + +booleanliteral: BOOLEAN; + + +longliteral : + LONG ; + +uuidliteral : + UUID; + +stringliteral : + STRING; + +floatliteral : + FLOAT ; + +//We delegate to each sub class literal so we can get each type +value : + booleanliteral + | longliteral + | uuidliteral + | stringliteral + | floatliteral + ; + + + +//Every operand returns with the name of 'op'. This is used because all subtrees require operands, +//this allows us to link the java code easily by using the same name as a converntion + +//begin search expressions + +//mathmatical equality operations +equalityop : + property LT^ value + |property LTE^ value + |property EQ^ value + |property GT^ value + |property GTE^ value + ; + +//geo location search +locationop : + withinproperty WITHIN^ (floatliteral|longliteral) OF! (floatliteral|longliteral) ','! (floatliteral|longliteral); + +//string search +containsop : + containsproperty CONTAINS^ stringliteral; + +// +operation : + '('! expression ')'! + | equalityop + | locationop + | containsop + ; + +//negations of expressions +notexp : +//only link if we have the not + NOT^ operation + |operation + ; + +//and expressions contain operands. These should always be closer to the leaves of a tree, it allows +//for faster result intersection sooner in the query execution +andexp : + notexp (AND^ notexp )*; + + +//or expression should always be after AND expressions. This will give us a smaller result set to union when evaluating trees +//also a root level expression +expression : + andexp (OR^ andexp )*; + + + +//end expressions + +//begin order clauses + +//direction for ordering +direction : (ASC | DESC); + +//order clause +order + : (property direction?){ + String property = $property.text; + String direction = $direction.text; + query.addSort(new SortPredicate(property, direction)); + + }; + +//end order clauses + +//Begin select clauses + +select_subject + : ID { + + query.addSelect($ID.text); + +}; + + + +select_assign + : target=ID ':' source=ID { + + query.addSelect($target.text, $source.text); + +}; + +select_expr + : ('*' | select_subject (',' select_subject) * | '{' select_assign (',' select_assign) * '}'); + +//end select clauses + +ql returns [Query query] + : ('select'! select_expr!)? ('where'!? expression)? ('order by'! order! (','! order!)*)? { + + if($expression.tree instanceof Operand){ + query.setRootOperand((Operand)$expression.tree); + } + + retval.query = query; + + +}; + + + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/QueryFilter.tokens ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/QueryFilter.tokens b/stack/corepersistence/queryindex/src/main/java/QueryFilter.tokens new file mode 100644 index 0000000..53a0817 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/QueryFilter.tokens @@ -0,0 +1,47 @@ +T__31=31 +T__32=32 +T__33=33 +T__34=34 +T__35=35 +T__36=36 +T__37=37 +T__38=38 +T__39=39 +T__40=40 +AND=4 +ASC=5 +BOOLEAN=6 +CONTAINS=7 +DESC=8 +EQ=9 +ESC_SEQ=10 +EXPONENT=11 +FALSE=12 +FLOAT=13 +GT=14 +GTE=15 +HEX_DIGIT=16 +ID=17 +LONG=18 +LT=19 +LTE=20 +NOT=21 +OCTAL_ESC=22 +OF=23 +OR=24 +STRING=25 +TRUE=26 +UNICODE_ESC=27 +UUID=28 +WITHIN=29 +WS=30 +'('=31 +')'=32 +'*'=33 +','=34 +':'=35 +'order by'=36 +'select'=37 +'where'=38 +'{'=39 +'}'=40 http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/ApplicationAlreadyExistsException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/ApplicationAlreadyExistsException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/ApplicationAlreadyExistsException.java new file mode 100644 index 0000000..788f9a2 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/ApplicationAlreadyExistsException.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class ApplicationAlreadyExistsException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 1L; + final String applicationName; + + + public ApplicationAlreadyExistsException( String applicationName ) { + super( "Application " + applicationName + " already exists" ); + this.applicationName = applicationName; + } + + + public String getApplicationName() { + return applicationName; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/DuplicateUniquePropertyExistsException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/DuplicateUniquePropertyExistsException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/DuplicateUniquePropertyExistsException.java new file mode 100644 index 0000000..7687dea --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/DuplicateUniquePropertyExistsException.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class DuplicateUniquePropertyExistsException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 1L; + final String entityType; + final String propertyName; + final Object propertyValue; + + + public DuplicateUniquePropertyExistsException( String entityType, String propertyName, Object propertyValue ) { + super( "Entity " + entityType + " requires that property named " + propertyName + " be unique, value of " + + propertyValue + " exists" ); + this.entityType = entityType; + this.propertyName = propertyName; + this.propertyValue = propertyValue; + } + + + public String getEntityType() { + return entityType; + } + + + public String getPropertyName() { + return propertyName; + } + + + public Object getPropertyValue() { + return propertyValue; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/EntityNotFoundException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/EntityNotFoundException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/EntityNotFoundException.java new file mode 100644 index 0000000..385f69b --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/EntityNotFoundException.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class EntityNotFoundException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = -3579346096812510039L; + + + public EntityNotFoundException() { + super(); + } + + + public EntityNotFoundException( String message, Throwable cause ) { + super( message, cause ); + } + + + public EntityNotFoundException( String message ) { + super( message ); + } + + + public EntityNotFoundException( Throwable cause ) { + super( cause ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java new file mode 100644 index 0000000..1f4cb5d --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonReadException.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class JsonReadException extends RuntimeException { + private static final long serialVersionUID = 1L; + + + public JsonReadException( String msg, Throwable t ) { + super( msg, t ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java new file mode 100644 index 0000000..22cf563 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/JsonWriteException.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class JsonWriteException extends RuntimeException { + private static final long serialVersionUID = 1L; + + + public JsonWriteException( String msg, Throwable t ) { + super( msg, t ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/LockingException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/LockingException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/LockingException.java new file mode 100644 index 0000000..7d01114 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/LockingException.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** General Exception for locking related operations. */ +public class LockingException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1630572186589575754L; + + + /** + * + */ + public LockingException() { + // TODO Auto-generated constructor stub + } + + + /** + * @param arg0 + */ + public LockingException( String arg0 ) { + super( arg0 ); + // TODO Auto-generated constructor stub + } + + + /** + * @param arg0 + */ + public LockingException( Throwable arg0 ) { + super( arg0 ); + // TODO Auto-generated constructor stub + } + + + /** + * @param arg0 + * @param arg1 + */ + public LockingException( String arg0, Throwable arg1 ) { + super( arg0, arg1 ); + // TODO Auto-generated constructor stub + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java new file mode 100644 index 0000000..793f623 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoFullTextIndexException.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** + * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed + * + * @author tnine + */ +public class NoFullTextIndexException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 1L; + final String entityType; + final String propertyName; + + + public NoFullTextIndexException( String entityType, String propertyName ) { + super( "Entity '" + entityType + "' with property named '" + propertyName + + "' is not full text indexed. You cannot use the 'contains' operand on this field" ); + this.entityType = entityType; + this.propertyName = propertyName; + } + + + public String getEntityType() { + return entityType; + } + + + public String getPropertyName() { + return propertyName; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java new file mode 100644 index 0000000..2ee5107 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NoIndexException.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** + * Thrown when the user attempts to perform a "contains" operation on a field that isn't full text indexed + * + * @author tnine + */ +public class NoIndexException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 1L; + final String entityType; + final String propertyName; + + + public NoIndexException( String entityType, String propertyName ) { + super( "Entity '" + entityType + "' with property named '" + propertyName + + "' is not indexed. You cannot use the this field in queries." ); + this.entityType = entityType; + this.propertyName = propertyName; + } + + + public String getEntityType() { + return entityType; + } + + + public String getPropertyName() { + return propertyName; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NotImplementedException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NotImplementedException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NotImplementedException.java new file mode 100644 index 0000000..52ee71e --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/NotImplementedException.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class NotImplementedException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + /** + * + */ + public NotImplementedException() { + super(); + } + + + /** + * @param message + * @param cause + */ + public NotImplementedException( String message, Throwable cause ) { + super( message, cause ); + } + + + /** + * @param message + */ + public NotImplementedException( String message ) { + super( message ); + } + + + /** + * @param cause + */ + public NotImplementedException( Throwable cause ) { + super( cause ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java new file mode 100644 index 0000000..dff5c8a --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PersistenceException.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class PersistenceException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + public PersistenceException() { + super(); + } + + + public PersistenceException( String message, Throwable cause ) { + super( message, cause ); + } + + + public PersistenceException( String message ) { + super( message ); + } + + + public PersistenceException( Throwable cause ) { + super( cause ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PropertyTypeConversionException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PropertyTypeConversionException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PropertyTypeConversionException.java new file mode 100644 index 0000000..90234e5 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/PropertyTypeConversionException.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class PropertyTypeConversionException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 1L; + final String entityType; + final String propertyName; + final Object propertyValue; + final Class propertyType; + + + public PropertyTypeConversionException( String entityType, String propertyName, Object propertyValue, + Class propertyType ) { + super( "Unable to convert property \"" + propertyName + "\" of entity \"" + entityType + + "\" from value of type " + propertyValue.getClass() + " to value of type " + propertyType ); + this.entityType = entityType; + this.propertyName = propertyName; + this.propertyValue = propertyValue; + this.propertyType = propertyType; + } + + + public PropertyTypeConversionException( String entityType, String propertyName, Object propertyValue, + Class propertyType, Throwable cause ) { + super( "Unable to convert property \"" + propertyName + "\" of entity \"" + entityType + + "\" from value of type " + propertyValue.getClass() + " to value of type " + propertyType, cause ); + this.entityType = entityType; + this.propertyName = propertyName; + this.propertyValue = propertyValue; + this.propertyType = propertyType; + } + + + public String getEntityType() { + return entityType; + } + + + public String getPropertyName() { + return propertyName; + } + + + public Object getPropertyValue() { + return propertyValue; + } + + + public Class getPropertyType() { + return propertyType; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryIterationException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryIterationException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryIterationException.java new file mode 100644 index 0000000..1acc76a --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryIterationException.java @@ -0,0 +1,13 @@ +package org.apache.usergrid.persistence.exceptions; + + +/** + * Thrown when an error occurs during query iteration + * + * @author tnine + */ +public class QueryIterationException extends RuntimeException { + public QueryIterationException( final String message ) { + super( message ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java new file mode 100644 index 0000000..d53144f --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryParseException.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** + * An exception thrown when a query cannot be parsed + * + * @author tnine + */ +public class QueryParseException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + /** + * + */ + public QueryParseException() { + super(); + } + + + /** + * @param arg0 + * @param arg1 + */ + public QueryParseException( String arg0, Throwable arg1 ) { + super( arg0, arg1 ); + } + + + /** + * @param arg0 + */ + public QueryParseException( String arg0 ) { + super( arg0 ); + } + + + /** + * @param arg0 + */ + public QueryParseException( Throwable arg0 ) { + super( arg0 ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java new file mode 100644 index 0000000..72f158a --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueryTokenException.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** + * An exception thrown when a query encounters a token it doesn't recognize + * @author tnine + */ +public class QueryTokenException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + + + /** + * @param arg0 + */ + public QueryTokenException( Throwable arg0 ) { + super( arg0 ); + } + + + @Override + public String getMessage() { + //antlr errors or strange. We have to do this, there's no message + return getCause().toString(); + } + + + @Override + public String getLocalizedMessage() { + return getMessage(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueueException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueueException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueueException.java new file mode 100644 index 0000000..07889a6 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/QueueException.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +/** General Exception for queue related operations. */ +public class QueueException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1630572186589575754L; + + + /** + * + */ + public QueueException() { + } + + + /** + * @param arg0 + */ + public QueueException( String arg0 ) { + super( arg0 ); + } + + + /** + * @param arg0 + */ + public QueueException( Throwable arg0 ) { + super( arg0 ); + } + + + /** + * @param arg0 + * @param arg1 + */ + public QueueException( String arg0, Throwable arg1 ) { + super( arg0, arg1 ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/RequiredPropertyNotFoundException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/RequiredPropertyNotFoundException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/RequiredPropertyNotFoundException.java new file mode 100644 index 0000000..850c925 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/RequiredPropertyNotFoundException.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class RequiredPropertyNotFoundException extends PersistenceException { + + private static final long serialVersionUID = 1L; + final String entityType; + final String propertyName; + + + public RequiredPropertyNotFoundException( String entityType, String propertyName ) { + super( "Entity " + entityType + " requires a property named " + propertyName ); + this.entityType = entityType; + this.propertyName = propertyName; + } + + + public String getEntityType() { + return entityType; + } + + + public String getPropertyName() { + return propertyName; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/TransactionNotFoundException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/TransactionNotFoundException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/TransactionNotFoundException.java new file mode 100644 index 0000000..21bc13e --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/TransactionNotFoundException.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class TransactionNotFoundException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = -3579346096812510039L; + + + public TransactionNotFoundException() { + super(); + } + + + public TransactionNotFoundException( String message, Throwable cause ) { + super( message, cause ); + } + + + public TransactionNotFoundException( String message ) { + super( message ); + } + + + public TransactionNotFoundException( Throwable cause ) { + super( cause ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/UnexpectedEntityTypeException.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/UnexpectedEntityTypeException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/UnexpectedEntityTypeException.java new file mode 100644 index 0000000..7f59830 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/exceptions/UnexpectedEntityTypeException.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2012 Apigee Corporation + * + * Licensed 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.usergrid.persistence.exceptions; + + +public class UnexpectedEntityTypeException extends PersistenceException { + + /** + * + */ + private static final long serialVersionUID = 8221919267880904834L; + + + public UnexpectedEntityTypeException() { + super(); + } + + + public UnexpectedEntityTypeException( String message, Throwable cause ) { + super( message, cause ); + } + + + public UnexpectedEntityTypeException( String message ) { + super( message ); + } + + + public UnexpectedEntityTypeException( Throwable cause ) { + super( cause ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java new file mode 100644 index 0000000..4652f81 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java @@ -0,0 +1,46 @@ +/* + * 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.usergrid.persistence.index; + +import org.apache.usergrid.persistence.model.entity.Entity; + + +/** + * Provides indexing of Entities within a scope. + */ +public interface EntityCollectionIndex { + + /** + * Create index for Entity + * @param entity Entity to be indexed. + */ + public void index( Entity entity ); + + /** + * Remove index of entity. + * @param entity Entity to be removed from index. + */ + public void deindex( Entity entity ); + + /** + * Simple query interface for testing using Lucene query syntax. + */ + public EntitySearchResults simpleQuery( String query, int from, int size ); +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntitySearchResults.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntitySearchResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntitySearchResults.java new file mode 100644 index 0000000..03e91d9 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntitySearchResults.java @@ -0,0 +1,65 @@ +/* + * 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.usergrid.persistence.index; + +import java.util.List; +import java.util.UUID; +import org.apache.usergrid.persistence.model.entity.Id; + + +/** + * Search results are Id and Version references to Entities. + */ +public class EntitySearchResults { + private final long count; + private final List refs; + + public EntitySearchResults( long count, List refs ) { + this.count = count; + this.refs = refs; + } + + public long count() { + return count; + } + + public List getRefs() { + return refs; + } + + /** + * Reference to one specific version of an Entity. + */ + public static final class Ref { + private Id id; + private UUID version; + + public Ref( Id id, UUID version ) { + this.id = id; + this.version = version; + } + public Id getId() { + return id; + } + public UUID getVersion() { + return version; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c0543f5f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexImpl.java new file mode 100644 index 0000000..c009a66 --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexImpl.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. 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. For additional information regarding + * copyright in this work, please see the NOTICE file in the top level + * directory of this distribution. + */ +package org.apache.usergrid.persistence.index.impl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import org.apache.usergrid.persistence.collection.CollectionScope; +import org.apache.usergrid.persistence.index.EntityCollectionIndex; +import org.apache.usergrid.persistence.index.EntitySearchResults; +import org.apache.usergrid.persistence.index.EntitySearchResults.Ref; +import org.apache.usergrid.persistence.model.entity.Entity; +import org.apache.usergrid.persistence.model.entity.SimpleId; +import org.apache.usergrid.persistence.model.field.ArrayField; +import org.apache.usergrid.persistence.model.field.EntityObjectField; +import org.apache.usergrid.persistence.model.field.Field; +import org.apache.usergrid.persistence.model.field.ListField; +import org.apache.usergrid.persistence.model.field.SetField; +import org.apache.usergrid.persistence.model.field.StringField; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.AdminClient; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.xcontent.XContentBuilder; +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import org.elasticsearch.index.query.QueryStringQueryBuilder; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHits; + + +public class EntityCollectionIndexImpl implements EntityCollectionIndex { + private final Client client; + private final String index; + private final boolean refresh; + private final CollectionScope scope; + + public static final String STRING_FIELD_SUFFIX = "_ug_analyzed"; + + + public EntityCollectionIndexImpl( Client client, String index, CollectionScope scope, boolean refresh ) { + this.client = client; + this.index = index; + this.scope = scope; + this.refresh = refresh; + + // if new index then create it + AdminClient admin = client.admin(); + if ( !admin.indices().exists( new IndicesExistsRequest( index )).actionGet().isExists() ) { + admin.indices().prepareCreate( index ).execute().actionGet(); + } + + // if new type then create mapping + if ( !admin.indices().typesExists( new TypesExistsRequest( + new String[] {index}, scope.getName() )).actionGet().isExists()) { + + try { + XContentBuilder mxcb = EntityCollectionIndexImpl + .createDoubleStringIndexMapping( jsonBuilder(), scope.getName() ); + + PutMappingResponse pmr = admin.indices().preparePutMapping(index) + .setType( scope.getName() ).setSource( mxcb ).execute().actionGet(); + + } catch ( IOException ex ) { + throw new RuntimeException("Error adding mapping for type " + scope.getName(), ex ); + } + } + } + + + public void index( Entity entity ) { + + Map entityAsMap = EntityCollectionIndexImpl.entityToMap( entity ); + + IndexRequestBuilder irb = client.prepareIndex(index, scope.getName(), createIndexId( entity )) + .setSource( entityAsMap ) + .setRefresh( refresh ); + + // Cannot set version. As far as I can tell ES insists that initial version number is -1 + // and that number is incremented by 1 on each update. + // irb = irb.setVersion( entity.getVersion().timestamp() ); + + IndexResponse ir = irb.execute().actionGet(); + } + + + private String createIndexId( Entity entity ) { + return entity.getId().getUuid().toString() + "|" + + entity.getId().getType() + "|" + + entity.getVersion().toString(); + } + + + public void deindex( Entity entity ) { + String compositeId = entity.getId().toString() + "|" + entity.getVersion().toString(); + client.prepareDelete( index, scope.getName(), compositeId).execute().actionGet(); + } + + + public EntitySearchResults simpleQuery( String query, int from, int size ) { + + QueryStringQueryBuilder builder = new QueryStringQueryBuilder( query ); + + SearchResponse sr = client.prepareSearch( index ).setTypes( scope.getName() ) + .setQuery( builder ).setFrom( from ).setSize( size ).execute().actionGet(); + + List refs = new ArrayList(); + SearchHits hits = sr.getHits(); + + for ( SearchHit hit : hits.getHits() ) { + + String[] idparts = hit.getId().split( "\\|" ); + String id = idparts[0]; + String type = idparts[1]; + String version = idparts[2]; + + Ref ref = new Ref( new SimpleId( UUID.fromString(id), type), UUID.fromString(version)); + refs.add( ref ); + } + + EntitySearchResults results = new EntitySearchResults( sr.getHits().getTotalHits(), refs ); + return results; + } + + + /** + * Convert Entity to Map, adding version_ug_field and a {name}_ug_analyzed field for each StringField. + */ + public static Map entityToMap( Entity entity ) { + + Map entityMap = new HashMap(); + + for ( Object f : entity.getFields().toArray() ) { + + if ( f instanceof ListField || f instanceof ArrayField ) { + Field field = (Field)f; + List list = (List)field.getValue(); + entityMap.put( field.getName(), + new ArrayList( processCollectionForMap( list ) ) ); + + } else if ( f instanceof SetField ) { + Field field = (Field)f; + Set set = (Set)field.getValue(); + entityMap.put( field.getName(), + new ArrayList( processCollectionForMap( set ) ) ); + + } else if ( f instanceof EntityObjectField ) { + Field field = (Field)f; + Entity ev = (Entity)field.getValue(); + entityMap.put( field.getName(), entityToMap( ev ) ); // recursion + + } else if ( f instanceof StringField ) { + Field field = (Field)f; + entityMap.put( field.getName(), field.getValue() ); + entityMap.put( field.getName() + STRING_FIELD_SUFFIX, field.getValue() ); + + } else { + Field field = (Field)f; + entityMap.put( field.getName(), field.getValue() ); + } + } + + return entityMap; + } + + + private static Collection processCollectionForMap( Collection c ) { + if ( c.isEmpty() ) { + return c; + } + List processed = new ArrayList(); + Object sample = c.iterator().next(); + + if ( sample instanceof Entity ) { + for ( Object o : c.toArray() ) { + Entity e = (Entity)o; + processed.add( entityToMap( e ) ); + } + + } else if ( sample instanceof List ) { + for ( Object o : c.toArray() ) { + List list = (List)o; + processed.add( processCollectionForMap( list ) ); // recursion; + } + + } else if ( sample instanceof Set ) { + for ( Object o : c.toArray() ) { + Set set = (Set)o; + processed.add( processCollectionForMap( set ) ); // recursion; + } + + } else { + for ( Object o : c.toArray() ) { + processed.add( o ); + } + } + return processed; + } + + + /** + * Build mappings for data to be indexed. Setup String fields as not_analyzed and analyzed, + * where the analyzed field is named {name}_ug_analyzed + * + * @param builder Add JSON object to this builder. + * @param type ElasticSearch type of entity. + * @return Content builder with JSON for mapping. + * + * @throws java.io.IOException On JSON generation error. + */ + public static XContentBuilder createDoubleStringIndexMapping( + XContentBuilder builder, String type ) throws IOException { + + builder = builder + .startObject() + .startObject( type ) + .startArray( "dynamic_templates" ) + + // any string with field name that ends with _ug_analyzed gets analyzed + .startObject() + .startObject( "template_1" ) + .field( "match", "*" + STRING_FIELD_SUFFIX) + .field( "match_mapping_type", "string") + .startObject( "mapping" ) + .field( "type", "string" ) + .field( "index", "analyzed" ) + .endObject() + .endObject() + .endObject() + + // all other strings are not analyzed + .startObject() + .startObject( "template_2" ) + .field( "match", "*") + .field( "match_mapping_type", "string") + .startObject( "mapping" ) + .field( "type", "string" ) + .field( "index", "not_analyzed" ) + .endObject() + .endObject() + .endObject() + + .endArray() + .endObject() + .endObject(); + + return builder; + } +}