├── .gitattributes ├── .gitignore ├── README.md ├── build.gradle ├── buildSrc └── src │ └── main │ └── groovy │ └── org │ └── hibernate │ └── build │ └── gradle │ └── api │ └── plugins │ └── antlr │ ├── Antlr3Extension.groovy │ ├── Antlr3Plugin.groovy │ ├── Antlr3Task.groovy │ ├── AntlrSourceVirtualDirectory.java │ └── internal │ └── AntlrSourceVirtualDirectoryImpl.java ├── copyright.txt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libraries.gradle ├── license.txt ├── lucene ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── hibernate │ │ └── hql │ │ └── lucene │ │ ├── LuceneProcessingChain.java │ │ ├── LuceneQueryParsingResult.java │ │ ├── internal │ │ ├── ClassBasedLuceneQueryResolverDelegate.java │ │ ├── LuceneQueryRendererDelegate.java │ │ ├── UntypedLuceneQueryResolverDelegate.java │ │ ├── ast │ │ │ ├── HSearchEmbeddedEntityTypeDescriptor.java │ │ │ ├── HSearchIndexedEntityTypeDescriptor.java │ │ │ ├── HSearchPropertyTypeDescriptor.java │ │ │ └── HSearchTypeDescriptor.java │ │ ├── builder │ │ │ ├── ClassBasedLucenePropertyHelper.java │ │ │ ├── FieldBridgeProviderBasedLucenePropertyHelper.java │ │ │ ├── LucenePropertyHelper.java │ │ │ └── predicate │ │ │ │ ├── LuceneComparisonPredicate.java │ │ │ │ ├── LuceneConjunctionPredicate.java │ │ │ │ ├── LuceneDisjunctionPredicate.java │ │ │ │ ├── LuceneInPredicate.java │ │ │ │ ├── LuceneIsNullPredicate.java │ │ │ │ ├── LuceneLikePredicate.java │ │ │ │ ├── LuceneNegationPredicate.java │ │ │ │ ├── LucenePredicateFactory.java │ │ │ │ ├── LuceneRangePredicate.java │ │ │ │ ├── LuceneRootPredicate.java │ │ │ │ └── MatchingContextSupport.java │ │ └── logging │ │ │ ├── Log.java │ │ │ └── LoggerFactory.java │ │ └── spi │ │ └── FieldBridgeProvider.java │ └── test │ ├── java │ └── org │ │ └── hibernate │ │ └── hql │ │ └── lucene │ │ ├── test │ │ ├── ClassBasedLuceneQueryParsingTest.java │ │ ├── LuceneQueryParsingTestBase.java │ │ ├── UntypedLuceneQueryParsingTest.java │ │ ├── internal │ │ │ └── builder │ │ │ │ ├── ClassBasedLucenePropertyHelperTest.java │ │ │ │ ├── LuceneQueryBuilderTest.java │ │ │ │ └── model │ │ │ │ └── IndexedEntity.java │ │ └── model │ │ │ ├── Address.java │ │ │ ├── Author.java │ │ │ ├── ContactAddress.java │ │ │ ├── ContactDetail.java │ │ │ ├── GenericValueHolder.java │ │ │ └── IndexedEntity.java │ │ └── testutil │ │ └── MapBasedEntityNamesResolver.java │ └── resources │ └── log4j.properties ├── parser ├── build.gradle └── src │ ├── main │ ├── antlr │ │ └── org │ │ │ └── hibernate │ │ │ └── hql │ │ │ └── ast │ │ │ ├── origin │ │ │ ├── hql │ │ │ │ ├── parse │ │ │ │ │ ├── HQLLexer.g │ │ │ │ │ └── HQLParser.g │ │ │ │ └── resolve │ │ │ │ │ └── GeneratedHQLResolver.g │ │ │ └── ordering │ │ │ │ └── OrderByParser.g │ │ │ └── render │ │ │ ├── OrderByRenderer.g │ │ │ ├── QueryRenderer.g │ │ │ └── SQLRenderer.g-tmp │ └── java │ │ └── org │ │ └── hibernate │ │ └── hql │ │ ├── ParsingException.java │ │ ├── QueryParser.java │ │ ├── ast │ │ ├── AnyTypeDescriptor.java │ │ ├── BasicTypeDescriptor.java │ │ ├── CollectionTypeDescriptor.java │ │ ├── CompositeTypeDescriptor.java │ │ ├── DefaultParsingContext.java │ │ ├── EntityTypeDescriptor.java │ │ ├── TemplateConstants.java │ │ ├── TypeDescriptor.java │ │ ├── alias │ │ │ └── ImplicitAliasGenerator.java │ │ ├── common │ │ │ ├── HibernateToken.java │ │ │ ├── HibernateTree.java │ │ │ ├── JoinType.java │ │ │ └── ParserContext.java │ │ ├── origin │ │ │ └── hql │ │ │ │ └── resolve │ │ │ │ └── path │ │ │ │ ├── AggregationPropertyPath.java │ │ │ │ ├── PathedPropertyReference.java │ │ │ │ ├── PathedPropertyReferenceSource.java │ │ │ │ └── PropertyPath.java │ │ ├── spi │ │ │ ├── AstProcessingChain.java │ │ │ ├── AstProcessor.java │ │ │ ├── EntityNamesResolver.java │ │ │ ├── PropertyHelper.java │ │ │ ├── QueryRendererDelegate.java │ │ │ ├── QueryRendererProcessor.java │ │ │ ├── QueryResolverDelegate.java │ │ │ ├── QueryResolverProcessor.java │ │ │ ├── SingleEntityHavingQueryBuilder.java │ │ │ ├── SingleEntityQueryBuilder.java │ │ │ ├── SingleEntityQueryRendererDelegate.java │ │ │ └── predicate │ │ │ │ ├── AbstractPredicate.java │ │ │ │ ├── ComparisonPredicate.java │ │ │ │ ├── ConjunctionPredicate.java │ │ │ │ ├── DisjunctionPredicate.java │ │ │ │ ├── InPredicate.java │ │ │ │ ├── IsNullPredicate.java │ │ │ │ ├── LikePredicate.java │ │ │ │ ├── NegatablePredicate.java │ │ │ │ ├── NegationPredicate.java │ │ │ │ ├── ParentPredicate.java │ │ │ │ ├── Predicate.java │ │ │ │ ├── PredicateFactory.java │ │ │ │ ├── RangePredicate.java │ │ │ │ └── RootPredicate.java │ │ └── tree │ │ │ ├── EntityNameTree.java │ │ │ └── PropertyPathTree.java │ │ └── internal │ │ ├── logging │ │ ├── Log.java │ │ └── LoggerFactory.java │ │ └── util │ │ └── Strings.java │ └── test │ ├── antlr3 │ └── org │ │ └── hibernate │ │ └── hql │ │ └── ast │ │ └── origin │ │ └── hql │ │ └── parse │ │ └── TestHQLTreeWalker.g │ ├── java │ └── org │ │ └── hibernate │ │ └── hql │ │ ├── test │ │ ├── ast │ │ │ └── QueryParserTest.java │ │ ├── grammars │ │ │ ├── GeneratedASTTest.java │ │ │ ├── HQLGrammarTest.java │ │ │ ├── HQLTokensTest.java │ │ │ └── SingleParserTest.java │ │ └── tree │ │ │ ├── HQLTreeWalkerTest.java │ │ │ └── ParsingTest.java │ │ └── testutil │ │ ├── TestForIssue.java │ │ └── TestingParserContext.java │ └── resources │ ├── log4j.properties │ └── org │ └── hibernate │ └── hql │ └── ast │ └── origin │ └── hql │ ├── parse │ ├── gUnitGeneratedAST.testsuite │ ├── gUnitHQLGrammar.testsuite │ └── gUnitHQLTokens.testsuite │ └── resolve │ └── gUnitHQLTreeWalker.todo ├── settings.gradle ├── shared └── config │ └── checkstyle │ └── checkstyle.xml └── testing ├── build.gradle └── src ├── main ├── antlr4-gradle │ └── GrammarTest.g4 ├── antlr4 │ └── org │ │ └── hibernate │ │ └── hql │ │ └── testing │ │ └── internal │ │ └── GrammarTest.g4 └── java │ └── org │ └── hibernate │ └── hql │ └── testing │ ├── ForGrammar.java │ ├── internal │ ├── junit │ │ ├── GrammarRuleStatement.java │ │ ├── GrammarRuleStatements.java │ │ └── GrammarRuleTest.java │ ├── model │ │ ├── GrammarRuleTestDescriptor.java │ │ ├── GrammarRuleTestGroupDescriptor.java │ │ ├── GrammarTestDescriptor.java │ │ ├── ParsingResult.java │ │ └── RuleType.java │ └── parser │ │ ├── GrammarRuleTestRunner.java │ │ ├── GrammarTestDescriptorBuildingListener.java │ │ └── GrammarTestParser.java │ └── junit │ └── GrammarTestRunner.java └── test ├── antlr └── com │ └── example │ └── calculator │ ├── Expr.g │ └── ExprAst.g ├── java └── org │ └── hibernate │ └── hql │ └── testing │ └── test │ ├── internal │ └── parser │ │ └── GrammarTestParserTest.java │ └── junit │ ├── GrammarTestRunnerAstTest.java │ ├── GrammarTestRunnerSubGroupsTest.java │ └── GrammarTestRunnerTest.java └── resources └── org └── hibernate └── hql └── testing └── test ├── expr.testsuite ├── exprAst.testsuite └── exprSubGroups.testsuite /.gitattributes: -------------------------------------------------------------------------------- 1 | # Repository specific GIT options 2 | 3 | # Set default handling of line terminators for all non explicitly listed file types: 4 | * text=auto 5 | 6 | # Force LF as internal repository format for all following files; 7 | # this overrides user settings to enforce the *right format* : 8 | *.java text 9 | *.xml text 10 | *.txt text 11 | *.md text 12 | *.g text 13 | *.testsuite text 14 | 15 | # Specify we want Java-friendly readable chunk headers for diff: 16 | 17 | *.java diff=java 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Typically *NIX text editors, by default, append '~' to files on saving to make backups 2 | *~ 3 | 4 | # Gradle work directory 5 | .gradle 6 | buildSrc/.gradle 7 | 8 | # Build output directies 9 | /*/target 10 | /*/build 11 | 12 | bin 13 | test-output 14 | antlr-generated 15 | 16 | # IntelliJ specific files/directories 17 | /out 18 | .idea 19 | *.ipr 20 | *.iws 21 | *.iml 22 | atlassian-ide-plugin.xml 23 | 24 | # Eclipse specific files/directories 25 | .classpath 26 | .project 27 | .settings 28 | .externalToolBuilders 29 | .factorypath 30 | 31 | # NetBeans specific files/directories 32 | .nbattrs 33 | 34 | # Miscellaneous 35 | *.log 36 | *.sh 37 | .clover 38 | 39 | /build 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hibernate Query Parser 2 | 3 | This repository held experimental work on a new parser for HQL and JP-QL queries. That work is no longer expiremental and is part of ORM 6.0 4 | 5 | This repository is considered obsolete and therefore archived 6 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/hibernate/build/gradle/api/plugins/antlr/Antlr3Extension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.hibernate.build.gradle.api.plugins.antlr 17 | 18 | /** 19 | * @author Strong Liu 20 | */ 21 | class Antlr3Extension { 22 | 23 | File outputDirectory; 24 | Boolean forceAllFilesToOutputDir; 25 | File lib; 26 | String language; 27 | String forcedLanguageOption; 28 | Boolean nfa; 29 | Boolean dfa; 30 | Boolean debug; 31 | Boolean trace; 32 | Boolean report; 33 | Boolean profile; 34 | Boolean print; 35 | Boolean depend; 36 | Boolean verbose; 37 | Boolean make; 38 | String messageFormat; 39 | Boolean xgrtree; 40 | Boolean xdfa; 41 | Boolean xnoprune; 42 | Boolean xnocollapse; 43 | Boolean xdbgconversion; 44 | Boolean xmultithreaded; 45 | Boolean xnomergestopstates; 46 | Boolean xdfaverbose; 47 | Boolean xwatchconversion; 48 | Boolean xdbgST; 49 | Integer xmaxinlinedfastates; 50 | Integer xmaxswitchcaselabels; 51 | Integer xminswitchalts; 52 | Integer xm; 53 | Integer xmaxdfaedges; 54 | Integer xconversiontimeout; 55 | Boolean xnfastates; 56 | Boolean xsavelexer; 57 | String version = "3.4"; 58 | } 59 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/hibernate/build/gradle/api/plugins/antlr/Antlr3Task.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | 19 | package org.hibernate.build.gradle.api.plugins.antlr 20 | 21 | import org.gradle.api.file.FileCollection 22 | import org.gradle.api.internal.ConventionTask 23 | import org.gradle.api.tasks.InputFiles 24 | import org.gradle.api.tasks.OutputDirectory 25 | import org.gradle.api.tasks.TaskAction 26 | import org.gradle.process.internal.DefaultJavaExecAction 27 | import org.gradle.process.internal.JavaExecAction 28 | 29 | /** 30 | * @author Strong Liu 31 | */ 32 | class Antlr3Task extends ConventionTask { 33 | /** 34 | * Class path holding the ANTLR 3 library. 35 | */ 36 | @InputFiles 37 | FileCollection antlr3Classpath 38 | @OutputDirectory 39 | File outputDirectory 40 | @InputFiles 41 | Set grammarFiles 42 | List args = [] 43 | 44 | File baseSourcePath 45 | 46 | final private static String MAIN = "org.antlr.Tool" 47 | 48 | private final JavaExecAction javaExecHandleBuilder; 49 | 50 | public Antlr3Task() { 51 | javaExecHandleBuilder = new DefaultJavaExecAction(project.fileResolver); 52 | } 53 | 54 | 55 | @TaskAction 56 | public void generate() { 57 | javaExecHandleBuilder.setMain(MAIN) 58 | javaExecHandleBuilder.classpath(getAntlr3Classpath()) 59 | javaExecHandleBuilder.args(getArgs()) 60 | if ( baseSourcePath != null && baseSourcePath.exists() ) { 61 | javaExecHandleBuilder.setWorkingDir(baseSourcePath) 62 | } 63 | javaExecHandleBuilder.execute(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/hibernate/build/gradle/api/plugins/antlr/AntlrSourceVirtualDirectory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.hibernate.build.gradle.api.plugins.antlr; 18 | 19 | import groovy.lang.Closure; 20 | import org.gradle.api.file.SourceDirectorySet; 21 | 22 | /** 23 | * Contract for a Gradle "convention object" that acts as a handler for what I call a virtual directory mapping, 24 | * injecting a virtual directory named 'antlr' into the project's various {@link org.gradle.api.tasks.SourceSet source 25 | * sets}. Its implementation gets pushed onto the {@link org.gradle.api.internal.DynamicObjectAware} portion of the 26 | * source set under the name 'antlr'. 27 | * 28 | * @author Steve Ebersole 29 | */ 30 | public interface AntlrSourceVirtualDirectory { 31 | public static final String NAME = "antlr"; 32 | 33 | /** 34 | * All Antlr source for this source set. 35 | * 36 | * @return The Antlr source. Never returns null. 37 | */ 38 | public SourceDirectorySet getAntlr(); 39 | 40 | /** 41 | * Configures the Antlr source for this set. The given closure is used to configure the {@code SourceDirectorySet} (see 42 | * {@link #getAntlr}) which contains the Antlr source. 43 | * 44 | * @param configureClosure The closure to use to configure the Antlr source. 45 | * @return this 46 | */ 47 | public AntlrSourceVirtualDirectory antlr(Closure configureClosure); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/hibernate/build/gradle/api/plugins/antlr/internal/AntlrSourceVirtualDirectoryImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.hibernate.build.gradle.api.plugins.antlr.internal; 17 | 18 | import groovy.lang.Closure; 19 | import org.gradle.api.file.SourceDirectorySet; 20 | import org.gradle.api.internal.file.DefaultSourceDirectorySet; 21 | import org.gradle.api.internal.file.FileResolver; 22 | import org.hibernate.build.gradle.api.plugins.antlr.AntlrSourceVirtualDirectory; 23 | import org.gradle.util.ConfigureUtil; 24 | 25 | /** 26 | * The implementation of the {@link org.gradle.api.plugins.antlr.AntlrSourceVirtualDirectory} contract. 27 | * 28 | * @author Steve Ebersole 29 | */ 30 | public class AntlrSourceVirtualDirectoryImpl implements AntlrSourceVirtualDirectory { 31 | private final SourceDirectorySet antlr; 32 | 33 | public AntlrSourceVirtualDirectoryImpl(String parentDisplayName, FileResolver fileResolver) { 34 | final String displayName = String.format("%s Antlr source", parentDisplayName); 35 | antlr = new DefaultSourceDirectorySet(displayName, fileResolver); 36 | antlr.getFilter().include("**/*.g"); 37 | } 38 | 39 | public SourceDirectorySet getAntlr() { 40 | return antlr; 41 | } 42 | 43 | public AntlrSourceVirtualDirectory antlr(Closure configureClosure) { 44 | ConfigureUtil.configure(configureClosure, getAntlr()); 45 | return this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /copyright.txt: -------------------------------------------------------------------------------- 1 | Red Hat, Inc. 2 | Alexandre Porcelli 3 | Sanne Grinovero 4 | Steve Ebersole 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibernate/hibernate-hql-parser/c228e535224c7083908c7a5ee1c2b5a50ce67684/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Oct 28 13:56:33 CET 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /libraries.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * Copyright (c) 2013, Red Hat Inc. or third-party contributors as 5 | * indicated by the @author tags or express copyright attribution 6 | * statements applied by the authors. All third-party contributions are 7 | * distributed under license by Red Hat Inc. 8 | * 9 | * This copyrighted material is made available to anyone wishing to use, modify, 10 | * copy, or redistribute it subject to the terms and conditions of the GNU 11 | * Lesser General Public License, as published by the Free Software Foundation. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this distribution; if not, write to: 20 | * Free Software Foundation, Inc. 21 | * 51 Franklin Street, Fifth Floor 22 | * Boston, MA 02110-1301 USA 23 | */ 24 | ext { 25 | antlr3Version = "3.4" 26 | antlr4Version = "4.0" 27 | hibernateSearchVersion = "5.8.0.Final" 28 | 29 | libraries = [ 30 | //Antlr 31 | antlr3_runtime: "org.antlr:antlr-runtime:${antlr3Version}", 32 | antlr4_runtime: "org.antlr:antlr4-runtime:${antlr4Version}", 33 | antlr4_generator: "org.antlr:antlr4:${antlr4Version}", 34 | 35 | //Search 36 | hibernate_search: "org.hibernate:hibernate-search-engine:${hibernateSearchVersion}", 37 | hibernate_search_tests: "org.hibernate:hibernate-search-engine:${hibernateSearchVersion}:tests", 38 | 39 | //JBoss logging 40 | jboss_logging: "org.jboss.logging:jboss-logging:3.1.4.GA", 41 | jboss_logging_processor: "org.jboss.logging:jboss-logging-processor:1.2.0.Final", 42 | 43 | //Animal Sniffer Ant Task and Java 1.6 API signature file 44 | //not using 1.9 for the time being due to MANIMALSNIFFER-34 45 | animal_sniffer: 'org.codehaus.mojo:animal-sniffer-ant-tasks:1.16', 46 | java18_signature: 'org.codehaus.mojo.signature:java18:1.0@signature', 47 | 48 | //Specs 49 | jpa_api: "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final", 50 | jta_api: "org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Final", 51 | 52 | //Testing 53 | junit: "junit:junit:4.11", 54 | fest_assert: "org.easytesting:fest-assert:1.4", 55 | 56 | //Misc. 57 | slf4j_api: "org.slf4j:slf4j-api:1.6.4", 58 | log4j: "log4j:log4j:1.2.16" 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /lucene/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile( libraries.hibernate_search ) 3 | compile( libraries.jpa_api ) 4 | compile project(':hibernate-hql-parser') 5 | compile( libraries.jboss_logging ) 6 | 7 | testCompile( libraries.hibernate_search_tests ) 8 | testCompile( libraries.log4j ) 9 | 10 | testRuntime( libraries.jta_api ) 11 | } 12 | 13 | compileJava.dependsOn generateMainLoggingClasses 14 | 15 | def pomName() { 16 | return "Hibernate HQL/JP-QL Walker for Lucene" 17 | } 18 | 19 | def pomDescription() { 20 | return "Creates Lucene query objects from HQL/JP-QL queries" 21 | } 22 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/ast/HSearchEmbeddedEntityTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.ast; 22 | 23 | import java.util.LinkedList; 24 | import java.util.List; 25 | 26 | import org.hibernate.hql.ast.TypeDescriptor; 27 | import org.hibernate.hql.lucene.internal.builder.ClassBasedLucenePropertyHelper; 28 | 29 | /** 30 | * A {@link TypeDescriptor} representing an embedded entity of a Hibernate Search indexed entity. 31 | * 32 | * @author Gunnar Morling 33 | */ 34 | public class HSearchEmbeddedEntityTypeDescriptor implements HSearchTypeDescriptor { 35 | 36 | private final Class indexedEntityType; 37 | private final List propertyPath; 38 | private final ClassBasedLucenePropertyHelper propertyHelper; 39 | 40 | /** 41 | * Creates a new {@link HSearchEmbeddedEntityTypeDescriptor}. 42 | * 43 | * @param indexedEntityType the indexed entity into which this entity is embedded 44 | * @param path the property path from the embedding indexed entity to this entity 45 | * @param propertyHelper a helper for dealing with properties 46 | */ 47 | public HSearchEmbeddedEntityTypeDescriptor(Class indexedEntityType, List path, ClassBasedLucenePropertyHelper propertyHelper) { 48 | this.indexedEntityType = indexedEntityType; 49 | this.propertyPath = path; 50 | this.propertyHelper = propertyHelper; 51 | } 52 | 53 | @Override 54 | public boolean hasProperty(String propertyName) { 55 | List newPath = new LinkedList( propertyPath ); 56 | newPath.add( propertyName ); 57 | return propertyHelper.exists( indexedEntityType, newPath ); 58 | } 59 | 60 | @Override 61 | public boolean isAnalyzed(String propertyName) { 62 | List newPath = new LinkedList( propertyPath ); 63 | newPath.add( propertyName ); 64 | return propertyHelper.isAnalyzed( indexedEntityType, newPath ); 65 | } 66 | 67 | @Override 68 | public boolean isEmbedded(String propertyName) { 69 | List newPath = new LinkedList( propertyPath ); 70 | newPath.add( propertyName ); 71 | return propertyHelper.isEmbedded( indexedEntityType, newPath ); 72 | } 73 | 74 | @Override 75 | public Class getIndexedEntityType() { 76 | return indexedEntityType; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return propertyPath.toString(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/ast/HSearchIndexedEntityTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.ast; 22 | 23 | import org.hibernate.hql.ast.TypeDescriptor; 24 | import org.hibernate.hql.lucene.internal.builder.ClassBasedLucenePropertyHelper; 25 | 26 | /** 27 | * A {@link TypeDescriptor} representing a Hibernate Search indexed entity. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public class HSearchIndexedEntityTypeDescriptor implements HSearchTypeDescriptor { 32 | 33 | private final Class indexedEntityType; 34 | private final ClassBasedLucenePropertyHelper propertyHelper; 35 | 36 | public HSearchIndexedEntityTypeDescriptor(Class indexedEntityType, ClassBasedLucenePropertyHelper propertyHelper) { 37 | this.indexedEntityType = indexedEntityType; 38 | this.propertyHelper = propertyHelper; 39 | } 40 | 41 | @Override 42 | public boolean hasProperty(String propertyName) { 43 | return propertyHelper.exists( indexedEntityType, propertyName ); 44 | } 45 | 46 | @Override 47 | public Class getIndexedEntityType() { 48 | return indexedEntityType; 49 | } 50 | 51 | @Override 52 | public boolean isAnalyzed(String propertyName) { 53 | return propertyHelper.isAnalyzed( indexedEntityType, propertyName ); 54 | } 55 | 56 | @Override 57 | public boolean isEmbedded(String propertyName) { 58 | return propertyHelper.isEmbedded( indexedEntityType, propertyName ); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return indexedEntityType.getCanonicalName(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/ast/HSearchPropertyTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.ast; 22 | 23 | import org.hibernate.hql.ast.TypeDescriptor; 24 | 25 | /** 26 | * A {@link TypeDescriptor} representing a property of a Hibernate Search indexed entity. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public class HSearchPropertyTypeDescriptor implements HSearchTypeDescriptor { 31 | 32 | public HSearchPropertyTypeDescriptor() { 33 | } 34 | 35 | @Override 36 | public boolean hasProperty(String propertyName) { 37 | return false; 38 | } 39 | 40 | @Override 41 | public Class getIndexedEntityType() { 42 | return null; 43 | } 44 | 45 | @Override 46 | public boolean isAnalyzed(String propertyName) { 47 | return false; 48 | } 49 | 50 | @Override 51 | public boolean isEmbedded(String propertyName) { 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/ast/HSearchTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.ast; 22 | 23 | import org.hibernate.hql.ast.TypeDescriptor; 24 | 25 | /** 26 | * A {@link TypeDescriptor} backed by HSearch type meta-data. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public interface HSearchTypeDescriptor extends TypeDescriptor { 31 | 32 | /** 33 | * Returns the Java type of the represented indexed entity. 34 | * 35 | * @return the Java type of the represented indexed entity 36 | */ 37 | Class getIndexedEntityType(); 38 | 39 | /** 40 | * Whether the given property of this indexed entity is analyzed or not. 41 | * 42 | * @param propertyName the name of the property 43 | * @return {@code true} if the given property is analyed, {@code false} otherwise. 44 | */ 45 | boolean isAnalyzed(String propertyName); 46 | 47 | /** 48 | * Whether the given property denotes an embedded entity or not. 49 | * 50 | * @param propertyName the name of the property 51 | * @return {@code true} if the given property denotes an entity embedded into this one, {@code false} otherwise. 52 | */ 53 | boolean isEmbedded(String propertyName); 54 | } 55 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/FieldBridgeProviderBasedLucenePropertyHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder; 22 | 23 | import java.util.List; 24 | 25 | import org.hibernate.hql.lucene.spi.FieldBridgeProvider; 26 | import org.hibernate.search.bridge.FieldBridge; 27 | import org.hibernate.search.bridge.builtin.NumericFieldBridge; 28 | import org.hibernate.search.bridge.util.impl.BridgeAdaptor; 29 | import org.hibernate.search.metadata.NumericFieldSettingsDescriptor.NumericEncodingType; 30 | 31 | /** 32 | * A {@link LucenePropertyHelper} which delegates retrieval of {@link FieldBridge}s to a {@link FieldBridgeProvider}. 33 | * 34 | * @author Gunnar Morling 35 | */ 36 | public class FieldBridgeProviderBasedLucenePropertyHelper extends LucenePropertyHelper { 37 | 38 | private final FieldBridgeProvider fieldBridgeProvider; 39 | 40 | public FieldBridgeProviderBasedLucenePropertyHelper(FieldBridgeProvider fieldBridgeProvider) { 41 | this.fieldBridgeProvider = fieldBridgeProvider; 42 | } 43 | 44 | @Override 45 | public FieldBridge getFieldBridge(String entityType, List propertyPath) { 46 | return fieldBridgeProvider.getFieldBridge( 47 | entityType, 48 | fieldName( propertyPath ) ); 49 | } 50 | 51 | @Override 52 | public NumericEncodingType getNumericEncodingType(String entityType, List propertyPath) { 53 | NumericFieldBridge numericFieldBridge = numericFieldBridge( entityType, propertyPath ); 54 | if ( numericFieldBridge != null ) { 55 | return numericFieldBridge.getEncodingType(); 56 | } 57 | return null; 58 | } 59 | 60 | private NumericFieldBridge numericFieldBridge(String entityType, List propertyPath) { 61 | FieldBridge fieldBridge = getFieldBridge( entityType, propertyPath ); 62 | if ( fieldBridge instanceof NumericFieldBridge ) { 63 | return (NumericFieldBridge) fieldBridge; 64 | } 65 | if ( fieldBridge instanceof BridgeAdaptor ) { 66 | return ( (BridgeAdaptor) fieldBridge ).unwrap( NumericFieldBridge.class ); 67 | } 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneComparisonPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.ComparisonPredicate; 25 | import org.hibernate.search.bridge.FieldBridge; 26 | import org.hibernate.search.query.dsl.QueryBuilder; 27 | 28 | /** 29 | * Lucene-based comparison predicate. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public class LuceneComparisonPredicate extends ComparisonPredicate { 34 | 35 | private final MatchingContextSupport matchingContextSupport; 36 | 37 | public LuceneComparisonPredicate(QueryBuilder builder, FieldBridge fieldBridge, String propertyName, Type comparisonType, Object value) { 38 | super( propertyName, comparisonType, value ); 39 | this.matchingContextSupport = new MatchingContextSupport( builder, fieldBridge, propertyName ); 40 | } 41 | 42 | @Override 43 | protected Query getStrictlyLessQuery() { 44 | return matchingContextSupport.rangeMatchingContext().below( value ).excludeLimit().createQuery(); 45 | } 46 | 47 | @Override 48 | protected Query getLessOrEqualsQuery() { 49 | return matchingContextSupport.rangeMatchingContext().below( value ).createQuery(); 50 | } 51 | 52 | @Override 53 | protected Query getEqualsQuery() { 54 | return matchingContextSupport.keyWordTermMatchingContext().matching( value ).createQuery(); 55 | } 56 | 57 | @Override 58 | protected Query getGreaterOrEqualsQuery() { 59 | return matchingContextSupport.rangeMatchingContext().above( value ).createQuery(); 60 | } 61 | 62 | @Override 63 | protected Query getStrictlyGreaterQuery() { 64 | return matchingContextSupport.rangeMatchingContext().above( value ).excludeLimit().createQuery(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneConjunctionPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.ConjunctionPredicate; 25 | import org.hibernate.hql.ast.spi.predicate.Predicate; 26 | import org.hibernate.search.query.dsl.BooleanJunction; 27 | import org.hibernate.search.query.dsl.QueryBuilder; 28 | 29 | /** 30 | * Lucene-based {@code AND} predicate. 31 | * 32 | * @author Gunnar Morling 33 | */ 34 | public class LuceneConjunctionPredicate extends ConjunctionPredicate { 35 | 36 | private final QueryBuilder builder; 37 | 38 | public LuceneConjunctionPredicate(QueryBuilder builder) { 39 | this.builder = builder; 40 | } 41 | 42 | @Override 43 | public Query getQuery() { 44 | BooleanJunction booleanJunction = builder.bool(); 45 | 46 | for ( Predicate predicate : children ) { 47 | // minor optimization: unwrap negated predicates and add child directly to this 48 | // predicate 49 | if ( predicate.getType() == Type.NEGATION ) { 50 | booleanJunction.must( predicate.as( LuceneNegationPredicate.class ).getChild().getQuery() ).not(); 51 | } 52 | else { 53 | booleanJunction.must( predicate.getQuery() ); 54 | } 55 | } 56 | 57 | return booleanJunction.createQuery(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneDisjunctionPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.DisjunctionPredicate; 25 | import org.hibernate.hql.ast.spi.predicate.Predicate; 26 | import org.hibernate.search.query.dsl.BooleanJunction; 27 | import org.hibernate.search.query.dsl.QueryBuilder; 28 | 29 | /** 30 | * Lucene-based {@code OR} predicate. 31 | * 32 | * @author Gunnar Morling 33 | */ 34 | public class LuceneDisjunctionPredicate extends DisjunctionPredicate { 35 | 36 | private final QueryBuilder builder; 37 | 38 | public LuceneDisjunctionPredicate(QueryBuilder builder) { 39 | this.builder = builder; 40 | } 41 | 42 | @Override 43 | public Query getQuery() { 44 | BooleanJunction booleanJunction = builder.bool(); 45 | 46 | for ( Predicate predicate : children ) { 47 | booleanJunction.should( predicate.getQuery() ); 48 | } 49 | 50 | return booleanJunction.createQuery(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneInPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import java.util.List; 24 | 25 | import org.apache.lucene.search.Query; 26 | import org.hibernate.hql.ast.spi.predicate.InPredicate; 27 | import org.hibernate.search.bridge.FieldBridge; 28 | import org.hibernate.search.query.dsl.QueryBuilder; 29 | 30 | /** 31 | * Lucene-based {@code IN} predicate in the form of disjoint {@code EQUALS} predicates for the given values. 32 | * 33 | * @author Gunnar Morling 34 | */ 35 | public class LuceneInPredicate extends InPredicate { 36 | 37 | private final QueryBuilder builder; 38 | private final FieldBridge fieldBridge; 39 | 40 | public LuceneInPredicate(QueryBuilder builder, FieldBridge fieldBridge, String propertyName, List values) { 41 | super( propertyName, values ); 42 | this.builder = builder; 43 | this.fieldBridge = fieldBridge; 44 | } 45 | 46 | @Override 47 | public Query getQuery() { 48 | LuceneDisjunctionPredicate predicate = new LuceneDisjunctionPredicate( builder ); 49 | 50 | for ( Object element : values ) { 51 | LuceneComparisonPredicate equals = new LuceneComparisonPredicate( 52 | builder, 53 | fieldBridge, 54 | propertyName, 55 | org.hibernate.hql.ast.spi.predicate.ComparisonPredicate.Type.EQUALS, element ); 56 | 57 | predicate.add( equals ); 58 | } 59 | 60 | return predicate.getQuery(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneIsNullPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.IsNullPredicate; 25 | import org.hibernate.search.bridge.FieldBridge; 26 | import org.hibernate.search.query.dsl.QueryBuilder; 27 | 28 | /** 29 | * Lucene-based {@code IS NULL} predicate. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public class LuceneIsNullPredicate extends IsNullPredicate { 34 | 35 | private final MatchingContextSupport matchingContextSupport; 36 | 37 | public LuceneIsNullPredicate(QueryBuilder builder, FieldBridge fieldBridge, String propertyName) { 38 | super( propertyName ); 39 | this.matchingContextSupport = new MatchingContextSupport( builder, fieldBridge, propertyName ); 40 | } 41 | 42 | @Override 43 | public Query getQuery() { 44 | return matchingContextSupport.keyWordTermMatchingContext().matching( null ).createQuery(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneLikePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import java.util.regex.Pattern; 24 | 25 | import org.apache.lucene.search.Query; 26 | import org.hibernate.hql.ast.spi.predicate.LikePredicate; 27 | import org.hibernate.search.bridge.FieldBridge; 28 | import org.hibernate.search.query.dsl.QueryBuilder; 29 | 30 | /** 31 | * Lucene-based {@code LIKE} predicate. 32 | * 33 | * @author Gunnar Morling 34 | */ 35 | public class LuceneLikePredicate extends LikePredicate { 36 | 37 | private static final String LUCENE_SINGLE_CHARACTER_WILDCARD = "?"; 38 | private static final String LUCENE_MULTIPLE_CHARACTERS_WILDCARD = "*"; 39 | 40 | private static final Pattern MULTIPLE_CHARACTERS_WILDCARD_PATTERN = Pattern.compile( "%" ); 41 | private static final Pattern SINGLE_CHARACTER_WILDCARD_PATTERN = Pattern.compile( "_" ); 42 | 43 | private final MatchingContextSupport matchingContextSupport; 44 | 45 | public LuceneLikePredicate(QueryBuilder builder, FieldBridge fieldBridge, String propertyName, String patternValue) { 46 | super( propertyName, patternValue, null ); 47 | this.matchingContextSupport = new MatchingContextSupport( builder, fieldBridge, propertyName ); 48 | } 49 | 50 | @Override 51 | public Query getQuery() { 52 | String patternValue = MULTIPLE_CHARACTERS_WILDCARD_PATTERN.matcher( this.patternValue ).replaceAll( LUCENE_MULTIPLE_CHARACTERS_WILDCARD ); 53 | patternValue = SINGLE_CHARACTER_WILDCARD_PATTERN.matcher( patternValue ).replaceAll( LUCENE_SINGLE_CHARACTER_WILDCARD ); 54 | 55 | return matchingContextSupport.wildcardTermMatchingContext().matching( patternValue ).createQuery(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneNegationPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.NegationPredicate; 25 | import org.hibernate.search.query.dsl.QueryBuilder; 26 | 27 | /** 28 | * Lucene-based {@code NOT} predicate. 29 | * 30 | * @author Gunnar Morling 31 | */ 32 | public class LuceneNegationPredicate extends NegationPredicate { 33 | 34 | private final QueryBuilder builder; 35 | 36 | public LuceneNegationPredicate(QueryBuilder builder) { 37 | this.builder = builder; 38 | } 39 | 40 | @Override 41 | public Query getQuery() { 42 | return builder.bool().must( getChild().getQuery() ).not().createQuery(); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "( NOT " + getChild() + " )"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneRangePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.RangePredicate; 25 | import org.hibernate.search.bridge.FieldBridge; 26 | import org.hibernate.search.query.dsl.QueryBuilder; 27 | 28 | /** 29 | * Lucene-based {@code BETWEEN} predicate. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public class LuceneRangePredicate extends RangePredicate { 34 | 35 | private final MatchingContextSupport matchingContextSupport; 36 | 37 | public LuceneRangePredicate(QueryBuilder builder, FieldBridge fieldBridge, String propertyName, Object lower, Object upper) { 38 | super( propertyName, lower, upper ); 39 | this.matchingContextSupport = new MatchingContextSupport( builder, fieldBridge, propertyName ); 40 | } 41 | 42 | @Override 43 | public Query getQuery() { 44 | return matchingContextSupport.rangeMatchingContext().from( lower ).to( upper ).createQuery(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/LuceneRootPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.apache.lucene.search.Query; 24 | import org.hibernate.hql.ast.spi.predicate.RootPredicate; 25 | import org.hibernate.search.query.dsl.QueryBuilder; 26 | 27 | /** 28 | * Lucene-based root predicate. 29 | * 30 | * @author Gunnar Morling 31 | */ 32 | public class LuceneRootPredicate extends RootPredicate { 33 | 34 | private final QueryBuilder builder; 35 | 36 | public LuceneRootPredicate(QueryBuilder builder) { 37 | this.builder = builder; 38 | } 39 | 40 | @Override 41 | public Query getQuery() { 42 | return child == null ? builder.all().createQuery() : child.getQuery(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/builder/predicate/MatchingContextSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.builder.predicate; 22 | 23 | import org.hibernate.search.bridge.FieldBridge; 24 | import org.hibernate.search.query.dsl.QueryBuilder; 25 | import org.hibernate.search.query.dsl.RangeMatchingContext; 26 | import org.hibernate.search.query.dsl.TermMatchingContext; 27 | import org.hibernate.search.query.dsl.impl.ConnectedRangeMatchingContext; 28 | import org.hibernate.search.query.dsl.impl.ConnectedTermMatchingContext; 29 | 30 | /** 31 | * Helper for creating DSL matching contexts, taking explicitly provided field bridges into account. 32 | * 33 | * @author Gunnar Morling 34 | */ 35 | /* package private */class MatchingContextSupport { 36 | 37 | QueryBuilder builder; 38 | FieldBridge fieldBridge; 39 | String propertyName; 40 | 41 | MatchingContextSupport(QueryBuilder builder, FieldBridge fieldBridge, String propertyName) { 42 | this.builder = builder; 43 | this.fieldBridge = fieldBridge; 44 | this.propertyName = propertyName; 45 | } 46 | 47 | TermMatchingContext keyWordTermMatchingContext() { 48 | if ( fieldBridge != null ) { 49 | return ( (ConnectedTermMatchingContext) builder.keyword().onField( propertyName ) ).withFieldBridge( fieldBridge ).ignoreAnalyzer(); 50 | } 51 | else { 52 | return builder.keyword().onField( propertyName ); 53 | } 54 | } 55 | 56 | TermMatchingContext wildcardTermMatchingContext() { 57 | if ( fieldBridge != null ) { 58 | return ( (ConnectedTermMatchingContext) builder.keyword().wildcard().onField( propertyName ) ).withFieldBridge( fieldBridge ).ignoreAnalyzer(); 59 | } 60 | else { 61 | return builder.keyword().wildcard().onField( propertyName ); 62 | } 63 | } 64 | 65 | RangeMatchingContext rangeMatchingContext() { 66 | if ( fieldBridge != null ) { 67 | return ( (ConnectedRangeMatchingContext) builder.range().onField( propertyName ) ).withFieldBridge( fieldBridge ).ignoreAnalyzer(); 68 | } 69 | else { 70 | return builder.range().onField( propertyName ); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/logging/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.logging; 22 | 23 | import org.hibernate.hql.ParsingException; 24 | import org.jboss.logging.BasicLogger; 25 | import org.jboss.logging.Message; 26 | import org.jboss.logging.MessageLogger; 27 | 28 | /** 29 | * Logging methods for the Lucene query parser component. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | @MessageLogger(projectCode = "HQL") 34 | public interface Log extends BasicLogger { 35 | 36 | // All parser components use the same project prefix HQL. We need to make sure that there is no id conflict 37 | int HQL_LUCENE__START_ID = 100000; 38 | 39 | @Message(id = HQL_LUCENE__START_ID + 1, value = "The type %s is not an indexed entity.") 40 | IllegalArgumentException getNoIndexedEntityException(String typeName); 41 | 42 | @Message(id = HQL_LUCENE__START_ID + 2, value = "The type %s has no indexed property named %s.") 43 | ParsingException getNoSuchPropertyException(String typeName, String propertyName); 44 | 45 | @Message(id = HQL_LUCENE__START_ID + 3, value = "No queries can be applied to property %2$s in type %1$s since the property is analyzed.") 46 | ParsingException getQueryOnAnalyzedPropertyNotSupportedException(String typeName, String propertyName); 47 | 48 | @Message(id = HQL_LUCENE__START_ID + 4, value = "Unknown alias: %s.") 49 | ParsingException getUnknownAliasException(String unknownAlias); 50 | 51 | @Message(id = HQL_LUCENE__START_ID + 5, value = "Property %2$s can not be selected from type %1$s since it is an embedded entity.") 52 | ParsingException getProjectionOfCompleteEmbeddedEntitiesNotSupportedException(String typeName, String propertyPath); 53 | } 54 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/internal/logging/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.internal.logging; 22 | 23 | import org.jboss.logging.Logger; 24 | 25 | /** 26 | * Factory for obtaining {@link Logger} instances. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public final class LoggerFactory { 31 | 32 | private static final CallerProvider callerProvider = new CallerProvider(); 33 | 34 | public static Log make() { 35 | return Logger.getMessageLogger( Log.class, callerProvider.getCallerClass().getCanonicalName() ); 36 | } 37 | 38 | private static class CallerProvider extends SecurityManager { 39 | 40 | public Class getCallerClass() { 41 | return getClassContext()[2]; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lucene/src/main/java/org/hibernate/hql/lucene/spi/FieldBridgeProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.spi; 22 | 23 | import org.hibernate.search.bridge.FieldBridge; 24 | 25 | /** 26 | * Implementations provide the field bridges to be applied for queries on the properties of an entity. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public interface FieldBridgeProvider { 31 | 32 | /** 33 | * Returns the field bridge to be applied when executing queries on the given property of the given entity type. 34 | * 35 | * @param type the entity type hosting the given property; may either identify an actual Java type or a virtual type 36 | * managed by the given implementation; never {@code null} 37 | * @param propertyPath a dot separated path denoting the property of interest, e.g. "foo" or "foo.bar" (in case this 38 | * is an embedded property); never {@code null} 39 | * @return the field bridge to be used for querying the given property; may be {@code null} 40 | */ 41 | FieldBridge getFieldBridge(String type, String propertyPath); 42 | } 43 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/internal/builder/model/IndexedEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.internal.builder.model; 22 | 23 | import java.util.Date; 24 | import javax.persistence.Id; 25 | 26 | import org.hibernate.search.annotations.Analyze; 27 | import org.hibernate.search.annotations.Field; 28 | import org.hibernate.search.annotations.FieldBridge; 29 | import org.hibernate.search.annotations.Indexed; 30 | import org.hibernate.search.annotations.NumericField; 31 | import org.hibernate.search.annotations.Parameter; 32 | import org.hibernate.search.bridge.builtin.StringEncodingDateBridge; 33 | 34 | /** 35 | * @author Gunnar Morling 36 | */ 37 | @Indexed 38 | public class IndexedEntity { 39 | 40 | private String id; 41 | private String name; 42 | private String description; 43 | 44 | private int i; 45 | private long l; 46 | private float f; 47 | private double d; 48 | 49 | private Date date; 50 | 51 | @Id 52 | public String getId() { 53 | return id; 54 | } 55 | 56 | public void setId(String id) { 57 | this.id = id; 58 | } 59 | 60 | @Field(analyze = Analyze.NO) 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | public void setName(String name) { 66 | this.name = name; 67 | } 68 | 69 | @Field(analyze = Analyze.YES) 70 | public String getDescription() { 71 | return description; 72 | } 73 | 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | 78 | @Field(analyze = Analyze.NO) 79 | @NumericField 80 | public int getI() { 81 | return i; 82 | } 83 | 84 | public void setI(int i) { 85 | this.i = i; 86 | } 87 | 88 | @Field(analyze = Analyze.NO) 89 | @NumericField 90 | public long getL() { 91 | return l; 92 | } 93 | 94 | public void setL(long l) { 95 | this.l = l; 96 | } 97 | 98 | @Field(analyze = Analyze.NO) 99 | @NumericField 100 | public float getF() { 101 | return f; 102 | } 103 | 104 | public void setF(float f) { 105 | this.f = f; 106 | } 107 | 108 | @Field(analyze = Analyze.NO) 109 | @NumericField 110 | public double getD() { 111 | return d; 112 | } 113 | 114 | public void setD(double d) { 115 | this.d = d; 116 | } 117 | 118 | @Field(analyze = Analyze.NO, bridge = @FieldBridge(impl = StringEncodingDateBridge.class, params = { @Parameter(name = "resolution", value = "DAY") })) 119 | public Date getDate() { 120 | return date; 121 | } 122 | 123 | public void setDate(Date date) { 124 | this.date = date; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/model/Address.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.model; 22 | 23 | import java.util.Set; 24 | 25 | import javax.persistence.Entity; 26 | import javax.persistence.Id; 27 | import javax.persistence.OneToMany; 28 | 29 | import org.hibernate.search.annotations.ContainedIn; 30 | import org.hibernate.search.annotations.Field; 31 | import org.hibernate.search.annotations.Store; 32 | 33 | /** 34 | * @author Gunnar Morling 35 | */ 36 | @Entity 37 | public class Address { 38 | 39 | @Id 40 | private Long id; 41 | 42 | @Field(store = Store.YES) 43 | private String street; 44 | 45 | @Field 46 | private String city; 47 | 48 | @ContainedIn 49 | @OneToMany(mappedBy = "address") 50 | private Set authors; 51 | 52 | public Long getId() { 53 | return id; 54 | } 55 | 56 | public void setId(Long id) { 57 | this.id = id; 58 | } 59 | 60 | public String getStreet() { 61 | return street; 62 | } 63 | 64 | public void setStreet(String street) { 65 | this.street = street; 66 | } 67 | 68 | public String getCity() { 69 | return city; 70 | } 71 | 72 | public void setCity(String city) { 73 | this.city = city; 74 | } 75 | 76 | public Set getAuthors() { 77 | return authors; 78 | } 79 | 80 | public void setAuthors(Set authors) { 81 | this.authors = authors; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/model/Author.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.model; 22 | 23 | import java.util.Set; 24 | 25 | import javax.persistence.CascadeType; 26 | import javax.persistence.Entity; 27 | import javax.persistence.Id; 28 | import javax.persistence.OneToMany; 29 | import javax.persistence.OneToOne; 30 | 31 | import org.hibernate.search.annotations.Analyze; 32 | import org.hibernate.search.annotations.ContainedIn; 33 | import org.hibernate.search.annotations.Field; 34 | import org.hibernate.search.annotations.IndexedEmbedded; 35 | import org.hibernate.search.annotations.Store; 36 | 37 | /** 38 | * @author Gunnar Morling 39 | */ 40 | @Entity 41 | public class Author { 42 | 43 | @Id 44 | private Long id; 45 | 46 | @Field(store = Store.YES, analyze = Analyze.NO) 47 | private String name; 48 | 49 | @ContainedIn 50 | @OneToMany(mappedBy = "author") 51 | private Set indexedEntities; 52 | 53 | @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }) 54 | @IndexedEmbedded 55 | private Address address; 56 | 57 | public Long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(Long id) { 62 | this.id = id; 63 | } 64 | 65 | public String getName() { 66 | return name; 67 | } 68 | 69 | public void setName(String name) { 70 | this.name = name; 71 | } 72 | 73 | public Set getIndexedEntities() { 74 | return indexedEntities; 75 | } 76 | 77 | public void setIndexedEntities(Set indexedEntities) { 78 | this.indexedEntities = indexedEntities; 79 | } 80 | 81 | public Address getAddress() { 82 | return address; 83 | } 84 | 85 | public void setAddress(Address address) { 86 | this.address = address; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/model/ContactAddress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.model; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import javax.persistence.Embeddable; 27 | 28 | import org.hibernate.search.annotations.Analyze; 29 | import org.hibernate.search.annotations.Field; 30 | import org.hibernate.search.annotations.IndexedEmbedded; 31 | 32 | /** 33 | * @author Davide D'Alto 34 | */ 35 | @Embeddable 36 | public class ContactAddress { 37 | 38 | private String address; 39 | private String postCode; 40 | private List alternatives = new ArrayList(); 41 | 42 | @Field(analyze = Analyze.NO) 43 | public String getAddress() { 44 | return address; 45 | } 46 | 47 | public void setAddress(String address) { 48 | this.address = address; 49 | } 50 | 51 | @Field(analyze = Analyze.NO) 52 | public String getPostCode() { 53 | return postCode; 54 | } 55 | 56 | public void setPostCode(String postCode) { 57 | this.postCode = postCode; 58 | } 59 | 60 | @IndexedEmbedded(depth = 3) 61 | public List getAlternatives() { 62 | return alternatives; 63 | } 64 | 65 | public void setAlternatives(List alternatives) { 66 | this.alternatives = alternatives; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/model/ContactDetail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.model; 22 | 23 | import javax.persistence.Embeddable; 24 | 25 | import org.hibernate.search.annotations.Analyze; 26 | import org.hibernate.search.annotations.Field; 27 | import org.hibernate.search.annotations.IndexedEmbedded; 28 | 29 | /** 30 | * @author Davide D'Alto 31 | */ 32 | @Embeddable 33 | public class ContactDetail { 34 | 35 | private String email; 36 | private String phoneNumber; 37 | private ContactAddress address; 38 | 39 | @Field( analyze = Analyze.NO ) 40 | public String getEmail() { 41 | return email; 42 | } 43 | 44 | public void setEmail(String email) { 45 | this.email = email; 46 | } 47 | 48 | @Field( analyze = Analyze.NO ) 49 | public String getPhoneNumber() { 50 | return phoneNumber; 51 | } 52 | 53 | public void setPhoneNumber(String phoneNumber) { 54 | this.phoneNumber = phoneNumber; 55 | } 56 | 57 | @IndexedEmbedded 58 | public ContactAddress getAddress() { 59 | return address; 60 | } 61 | 62 | public void setAddress(ContactAddress address) { 63 | this.address = address; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/test/model/GenericValueHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.test.model; 22 | 23 | import org.hibernate.search.annotations.Indexed; 24 | import org.hibernate.search.annotations.ProvidedId; 25 | 26 | /** 27 | * A wrapper type used for querying non-class based types. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | @Indexed 32 | @ProvidedId 33 | public class GenericValueHolder { 34 | } 35 | -------------------------------------------------------------------------------- /lucene/src/test/java/org/hibernate/hql/lucene/testutil/MapBasedEntityNamesResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.lucene.testutil; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | import org.hibernate.hql.ast.spi.EntityNamesResolver; 27 | 28 | /** 29 | * A simple {@link EntityNamesResolver} implementation which resolves using their qualified and unqualified names. 30 | * 31 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 32 | * @author Gunnar Morling 33 | */ 34 | public class MapBasedEntityNamesResolver implements EntityNamesResolver { 35 | 36 | private final Map> entityNames; 37 | 38 | public MapBasedEntityNamesResolver(Map> entityNames) { 39 | this.entityNames = entityNames; 40 | } 41 | 42 | @Override 43 | public Class getClassFromName(String entityName) { 44 | return entityNames.get( entityName ); 45 | } 46 | 47 | public static MapBasedEntityNamesResolver forClasses(Class... classes) { 48 | Map> entityNames = new HashMap>(); 49 | 50 | for ( Class clazz : classes ) { 51 | entityNames.put( clazz.getCanonicalName(), clazz ); 52 | entityNames.put( clazz.getSimpleName(), clazz ); 53 | } 54 | 55 | return new MapBasedEntityNamesResolver( entityNames ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lucene/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # Copyright (c) 2013, Red Hat Inc. or third-party contributors as 5 | # indicated by the @author tags or express copyright attribution 6 | # statements applied by the authors. All third-party contributions are 7 | # distributed under license by Red Hat Inc. 8 | # 9 | # This copyrighted material is made available to anyone wishing to use, modify, 10 | # copy, or redistribute it subject to the terms and conditions of the GNU 11 | # Lesser General Public License, as published by the Free Software Foundation. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | # for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with this distribution; if not, write to: 20 | # Free Software Foundation, Inc. 21 | # 51 Franklin Street, Fifth Floor 22 | # Boston, MA 02110-1301 USA 23 | # 24 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 25 | log4j.appender.stdout.Target=System.out 26 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 27 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 28 | 29 | log4j.rootLogger=info, stdout 30 | 31 | log4j.logger.org.hibernate.test=info 32 | log4j.logger.org.hibernate.hql=debug 33 | -------------------------------------------------------------------------------- /parser/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: org.hibernate.build.gradle.api.plugins.antlr.Antlr3Plugin 2 | 3 | dependencies { 4 | compile( libraries.antlr3_runtime ) 5 | compile( libraries.jboss_logging ) 6 | 7 | testCompile project(':hibernate-hql-testing') 8 | } 9 | 10 | compileJava.dependsOn generateMainLoggingClasses 11 | 12 | def pomName() { 13 | return "Hibernate HQL/JP-QL Parser" 14 | } 15 | 16 | def pomDescription() { 17 | return "Extensible parser for HQL/JP-QL queries" 18 | } 19 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ParsingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql; 22 | 23 | /** 24 | * Raised in case an error ocurred when parsing a JPQL query or walking the resulting parse tree. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public class ParsingException extends RuntimeException { 29 | 30 | public ParsingException(String message) { 31 | super( message ); 32 | } 33 | 34 | public ParsingException(Throwable cause) { 35 | super( cause ); 36 | } 37 | 38 | public ParsingException(String message, Throwable cause) { 39 | super( message, cause ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/AnyTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public class AnyTypeDescriptor { 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/BasicTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public interface BasicTypeDescriptor { 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/CollectionTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public interface CollectionTypeDescriptor { 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/CompositeTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public interface CompositeTypeDescriptor { 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/DefaultParsingContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | import org.hibernate.hql.ast.alias.ImplicitAliasGenerator; 27 | import org.hibernate.hql.ast.common.ParserContext; 28 | 29 | /** 30 | * @author Sanne Grinovero (C) 2011 Red Hat Inc. 31 | */ 32 | public class DefaultParsingContext implements ParserContext { 33 | 34 | private final ImplicitAliasGenerator implicitAliasGenerator = new ImplicitAliasGenerator(); 35 | 36 | @Override 37 | public List getEntityImplementors(String entityName) { 38 | return Collections.singletonList( entityName ); 39 | } 40 | 41 | @Override 42 | public String buildUniqueImplicitAlias() { 43 | return implicitAliasGenerator.buildUniqueImplicitAlias(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/EntityTypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public interface EntityTypeDescriptor { 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/TemplateConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | public class TemplateConstants { 24 | 25 | public static final String TEMPLATE = "$PlaceHolder$"; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/TypeDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast; 22 | 23 | /** 24 | * @author Steve Ebersole 25 | */ 26 | public interface TypeDescriptor { 27 | 28 | boolean hasProperty(String propertyName); 29 | } 30 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/alias/ImplicitAliasGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * Copyright (c) 2008, Red Hat Inc. or third-party contributors as 5 | * indicated by the @author tags or express copyright attribution 6 | * statements applied by the authors. All third-party contributions are 7 | * distributed under license by Red Hat Inc. 8 | * 9 | * This copyrighted material is made available to anyone wishing to use, modify, 10 | * copy, or redistribute it subject to the terms and conditions of the GNU 11 | * Lesser General Public License, as published by the Free Software Foundation. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this distribution; if not, write to: 20 | * Free Software Foundation, Inc. 21 | * 51 Franklin Street, Fifth Floor 22 | * Boston, MA 02110-1301 USA 23 | */ 24 | package org.hibernate.hql.ast.alias; 25 | 26 | /** 27 | * Handles generating implicit (or synthetic) aliases. 28 | * 29 | * @author Steve Ebersole 30 | */ 31 | public class ImplicitAliasGenerator { 32 | private int unaliasedCount = 0; 33 | 34 | /** 35 | * Builds a unique implicit alias. 36 | * 37 | * @return The generated alias. 38 | */ 39 | public synchronized String buildUniqueImplicitAlias() { 40 | return ""; 41 | } 42 | 43 | /** 44 | * Determine if the given alias is implicit. 45 | * 46 | * @param alias The alias to check 47 | * @return True/false. 48 | */ 49 | public static boolean isImplicitAlias(String alias) { 50 | return alias == null || ( alias.startsWith( "" ) ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/common/HibernateToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2009 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.common; 22 | 23 | import org.antlr.runtime.CharStream; 24 | import org.antlr.runtime.CommonToken; 25 | import org.antlr.runtime.Token; 26 | 27 | /** 28 | * Models the token-type/text portion of an Antlr tree for a specific node in said tree. 29 | * 30 | * @author Steve Ebersole 31 | * @author Alexandre Porcelli 32 | */ 33 | public class HibernateToken extends CommonToken { 34 | public HibernateToken(int type) { 35 | super( type ); 36 | } 37 | 38 | public HibernateToken(CharStream input, int type, int channel, int start, int stop) { 39 | super( input, type, channel, start, stop ); 40 | } 41 | 42 | public HibernateToken(int type, String text) { 43 | super( type, text ); 44 | } 45 | 46 | /** 47 | * Constructor that preserves the char offset 48 | * 49 | * @param oldToken A token to use to template the creation of this new one. 50 | */ 51 | public HibernateToken(Token oldToken) { 52 | super( oldToken ); 53 | if ( null != oldToken && CommonToken.class.isInstance( oldToken ) ) { 54 | setStartIndex( ( (CommonToken)oldToken ).getStartIndex() ); 55 | setStopIndex( ( (CommonToken)oldToken ).getStopIndex() ); 56 | } 57 | } 58 | 59 | /** 60 | * Constructor form used to track origination position information via the passed 61 | * 'oldToken' param, but to utilize a new token type and text. 62 | * 63 | * @param oldToken The original token type (used for position tracking info). 64 | * @param type The type of the new (this) token 65 | * @param text The test of the new (this) token. 66 | */ 67 | public HibernateToken(Token oldToken, int type, String text) { 68 | this( oldToken ); 69 | setType( type ); 70 | setText( text ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/common/HibernateTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2009 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.common; 22 | 23 | import org.antlr.runtime.Token; 24 | import org.antlr.runtime.tree.CommonTree; 25 | import org.antlr.runtime.tree.Tree; 26 | 27 | /** 28 | * todo : javadocs 29 | * 30 | * @author Steve Ebersole 31 | * @author Alexandre Porcelli 32 | */ 33 | public class HibernateTree extends CommonTree { 34 | /** 35 | * start char offset 36 | */ 37 | int startCharOffset = -1; 38 | 39 | /** 40 | * end char offset 41 | */ 42 | int endCharOffset = -1; 43 | 44 | public HibernateTree() { 45 | } 46 | 47 | public HibernateTree(HibernateTree node) { 48 | super( node ); 49 | this.token = node.token; 50 | } 51 | 52 | public HibernateTree(CommonTree node) { 53 | super( node ); 54 | this.token = node.token; 55 | } 56 | 57 | public HibernateTree(Token token) { 58 | super( token ); 59 | } 60 | 61 | public HibernateTree(int type, String text) { 62 | this( new HibernateToken( type, text ) ); 63 | } 64 | 65 | public HibernateTree(int type) { 66 | this( new HibernateToken( type ) ); 67 | } 68 | 69 | @Override 70 | public Tree dupNode() { 71 | return new HibernateTree( this ); 72 | } 73 | 74 | /** 75 | * getter for start char offset 76 | * 77 | * @return start char offset 78 | */ 79 | public int getStartCharOffset() { 80 | return startCharOffset; 81 | } 82 | 83 | /** 84 | * setter for start char offset 85 | * 86 | * @param startCharOffset 87 | * start char offset 88 | */ 89 | public void setStartCharOffset(int startCharOffset) { 90 | this.startCharOffset = startCharOffset; 91 | } 92 | 93 | /** 94 | * getter of end char offset 95 | * 96 | * @return end char offset 97 | */ 98 | public int getEndCharOffset() { 99 | return endCharOffset; 100 | } 101 | 102 | /** 103 | * setter of end char offset 104 | * 105 | * @param endCharOffset 106 | * end char offset 107 | */ 108 | public void setEndCharOffset(int endCharOffset) { 109 | this.endCharOffset = endCharOffset; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/common/ParserContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.common; 22 | 23 | import java.util.List; 24 | 25 | public interface ParserContext { 26 | 27 | String buildUniqueImplicitAlias(); 28 | 29 | List getEntityImplementors(String entityName); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/origin/hql/resolve/path/AggregationPropertyPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.origin.hql.resolve.path; 22 | 23 | /** 24 | * An aggregated property path (e.g. {@code SUM(foo.bar.baz)}) represented by {@link PathedPropertyReferenceSource}s used 25 | * with an aggregation function in the SELECT, HAVING or ORDER BY clause. 26 | * 27 | * @author Adrian Nistor 28 | */ 29 | public final class AggregationPropertyPath extends PropertyPath { 30 | 31 | /** 32 | * The aggregation function. 33 | */ 34 | public enum Type { 35 | SUM, AVG, MIN, MAX, COUNT, COUNT_DISTINCT 36 | } 37 | 38 | private final Type type; 39 | 40 | public AggregationPropertyPath(Type type, PropertyPath propertyPath) { 41 | super( propertyPath ); 42 | this.type = type; 43 | } 44 | 45 | public Type getType() { 46 | return type; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "AggregationPropertyPath [type=" + type + ", path=" + path + "]"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/origin/hql/resolve/path/PathedPropertyReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.origin.hql.resolve.path; 22 | 23 | import org.hibernate.hql.ast.TypeDescriptor; 24 | 25 | /** 26 | * @author Sanne Grinovero (C) 2011 Red Hat Inc. 27 | */ 28 | public final class PathedPropertyReference implements PathedPropertyReferenceSource { 29 | 30 | private final String name; 31 | private final TypeDescriptor type; 32 | private final boolean alias; 33 | 34 | public PathedPropertyReference(String name, TypeDescriptor type, boolean alias) { 35 | this.name = name; 36 | this.type = type; 37 | this.alias = alias; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | @Override 46 | public TypeDescriptor getType() { 47 | return type; 48 | } 49 | 50 | @Override 51 | public boolean isAlias() { 52 | return alias; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return name; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/origin/hql/resolve/path/PathedPropertyReferenceSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.origin.hql.resolve.path; 22 | 23 | import org.hibernate.hql.ast.TypeDescriptor; 24 | 25 | public interface PathedPropertyReferenceSource { 26 | 27 | String getName(); 28 | 29 | TypeDescriptor getType(); 30 | 31 | boolean isAlias(); 32 | } 33 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/origin/hql/resolve/path/PropertyPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.origin.hql.resolve.path; 22 | 23 | import java.util.ArrayList; 24 | import java.util.LinkedList; 25 | import java.util.List; 26 | 27 | import org.hibernate.hql.internal.util.Strings; 28 | 29 | /** 30 | * Represents a path of properties (e.g. {@code foo.bar.baz}) represented by {@link PathedPropertyReferenceSource}s used 31 | * in a SELECT, GROUP BY, WHERE or HAVING clause. 32 | * 33 | * @author Gunnar Morling 34 | */ 35 | public class PropertyPath { 36 | 37 | protected final LinkedList path; 38 | 39 | /** 40 | * Creates an empty path. 41 | */ 42 | public PropertyPath() { 43 | path = new LinkedList(); 44 | } 45 | 46 | /** 47 | * Creates a copy of a given path. 48 | * 49 | * @param other the path to copy; can be {@code null} 50 | */ 51 | public PropertyPath(PropertyPath other) { 52 | path = other != null ? new LinkedList( other.path ) 53 | : new LinkedList(); 54 | } 55 | 56 | public void appendNode(PathedPropertyReferenceSource property) { 57 | path.add( property ); 58 | } 59 | 60 | public PathedPropertyReferenceSource getLastNode() { 61 | return path.getLast(); 62 | } 63 | 64 | public PathedPropertyReferenceSource getFirstNode() { 65 | return path.getFirst(); 66 | } 67 | 68 | public List getNodes() { 69 | return new LinkedList( path ); 70 | } 71 | 72 | public String asStringPathWithoutAlias() { 73 | if ( path.isEmpty() ) { 74 | return null; 75 | } 76 | 77 | return Strings.join( getNodeNamesWithoutAlias(), "." ); 78 | } 79 | 80 | public List getNodeNamesWithoutAlias() { 81 | List nodeNames = new ArrayList(); 82 | 83 | for ( PathedPropertyReferenceSource node : path ) { 84 | if ( !node.isAlias() ) { 85 | nodeNames.add( node.getName() ); 86 | } 87 | } 88 | 89 | return nodeNames; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return "PropertyPath [path=" + path + "]"; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/AstProcessingChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import java.util.Iterator; 24 | 25 | /** 26 | * A chain of {@link AstProcessor}s which are applied sequentially on an AST. Implementations must ensure that the chain 27 | * is consistent, i.e. each processor understands the AST as created or modified by the previous processor. 28 | * 29 | * @author Gunnar Morling 30 | * @param The result type of this chain as obtained from the last processor 31 | */ 32 | public interface AstProcessingChain extends Iterable { 33 | 34 | /** 35 | * Returns an iterator with the processors of this chain. 36 | * 37 | * @return an iterator with the processors of this chain 38 | */ 39 | @Override 40 | Iterator iterator(); 41 | 42 | /** 43 | * The processing result of this chain, as usually retrieved from the last processor. 44 | * 45 | * @return the processing result of this chain 46 | */ 47 | T getResult(); 48 | } 49 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/AstProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import org.antlr.runtime.RecognitionException; 24 | import org.antlr.runtime.TokenStream; 25 | import org.antlr.runtime.tree.CommonTree; 26 | 27 | /** 28 | * A processor for an AST, may inspect or alter the given AST. Usually implemented in form of an AST walker 29 | * generated from a tree grammar. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public interface AstProcessor { 34 | 35 | /** 36 | * Processes the given tree. 37 | * 38 | * @param tokens the token stream of the tree. 39 | * @param tree the input tree 40 | * @return the processed tree 41 | * @throws RecognitionException in case of an illegal input tree 42 | */ 43 | CommonTree process(TokenStream tokens, CommonTree tree) throws RecognitionException; 44 | } 45 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/EntityNamesResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | /** 24 | * Map entity names to entity classes. An entity name might be 25 | * the fully qualified class name or a short hand description. 26 | * 27 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 28 | */ 29 | public interface EntityNamesResolver { 30 | 31 | Class getClassFromName(String entityName); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/PropertyHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Helper dealing with entity properties. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public interface PropertyHelper { 31 | 32 | /** 33 | * Converts the given string value specified via JP-QL into the actual type of the given property. 34 | * 35 | * @param entityType the entity type owning the property 36 | * @param propertyPath the path from the entity to the property (will only contain more than one element in case the 37 | * entity is hosted on an embedded entity). 38 | * @param value the value of the property 39 | * @return the property value, converted into the actual type of the given entity property 40 | */ 41 | Object convertToPropertyType(String entityType, List propertyPath, String value); 42 | 43 | /** 44 | * Converts the given property value into the type expected by the query backend. 45 | * 46 | * @param entityType the entity type owning the property 47 | * @param propertyPath the path from the entity to the property (will only contain more than one element in case the 48 | * entity is hosted on an embedded entity). 49 | * @param value the value of the property 50 | * @return the property value, converted into the type expected by the query backend 51 | */ 52 | Object convertToBackendType(String entityType, List propertyPath, Object value); 53 | } 54 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/QueryRendererProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import org.antlr.runtime.RecognitionException; 24 | import org.antlr.runtime.TokenStream; 25 | import org.antlr.runtime.tree.CommonTree; 26 | import org.antlr.runtime.tree.CommonTreeNodeStream; 27 | import org.hibernate.hql.ast.render.QueryRenderer; 28 | 29 | /** 30 | * An {@link AstProcessor} which "renders" a given source query into an output query, by invoking 31 | * {@link QueryRendererDelegate} while traversing the given query tree. 32 | *

33 | * Input: Normalized parse tree as created by {@link QueryResolverProcessor}
34 | * Output: Query object 35 | * 36 | * @author Gunnar Morling 37 | */ 38 | public class QueryRendererProcessor implements AstProcessor { 39 | 40 | private final QueryRendererDelegate delegate; 41 | 42 | public QueryRendererProcessor(QueryRendererDelegate delegate) { 43 | this.delegate = delegate; 44 | } 45 | 46 | @Override 47 | public CommonTree process(TokenStream tokens, CommonTree tree) throws RecognitionException { 48 | CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream( tree ); 49 | treeNodeStream.setTokenStream( tokens ); 50 | 51 | return (CommonTree) new QueryRenderer( treeNodeStream, delegate ).statement().getTree(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/QueryResolverDelegate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import org.antlr.runtime.tree.Tree; 24 | import org.hibernate.hql.ast.common.JoinType; 25 | import org.hibernate.hql.ast.origin.hql.resolve.path.PathedPropertyReferenceSource; 26 | import org.hibernate.hql.ast.origin.hql.resolve.path.PropertyPath; 27 | 28 | /** 29 | * Defines hooks for implementing custom logic when walking the parse tree of a JPQL query. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public interface QueryResolverDelegate { 34 | 35 | void registerPersisterSpace(Tree entityName, Tree alias); 36 | 37 | void registerJoinAlias(Tree alias, PropertyPath path); 38 | 39 | boolean isUnqualifiedPropertyReference(); 40 | 41 | PathedPropertyReferenceSource normalizeUnqualifiedPropertyReference(Tree property); 42 | 43 | boolean isPersisterReferenceAlias(); 44 | 45 | PathedPropertyReferenceSource normalizeUnqualifiedRoot(Tree identifier382); 46 | 47 | PathedPropertyReferenceSource normalizeQualifiedRoot(Tree identifier381); 48 | 49 | PathedPropertyReferenceSource normalizePropertyPathIntermediary(PropertyPath path, Tree propertyName); 50 | 51 | PathedPropertyReferenceSource normalizeIntermediateIndexOperation(PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty, 52 | Tree selector); 53 | 54 | void normalizeTerminalIndexOperation(PathedPropertyReferenceSource propertyReferenceSource, Tree collectionProperty, Tree selector); 55 | 56 | PathedPropertyReferenceSource normalizeUnqualifiedPropertyReferenceSource(Tree identifier394); 57 | 58 | PathedPropertyReferenceSource normalizePropertyPathTerminus(PropertyPath path, Tree propertyNameNode); 59 | 60 | void pushFromStrategy(JoinType joinType, Tree assosiationFetchTree, Tree propertyFetchTree, Tree alias); 61 | 62 | void pushSelectStrategy(); 63 | 64 | void popStrategy(); 65 | 66 | /** 67 | * Notifies this delegate when parsing of a property path in the SELECT or WHERE is completed. 68 | * 69 | * @param path the completely parsed property path 70 | */ 71 | void propertyPathCompleted(PropertyPath path); 72 | } 73 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/QueryResolverProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import org.antlr.runtime.RecognitionException; 24 | import org.antlr.runtime.TokenStream; 25 | import org.antlr.runtime.tree.CommonTree; 26 | import org.antlr.runtime.tree.CommonTreeNodeStream; 27 | import org.hibernate.hql.ast.origin.hql.parse.HQLParser; 28 | import org.hibernate.hql.ast.origin.hql.resolve.GeneratedHQLResolver; 29 | 30 | /** 31 | * An {@link AstProcessor} which resolves the elements a given source query into an output query, by invoking 32 | * {@link QueryResolverDelegate} while traversing the given query tree. 33 | *

34 | * Input: Parse tree as created by {@link HQLParser}
35 | * Output: Normalized parse tree 36 | * 37 | * @author Gunnar Morling 38 | */ 39 | public class QueryResolverProcessor implements AstProcessor { 40 | 41 | private final QueryResolverDelegate delegate; 42 | 43 | public QueryResolverProcessor(QueryResolverDelegate delegate) { 44 | this.delegate = delegate; 45 | } 46 | 47 | @Override 48 | public CommonTree process(TokenStream tokens, CommonTree tree) throws RecognitionException { 49 | CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream( tree ); 50 | treeNodeStream.setTokenStream( tokens ); 51 | 52 | return (CommonTree) new GeneratedHQLResolver( treeNodeStream, delegate ).statement().getTree(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/SingleEntityHavingQueryBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi; 22 | 23 | import org.hibernate.hql.ast.origin.hql.resolve.path.AggregationPropertyPath; 24 | import org.hibernate.hql.ast.spi.predicate.ComparisonPredicate.Type; 25 | 26 | import java.util.List; 27 | 28 | /** 29 | * Builder for the creation of HAVING clause filters. 30 | * 31 | * @param the type of query created by this builder 32 | * @author Adrian Nistor 33 | */ 34 | public interface SingleEntityHavingQueryBuilder { 35 | 36 | void setEntityType(String entityType); 37 | 38 | void addComparisonPredicate(AggregationPropertyPath.Type aggregationType, List propertyPath, Type comparisonType, Object value); 39 | 40 | void addRangePredicate(AggregationPropertyPath.Type aggregationType, List propertyPath, Object lower, Object upper); 41 | 42 | void addInPredicate(AggregationPropertyPath.Type aggregationType, List propertyPath, List elements); 43 | 44 | void addLikePredicate(AggregationPropertyPath.Type aggregationType, List propertyPath, String patternValue, Character escapeCharacter); 45 | 46 | void addIsNullPredicate(AggregationPropertyPath.Type aggregationType, List propertyPath); 47 | 48 | void pushAndPredicate(); 49 | 50 | void pushOrPredicate(); 51 | 52 | void pushNotPredicate(); 53 | 54 | void popBooleanPredicate(); 55 | 56 | Q build(); 57 | } 58 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/AbstractPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import org.hibernate.hql.internal.logging.Log; 24 | import org.hibernate.hql.internal.logging.LoggerFactory; 25 | 26 | /** 27 | * Base class for predicate implementations. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public abstract class AbstractPredicate implements Predicate { 32 | 33 | private static final Log log = LoggerFactory.make(); 34 | 35 | private final Type type; 36 | 37 | protected AbstractPredicate(Type type) { 38 | this.type = type; 39 | } 40 | 41 | @Override 42 | public Type getType() { 43 | return type; 44 | } 45 | 46 | @Override 47 | public > T as(Class type) { 48 | if ( type.isAssignableFrom( getClass() ) ) { 49 | return type.cast( this ); 50 | } 51 | 52 | throw log.getUnsupportedPredicateTypeException( this, type.getCanonicalName() ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/ComparisonPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | 24 | /** 25 | * An comparison predicate such as {@code EQUALS} or {@code LESS}. 26 | * 27 | * @author Gunnar Morling 28 | */ 29 | public abstract class ComparisonPredicate extends AbstractPredicate { 30 | 31 | public enum Type { 32 | LESS, 33 | LESS_OR_EQUAL, 34 | EQUALS, 35 | GREATER_OR_EQUAL, 36 | GREATER 37 | } 38 | 39 | protected final String propertyName; 40 | protected final Type type; 41 | protected final Object value; 42 | 43 | public ComparisonPredicate(String propertyName, Type type, Object value) { 44 | super( Predicate.Type.COMPARISON ); 45 | this.propertyName = propertyName; 46 | this.type = type; 47 | this.value = value; 48 | } 49 | 50 | @Override 51 | public Q getQuery() { 52 | switch ( type ) { 53 | case LESS: 54 | return getStrictlyLessQuery(); 55 | case LESS_OR_EQUAL: 56 | return getLessOrEqualsQuery(); 57 | case EQUALS: 58 | return getEqualsQuery(); 59 | case GREATER_OR_EQUAL: 60 | return getGreaterOrEqualsQuery(); 61 | case GREATER: 62 | return getStrictlyGreaterQuery(); 63 | default: 64 | throw new UnsupportedOperationException( "Unsupported comparison type: " + type ); 65 | } 66 | } 67 | 68 | protected abstract Q getStrictlyLessQuery(); 69 | 70 | protected abstract Q getLessOrEqualsQuery(); 71 | 72 | protected abstract Q getEqualsQuery(); 73 | 74 | protected abstract Q getGreaterOrEqualsQuery(); 75 | 76 | protected abstract Q getStrictlyGreaterQuery(); 77 | 78 | @Override 79 | public String toString() { 80 | return "( " + type + " " + propertyName + " " + value + " )"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/ConjunctionPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * A logical {@code AND} predicate. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public abstract class ConjunctionPredicate extends AbstractPredicate implements ParentPredicate { 32 | 33 | protected final List> children = new ArrayList>( 3 ); 34 | 35 | public ConjunctionPredicate() { 36 | super( Type.CONJUNCTION ); 37 | } 38 | 39 | @Override 40 | public void add(Predicate predicate) { 41 | children.add( predicate ); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | StringBuilder sb = new StringBuilder( "( AND " ); 47 | 48 | for ( Predicate child : children ) { 49 | sb.append( child.toString() ).append( " " ); 50 | } 51 | 52 | sb.append( " )" ); 53 | 54 | return sb.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/DisjunctionPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * A logical {@code OR} predicate. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public abstract class DisjunctionPredicate extends AbstractPredicate implements ParentPredicate { 32 | 33 | protected final List> children = new ArrayList>( 3 ); 34 | 35 | public DisjunctionPredicate() { 36 | super( Type.DISJUNCTION ); 37 | } 38 | 39 | @Override 40 | public void add(Predicate predicate) { 41 | children.add( predicate ); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | StringBuilder sb = new StringBuilder( "( OR " ); 47 | 48 | for ( Predicate child : children ) { 49 | sb.append( child.toString() ).append( " " ); 50 | } 51 | 52 | sb.append( " )" ); 53 | 54 | return sb.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/InPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * An {@code IN} predicate. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public abstract class InPredicate extends AbstractPredicate { 31 | 32 | protected final String propertyName; 33 | protected final List values; 34 | 35 | public InPredicate(String propertyName, List values) { 36 | super( Predicate.Type.IN ); 37 | this.propertyName = propertyName; 38 | this.values = values; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "( IN " + propertyName + " " + values + " )"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/IsNullPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * A {@code IS NULL} predicate. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public abstract class IsNullPredicate extends AbstractPredicate { 29 | 30 | protected final String propertyName; 31 | 32 | public IsNullPredicate(String propertyName) { 33 | super( Predicate.Type.IS_NULL ); 34 | this.propertyName = propertyName; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "( " + propertyName + " IS NULL )"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/LikePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * A {@code LIKE} predicate. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public abstract class LikePredicate extends AbstractPredicate { 29 | 30 | protected final String propertyName; 31 | protected final String patternValue; 32 | protected final Character escapeCharacter; 33 | 34 | public LikePredicate(String propertyName, String patternValue, Character escapeCharacter) { 35 | super( Predicate.Type.LIKE ); 36 | this.propertyName = propertyName; 37 | this.patternValue = patternValue; 38 | this.escapeCharacter = escapeCharacter; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "( " + propertyName + " LIKE '" + patternValue + ( escapeCharacter != null ? " ESCAPE " + escapeCharacter : "" ) + "' )"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/NegatablePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * A predicate which can produce a negated query for its content. 25 | * 26 | * @author Gunnar Morling 27 | * 28 | */ 29 | public interface NegatablePredicate extends Predicate { 30 | 31 | Q getNegatedQuery(); 32 | } 33 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/NegationPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import org.hibernate.hql.internal.logging.Log; 24 | import org.hibernate.hql.internal.logging.LoggerFactory; 25 | 26 | /** 27 | * A logical {@code NOT} predicate. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public abstract class NegationPredicate extends AbstractPredicate implements ParentPredicate { 32 | 33 | private static final Log log = LoggerFactory.make(); 34 | 35 | private Predicate child; 36 | 37 | public NegationPredicate() { 38 | super( Type.NEGATION ); 39 | } 40 | 41 | @Override 42 | public void add(Predicate predicate) { 43 | if ( child != null ) { 44 | throw log.getNotMoreThanOnePredicateInNegationAllowedException( predicate ); 45 | } 46 | 47 | this.child = predicate; 48 | } 49 | 50 | public Predicate getChild() { 51 | return child; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "( NOT " + getChild() + " )"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/ParentPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * A predicate which can have one or more sub-predicates. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public interface ParentPredicate extends Predicate { 29 | 30 | /** 31 | * Adds the given predicate to this parent predicate. 32 | * 33 | * @param predicate the predicate to add 34 | */ 35 | void add(Predicate predicate); 36 | } 37 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/Predicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * Represents a predicate as contained in the {@code WHERE} clause of a query. Implementations know how to create an 25 | * equivalent query for themselves and, in case of parent predicates, their children. 26 | * 27 | * @param the type of query objects created by this predicate 28 | * @author Gunnar Morling 29 | */ 30 | public interface Predicate { 31 | 32 | /** 33 | * The type of a predicate. 34 | * 35 | * @author Gunnar Morling 36 | */ 37 | enum Type { 38 | ROOT(true), CONJUNCTION(true), DISJUNCTION(true), NEGATION(true), COMPARISON(false), RANGE(false), IN(false), LIKE(false), IS_NULL(false); 39 | 40 | private final boolean isParent; 41 | 42 | Type(boolean isParent) { 43 | this.isParent = isParent; 44 | } 45 | 46 | /** 47 | * Whether this is a parent predicate type (i.e. predicates of this type can have sub-predicates) or not. 48 | * 49 | * @return {@code true} if this is a parent predicate type, {@code false} otherwise. 50 | */ 51 | public boolean isParent() { 52 | return isParent; 53 | } 54 | } 55 | 56 | /** 57 | * Returns the query represented by this predicate. Contains the all sub-predicates if this predicate is a parent 58 | * predicate. 59 | * 60 | * @return the query represented by this predicate 61 | */ 62 | Q getQuery(); 63 | 64 | /** 65 | * Returns the type of this predicate. 66 | * 67 | * @return the type of this predicate 68 | */ 69 | Type getType(); 70 | 71 | /** 72 | * Narrows the type of this predicate down to the given type. The type should be checked before via 73 | * {@link #getType()}. 74 | * 75 | * @param type the type to narrow down to 76 | * @return this predicate, narrowed down to the given type 77 | */ 78 | > T as(Class type); 79 | } 80 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/PredicateFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import java.util.List; 24 | 25 | import org.hibernate.hql.ast.spi.predicate.ComparisonPredicate.Type; 26 | 27 | /** 28 | * Factory for creating predicate instances. Used by the query builder to create a stack of predicates representing the 29 | * processed query. 30 | * 31 | * @author Gunnar Morling 32 | */ 33 | public interface PredicateFactory { 34 | 35 | RootPredicate getRootPredicate(String entityType); 36 | 37 | ComparisonPredicate getComparisonPredicate(String entityType, Type comparisonType, List propertyPath, Object value); 38 | 39 | InPredicate getInPredicate(String entityType, List propertyPath, List typedElements); 40 | 41 | RangePredicate getRangePredicate(String entityType, List propertyPath, Object lowerValue, Object upperValue); 42 | 43 | NegationPredicate getNegationPredicate(); 44 | 45 | DisjunctionPredicate getDisjunctionPredicate(); 46 | 47 | ConjunctionPredicate getConjunctionPredicate(); 48 | 49 | LikePredicate getLikePredicate(String entityType, List propertyPath, String patternValue, Character escapeCharacter); 50 | 51 | IsNullPredicate getIsNullPredicate(String entityType, List propertyPath); 52 | } 53 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/RangePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | /** 24 | * A {@code BETWEEN} predicate. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public abstract class RangePredicate extends AbstractPredicate { 29 | 30 | protected final String propertyName; 31 | protected final Object lower; 32 | protected final Object upper; 33 | 34 | public RangePredicate(String propertyName, Object lower, Object upper) { 35 | super( Type.RANGE ); 36 | this.propertyName = propertyName; 37 | this.lower = lower; 38 | this.upper = upper; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "( BETWEEN " + propertyName + " " + lower + " " + upper + " )"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/spi/predicate/RootPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.spi.predicate; 22 | 23 | import org.hibernate.hql.internal.logging.Log; 24 | import org.hibernate.hql.internal.logging.LoggerFactory; 25 | 26 | /** 27 | * The root predicate of the {@code WHERE} clause of a query. Allows for a uniform handling of clauses containing only a 28 | * single predicate as well as clauses containing several logically joined predicates. 29 | * 30 | * @author Gunnar Morling 31 | */ 32 | public abstract class RootPredicate extends AbstractPredicate implements ParentPredicate { 33 | 34 | private static final Log log = LoggerFactory.make(); 35 | 36 | protected Predicate child; 37 | 38 | public RootPredicate() { 39 | super( Type.ROOT ); 40 | } 41 | 42 | @Override 43 | public void add(Predicate predicate) { 44 | if ( child != null ) { 45 | throw log.getNotMoreThanOnePredicateInRootOfWhereClauseAllowedException( predicate ); 46 | } 47 | 48 | child = predicate; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return child == null ? "( * )" : child.toString(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/tree/EntityNameTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.tree; 22 | 23 | import java.util.List; 24 | 25 | import org.antlr.runtime.CommonToken; 26 | import org.antlr.runtime.Token; 27 | import org.hibernate.hql.ast.common.HibernateTree; 28 | 29 | public class EntityNameTree extends HibernateTree { 30 | 31 | private List entityNames = null; 32 | private String outputText = null; 33 | 34 | public EntityNameTree(EntityNameTree entityNameTree, String outputText) { 35 | super( entityNameTree.getToken() ); 36 | this.outputText = outputText; 37 | } 38 | 39 | public EntityNameTree(int tokenType, Token token, String tokenText, 40 | List entityNames) { 41 | super( token ); 42 | Token newToken = createToken( token ); 43 | newToken.setType( tokenType ); 44 | newToken.setText( tokenText ); 45 | this.token = newToken; 46 | this.entityNames = entityNames; 47 | } 48 | 49 | private Token createToken(Token fromToken) { 50 | return new CommonToken(fromToken); 51 | } 52 | 53 | public int getEntityCount() { 54 | return entityNames.size(); 55 | } 56 | 57 | public String getEntityName(int index) { 58 | return (String)entityNames.get( index ); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | if (outputText == null) { 64 | outputText = entityNames.get( 0 ).toString(); 65 | } 66 | return outputText; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/ast/tree/PropertyPathTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.ast.tree; 22 | 23 | import org.antlr.runtime.tree.CommonTree; 24 | import org.hibernate.hql.ast.common.HibernateTree; 25 | import org.hibernate.hql.ast.origin.hql.resolve.path.PropertyPath; 26 | 27 | /** 28 | * A {@link HibernateTree} representing one property path. 29 | * 30 | * @author Gunnar Morling 31 | */ 32 | public class PropertyPathTree extends HibernateTree { 33 | 34 | private final PropertyPath propertyPath; 35 | 36 | public PropertyPathTree(int type, CommonTree node, PropertyPath propertyPath) { 37 | super( node ); 38 | this.propertyPath = propertyPath; 39 | } 40 | 41 | public PropertyPath getPropertyPath() { 42 | return propertyPath; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/internal/logging/Log.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.internal.logging; 22 | 23 | import java.util.List; 24 | 25 | import org.antlr.runtime.RecognitionException; 26 | import org.hibernate.hql.ParsingException; 27 | import org.hibernate.hql.ast.spi.predicate.Predicate; 28 | import org.jboss.logging.BasicLogger; 29 | import org.jboss.logging.Cause; 30 | import org.jboss.logging.Message; 31 | import org.jboss.logging.MessageLogger; 32 | 33 | /** 34 | * Logging methods for the query parser component. 35 | * 36 | * @author Gunnar Morling 37 | */ 38 | @MessageLogger(projectCode = "HQL") 39 | public interface Log extends BasicLogger { 40 | 41 | @Message(id = 1, value = "The query %s is not valid.") 42 | ParsingException getInvalidQuerySyntaxException(String query, @Cause RecognitionException cause); 43 | 44 | @Message(id = 2, value = "The query %s is not valid; Parser error messages: %s.") 45 | ParsingException getInvalidQuerySyntaxException(String query, List parserErrorMessages); 46 | 47 | @Message(id = 3, value = "The predicate %s is not of type %s.") 48 | IllegalArgumentException getUnsupportedPredicateTypeException(Object predicate, String targetTypeName); 49 | 50 | @Message(id = 4, value = "The predicate %s can not be added since there may be only one root predicate.") 51 | IllegalStateException getNotMoreThanOnePredicateInRootOfWhereClauseAllowedException(Predicate predicate); 52 | 53 | @Message(id = 5, value = "The predicate %s can not be added since there may be only one sub-predicate in a NOT predicate.") 54 | IllegalStateException getNotMoreThanOnePredicateInNegationAllowedException(Predicate predicate); 55 | 56 | @Message(id = 6, value = "The query %s is not valid; Found unconsumed token(s): %s.") 57 | ParsingException getInvalidQuerySyntaxDueToUnconsumedTokensException(String query, String unconsumedTokens); 58 | 59 | @Message(id = 7, value = "Unknown alias: %s.") 60 | ParsingException getUnknownAliasException(String unknownAlias); 61 | 62 | @Message(id = 8, value = "Cannot have aggregate functions in GROUP BY clause : %s.") 63 | ParsingException getNoAggregationsInGroupByClauseException(String aggregationType); 64 | 65 | @Message(id = 9, value = "Cannot have aggregate functions in WHERE clause : %s.") 66 | ParsingException getNoAggregationsInWhereClauseException(String aggregationType); 67 | 68 | @Message(id = 10, value = "%s aggregation can only be applied to property references.") 69 | ParsingException getAggregationCanOnlyBeAppliedToPropertyReferencesException(String aggregationType); 70 | } 71 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/internal/logging/LoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.internal.logging; 22 | 23 | import org.jboss.logging.Logger; 24 | 25 | /** 26 | * Factory for obtaining {@link Logger} instances. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public final class LoggerFactory { 31 | 32 | private static final CallerProvider callerProvider = new CallerProvider(); 33 | 34 | public static Log make() { 35 | return Logger.getMessageLogger( Log.class, callerProvider.getCallerClass().getCanonicalName() ); 36 | } 37 | 38 | private static class CallerProvider extends SecurityManager { 39 | 40 | public Class getCallerClass() { 41 | return getClassContext()[2]; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /parser/src/main/java/org/hibernate/hql/internal/util/Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.internal.util; 22 | 23 | import java.util.Arrays; 24 | 25 | /** 26 | * Helper class for dealing with strings. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public class Strings { 31 | 32 | private Strings() { 33 | } 34 | 35 | public static String join(String[] strings, String separator) { 36 | return join( Arrays.asList( strings ), separator ); 37 | } 38 | 39 | public static String join(Iterable iterable, String separator) { 40 | StringBuilder sb = new StringBuilder(); 41 | boolean isFirst = true; 42 | 43 | for ( String object : iterable ) { 44 | if ( !isFirst ) { 45 | sb.append( separator ); 46 | } 47 | else { 48 | isFirst = false; 49 | } 50 | 51 | sb.append( object ); 52 | } 53 | 54 | return sb.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/ast/QueryParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.ast; 22 | 23 | import java.util.Collections; 24 | import java.util.Iterator; 25 | 26 | import org.hibernate.hql.ParsingException; 27 | import org.hibernate.hql.QueryParser; 28 | import org.hibernate.hql.ast.spi.AstProcessingChain; 29 | import org.hibernate.hql.ast.spi.AstProcessor; 30 | import org.hibernate.hql.testutil.TestForIssue; 31 | import org.junit.Rule; 32 | import org.junit.Test; 33 | import org.junit.rules.ExpectedException; 34 | 35 | /** 36 | * Unit test for {@link QueryParser}. 37 | * 38 | * @author Gunnar Morling 39 | */ 40 | public class QueryParserTest { 41 | 42 | @Rule 43 | public ExpectedException expectedException = ExpectedException.none(); 44 | 45 | @Test 46 | @TestForIssue(jiraKey = "HQLPARSER-26") 47 | public void shouldRaiseExceptionDueToUnconsumedTokens() { 48 | expectedException.expect( ParsingException.class ); 49 | expectedException.expectMessage( "HQL000006" ); 50 | 51 | QueryParser queryParser = new QueryParser(); 52 | queryParser.parseQuery( "FROM IndexedEntity u WHERE u.name = 'John' blah blah blah", new NoOpProcessingChain() ); 53 | } 54 | 55 | private static class NoOpProcessingChain implements AstProcessingChain { 56 | 57 | @Override 58 | public Iterator iterator() { 59 | return Collections.emptyList().iterator(); 60 | } 61 | 62 | @Override 63 | public Void getResult() { 64 | return null; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/grammars/GeneratedASTTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.grammars; 22 | 23 | import org.hibernate.hql.testing.ForGrammar; 24 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 25 | import org.junit.runner.RunWith; 26 | 27 | 28 | /** 29 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 30 | */ 31 | @RunWith(GrammarTestRunner.class) 32 | @ForGrammar("/org/hibernate/hql/ast/origin/hql/parse/gUnitGeneratedAST.testsuite") 33 | public class GeneratedASTTest { 34 | 35 | } 36 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/grammars/HQLGrammarTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.grammars; 22 | 23 | import org.hibernate.hql.testing.ForGrammar; 24 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 25 | import org.junit.runner.RunWith; 26 | 27 | /** 28 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 29 | */ 30 | @RunWith(GrammarTestRunner.class) 31 | @ForGrammar("/org/hibernate/hql/ast/origin/hql/parse/gUnitHQLGrammar.testsuite") 32 | public class HQLGrammarTest { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/grammars/HQLTokensTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.grammars; 22 | 23 | import org.hibernate.hql.testing.ForGrammar; 24 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 25 | import org.junit.runner.RunWith; 26 | 27 | /** 28 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 29 | */ 30 | @RunWith(GrammarTestRunner.class) 31 | @ForGrammar("/org/hibernate/hql/ast/origin/hql/parse/gUnitHQLTokens.testsuite") 32 | public class HQLTokensTest { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/grammars/SingleParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.grammars; 22 | 23 | import org.antlr.runtime.ANTLRStringStream; 24 | import org.antlr.runtime.CommonTokenStream; 25 | import org.antlr.runtime.RecognitionException; 26 | import org.antlr.runtime.tree.CommonTree; 27 | import org.hibernate.hql.ast.origin.hql.parse.HQLLexer; 28 | import org.hibernate.hql.ast.origin.hql.parse.HQLParser; 29 | import org.hibernate.hql.ast.origin.hql.parse.HQLParser.statement_return; 30 | 31 | /** 32 | * Example of usage for the generated parser; useful to debug a specific syntax too. 33 | * Outputs both the lexer output and the Abstract Syntax Tree. 34 | * 35 | * @author Sanne Grinovero (C) 2012 Red Hat Inc. 36 | */ 37 | public class SingleParserTest { 38 | 39 | public static void main(String[] args) throws RecognitionException { 40 | String testCase = "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id having max(an.bodyWeight)>1.0"; 41 | ANTLRStringStream antlrStream = new ANTLRStringStream( testCase ); 42 | HQLLexer lexer = new HQLLexer( antlrStream ); 43 | CommonTokenStream tokens = new CommonTokenStream( lexer ); 44 | HQLParser parser = new HQLParser( tokens ); 45 | statement_return statement = parser.statement(); 46 | System.out.println( tokens.getTokens() ); 47 | CommonTree tree = (CommonTree) statement.getTree(); 48 | System.out.println( tree.toStringTree() ); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/test/tree/HQLTreeWalkerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.test.tree; 22 | 23 | /** 24 | * TODO 25 | */ 26 | //@RunWith(GUnitTestRunner.class) 27 | //@GUnitTest( "org/hibernate/sql/ast/origin/hql/resolve/gUnitHQLTreeWalker.todo" ) 28 | public class HQLTreeWalkerTest { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/testutil/TestForIssue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2010 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testutil; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * A documentation annotation for notating what JIRA issue is being tested. 30 | * 31 | * @author Steve Ebersole 32 | */ 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target({ ElementType.METHOD, ElementType.TYPE }) 35 | public @interface TestForIssue { 36 | /** 37 | * The key of a JIRA issue tested. 38 | * 39 | * @return The jira issue key 40 | */ 41 | String jiraKey(); 42 | } 43 | -------------------------------------------------------------------------------- /parser/src/test/java/org/hibernate/hql/testutil/TestingParserContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testutil; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | 27 | import org.hibernate.hql.ast.DefaultParsingContext; 28 | import org.hibernate.hql.ast.common.ParserContext; 29 | 30 | public class TestingParserContext extends DefaultParsingContext implements ParserContext { 31 | 32 | //map of 33 | private final HashMap knownEntities = new HashMap(); 34 | 35 | public TestingParserContext(String... validEntities) { 36 | for (String entityName : validEntities) { 37 | ArrayList implementors = new ArrayList(); 38 | implementors.add( entityName ); 39 | knownEntities.put( entityName, implementors ); 40 | } 41 | } 42 | 43 | @Override 44 | public List getEntityImplementors(String entityName) { 45 | return knownEntities.get( entityName ); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /parser/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Hibernate, Relational Persistence for Idiomatic Java 3 | # 4 | # Copyright (c) 2008, Red Hat Inc. or third-party contributors as 5 | # indicated by the @author tags or express copyright attribution 6 | # statements applied by the authors. All third-party contributions are 7 | # distributed under license by Red Hat Inc. 8 | # 9 | # This copyrighted material is made available to anyone wishing to use, modify, 10 | # copy, or redistribute it subject to the terms and conditions of the GNU 11 | # Lesser General Public License, as published by the Free Software Foundation. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | # for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with this distribution; if not, write to: 20 | # Free Software Foundation, Inc. 21 | # 51 Franklin Street, Fifth Floor 22 | # Boston, MA 02110-1301 USA 23 | # 24 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 25 | log4j.appender.stdout.Target=System.out 26 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 27 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n 28 | 29 | log4j.rootLogger=info, stdout 30 | 31 | log4j.logger.org.hibernate.test=info 32 | log4j.logger.org.hibernate.tool.hbm2ddl=debug 33 | log4j.logger.org.hibernate.query.ast.origin.ordering.OrderByFragmentTranslator=trace 34 | log4j.logger.org.hibernate.hql.ast=trace -------------------------------------------------------------------------------- /parser/src/test/resources/org/hibernate/hql/ast/origin/hql/parse/gUnitHQLTokens.testsuite: -------------------------------------------------------------------------------- 1 | gunit HQL; 2 | 3 | @header{ 4 | package org.hibernate.hql.ast.origin.hql.parse; 5 | } 6 | 7 | /* 8 | Some simple tests to verify grammar is compiled and gUnit is properly configured 9 | */ 10 | 11 | GREATER_EQUAL: 12 | ">=" OK 13 | 14 | IDENTIFIER: 15 | "acme" OK 16 | "1cme" FAIL 17 | 18 | FLOATING_POINT_LITERAL: 19 | ".12e+10" OK 20 | ".12e+-10" FAIL 21 | 22 | NULL: 23 | "null" OK 24 | "NULL" OK 25 | "NuLl" OK 26 | 27 | FALSE: 28 | "false" OK 29 | "FALSE" OK 30 | "FaLse" OK 31 | 32 | TRUE: 33 | "true" OK 34 | "TRUE" OK 35 | "TrUe" OK 36 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'testing', 'parser', 'lucene' 2 | rootProject.children.each { it.name = "hibernate-hql-" + it.name } 3 | -------------------------------------------------------------------------------- /testing/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: org.hibernate.build.gradle.api.plugins.antlr.Antlr3Plugin 2 | 3 | ext { 4 | testingGrammarPackage = "org/hibernate/hql/testing/internal" 5 | generatedAntlr4SourcesDir = "$buildDir/generated-src/antlr4/main" 6 | } 7 | 8 | configurations { 9 | antlr4Generator 10 | } 11 | 12 | dependencies { 13 | compile( libraries.junit ) 14 | compile( libraries.antlr3_runtime ) 15 | compile( libraries.antlr4_runtime ) 16 | antlr4Generator( libraries.antlr4_generator ) 17 | } 18 | 19 | sourceSets { 20 | main { 21 | java { 22 | srcDir "${generatedAntlr4SourcesDir}" 23 | } 24 | } 25 | } 26 | 27 | task generateAntlrTypes(type: JavaExec) { 28 | def sourceDir = 'src/main/antlr4-gradle' 29 | 30 | inputs.dir file(sourceDir) 31 | outputs.dir file(generatedAntlr4SourcesDir) 32 | 33 | def grammars = fileTree(sourceDir).include('**/*.g4') 34 | 35 | main = 'org.antlr.v4.Tool' 36 | classpath = configurations.antlr4Generator 37 | args = ["-o", "${generatedAntlr4SourcesDir}/${testingGrammarPackage}", grammars.files].flatten() 38 | } 39 | 40 | compileJava { 41 | dependsOn generateAntlrTypes 42 | } 43 | 44 | // do not run checkstyle on ANTLR generated sources of the calculator sample code 45 | checkstyleTest.exclude '**/com/example/**' 46 | 47 | def pomName() { 48 | return "Hibernate HQL/JP-QL Parser Testing" 49 | } 50 | 51 | def pomDescription() { 52 | return "Infrastructure for HQL/JP-QL parser tests" 53 | } 54 | -------------------------------------------------------------------------------- /testing/src/main/antlr4-gradle/GrammarTest.g4: -------------------------------------------------------------------------------- 1 | /** 2 | * A grammar for describing tests of Antlr grammars. Accepts a sub-set of the 3 | * constructs supported by the GUnit testing tool. 4 | */ 5 | grammar GrammarTest; 6 | 7 | @header { 8 | /* 9 | * Hibernate, Relational Persistence for Idiomatic Java 10 | * 11 | * Copyright (c) 2013, Red Hat, Inc. or third-party contributors as 12 | * indicated by the @author tags or express copyright attribution 13 | * statements applied by the authors. All third-party contributions are 14 | * distributed under license by Red Hat Inc. 15 | * 16 | * This copyrighted material is made available to anyone wishing to use, modify, 17 | * copy, or redistribute it subject to the terms and conditions of the GNU 18 | * Lesser General Public License, as published by the Free Software Foundation. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 22 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 23 | * for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public License 26 | * along with this distribution; if not, write to: 27 | * Free Software Foundation, Inc. 28 | * 51 Franklin Street, Fifth Floor 29 | * Boston, MA 02110-1301 USA 30 | */ 31 | package org.hibernate.hql.testing.internal; 32 | } 33 | 34 | /* Parser rules */ 35 | 36 | grammarTest : 'gunit' ID ';' header (testGroup)+ ; 37 | header : '@header' '{' pakkage '}' ; 38 | pakkage : 'package' PACKAGE_ID ';' ; 39 | testGroup : ID ':' (test)* (testSubGroup)* ; 40 | testSubGroup : TEST_GROUP_NAME (test)+ ; 41 | test : statement outcome ; 42 | statement : (STRING_LITERAL|MULTI_LINE) ; 43 | 44 | outcome 45 | : TEST_RESULT # testResult 46 | | '->' AST # expectedAst 47 | ; 48 | 49 | /* Lexer rules */ 50 | 51 | TEST_RESULT : ('OK'|'FAIL') ; 52 | ID : ('a'..'z'|'A'..'Z'|'_')+ ; 53 | PACKAGE_ID : ID('.'ID)* ; 54 | WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines 55 | 56 | TEST_GROUP_NAME : '[' ~(']')* ']' ; 57 | STRING_LITERAL : '"' ( ESC | ~('\\'|'"') )* '"' ; 58 | AST : '(' ( ESC | ~('\\'|'"') )* ')' ; 59 | MULTI_LINE : '<<' .*? '>>' ; 60 | COMMENT 61 | : ( '//' ~[\r\n]* '\r'? '\n' 62 | | '/*' .*? '*/' 63 | ) -> skip 64 | ; 65 | 66 | /* Fragments */ 67 | 68 | fragment 69 | ESC : '\\' ( 'n' | 'r' | 't' | 'b' | 'f' | '"' | '\'' | '\\' | '>' | 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ) ; 70 | 71 | fragment 72 | HEX_DIGIT : '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ; 73 | -------------------------------------------------------------------------------- /testing/src/main/antlr4/org/hibernate/hql/testing/internal/GrammarTest.g4: -------------------------------------------------------------------------------- 1 | /** 2 | * A grammar for describing tests of Antlr grammars. Accepts a sub-set of the 3 | * constructs supported by the GUnit testing tool. 4 | */ 5 | grammar GrammarTest; 6 | 7 | /* Parser rules */ 8 | 9 | grammarTest : 'gunit' ID ';' header (testGroup)+ ; 10 | header : '@header' '{' pakkage '}' ; 11 | pakkage : 'package' PACKAGE_ID ';' ; 12 | testGroup : ID ':' (test)* (testSubGroup)* ; 13 | testSubGroup : TEST_GROUP_NAME (test)+ ; 14 | test : statement outcome ; 15 | statement : (STRING_LITERAL|MULTI_LINE) ; 16 | 17 | outcome 18 | : TEST_RESULT # testResult 19 | | '->' AST # expectedAst 20 | ; 21 | 22 | /* Lexer rules */ 23 | 24 | TEST_RESULT : ('OK'|'FAIL') ; 25 | ID : ('a'..'z'|'A'..'Z'|'_')+ ; 26 | PACKAGE_ID : ID('.'ID)* ; 27 | WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines 28 | 29 | TEST_GROUP_NAME : '[' ~(']')* ']' ; 30 | STRING_LITERAL : '"' ( ESC | ~('\\'|'"') )* '"' ; 31 | AST : '(' ( ESC | ~('\\'|'"') )* ')' ; 32 | MULTI_LINE : '<<' .*? '>>' ; 33 | COMMENT 34 | : ( '//' ~[\r\n]* '\r'? '\n' 35 | | '/*' .*? '*/' 36 | ) -> skip 37 | ; 38 | 39 | /* Fragments */ 40 | 41 | fragment 42 | ESC : '\\' ( 'n' | 'r' | 't' | 'b' | 'f' | '"' | '\'' | '\\' | '>' | 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT ) ; 43 | 44 | fragment 45 | HEX_DIGIT : '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ; 46 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/ForGrammar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * Specificies a grammar file to be tested. The path must be given relatively to 30 | * the annotated test class. 31 | * 32 | * @author Gunnar Morling 33 | */ 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Target(ElementType.TYPE) 36 | public @interface ForGrammar { 37 | 38 | /** 39 | * The path to the grammar file to be tested. 40 | * 41 | * @return the path to the grammar file to be tested 42 | */ 43 | String value(); 44 | } 45 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/internal/junit/GrammarRuleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.internal.junit; 22 | 23 | import org.junit.runner.Description; 24 | import org.junit.runner.notification.RunNotifier; 25 | 26 | /** 27 | * One ore more tests for the rules of a tested grammar. 28 | *

29 | * Provides a unified view on {@link GrammarRuleStatement} and 30 | * {@link GrammarRuleStatements}. 31 | * 32 | * @author Gunnar Morling 33 | */ 34 | public interface GrammarRuleTest { 35 | 36 | Description getDescription(); 37 | 38 | void run(GrammarRuleStatements parent, RunNotifier notifier); 39 | } 40 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/internal/model/GrammarRuleTestDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.internal.model; 22 | 23 | import org.hibernate.hql.testing.internal.model.ParsingResult.Status; 24 | 25 | /** 26 | * Describes one test for a rule of a given grammar, comprising an expression 27 | * and the expected parsing result or the resulting AST, e.g. {@code "Pi" FAIL}. 28 | * 29 | * @author Gunnar Morling 30 | */ 31 | public class GrammarRuleTestDescriptor { 32 | 33 | private final int lineNumber; 34 | private final String expression; 35 | private final Status expectedParsingResultStatus; 36 | private final String expectedAst; 37 | 38 | public GrammarRuleTestDescriptor( 39 | int lineNumber, 40 | String expression, 41 | ParsingResult.Status expectedParsingResultStatus) { 42 | this.lineNumber = lineNumber; 43 | this.expression = expression; 44 | this.expectedParsingResultStatus = expectedParsingResultStatus; 45 | this.expectedAst = null; 46 | } 47 | 48 | public GrammarRuleTestDescriptor(int lineNumber, String expression, String expectedAst) { 49 | this.lineNumber = lineNumber; 50 | this.expression = expression; 51 | this.expectedParsingResultStatus = Status.OK; 52 | this.expectedAst = expectedAst; 53 | } 54 | 55 | public int getLineNumber() { 56 | return lineNumber; 57 | } 58 | 59 | public String getExpression() { 60 | return expression; 61 | } 62 | 63 | public Status getExpectedParsingResultStatus() { 64 | return expectedParsingResultStatus; 65 | } 66 | 67 | public String getExpectedAst() { 68 | return expectedAst; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "GrammarRuleTestDescriptor [lineNumber=" + lineNumber 74 | + ", expression=" + expression 75 | + ", expectedParsingResultStatus=" 76 | + expectedParsingResultStatus + ", expectedAst=" + expectedAst 77 | + "]"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/internal/model/ParsingResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.internal.model; 22 | 23 | /** 24 | * The result of invoking a parsing method on a lexer or parser. Has a status 25 | * and an description in case the status is {@link Status#FAIL}. May contain the 26 | * resulting AST if this result represents the outcome of a parser rule. 27 | * 28 | * @author Gunnar Morling 29 | */ 30 | public class ParsingResult { 31 | 32 | public enum Status { 33 | OK, FAIL; 34 | } 35 | 36 | private final Status status; 37 | private final String description; 38 | private final String ast; 39 | 40 | private ParsingResult(Status status, String description, String ast) { 41 | this.status = status; 42 | this.description = description; 43 | this.ast = ast; 44 | } 45 | 46 | public static ParsingResult ok() { 47 | return new ParsingResult( Status.OK, null, null ); 48 | } 49 | 50 | public static ParsingResult ok(String ast) { 51 | return new ParsingResult( Status.OK, null, ast ); 52 | } 53 | 54 | public static ParsingResult fail(String description) { 55 | return new ParsingResult( Status.FAIL, description, null ); 56 | } 57 | 58 | public static ParsingResult fail(String description, String ast) { 59 | return new ParsingResult( Status.FAIL, description, ast ); 60 | } 61 | 62 | public Status getStatus() { 63 | return status; 64 | } 65 | 66 | public String getDescription() { 67 | return description; 68 | } 69 | 70 | public String getAst() { 71 | return ast; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/internal/model/RuleType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.internal.model; 22 | 23 | /** 24 | * The type of a grammar rule. 25 | * 26 | * @author Gunnar Morling 27 | */ 28 | public enum RuleType { 29 | LEXER, PARSER; 30 | } 31 | -------------------------------------------------------------------------------- /testing/src/main/java/org/hibernate/hql/testing/junit/GrammarTestRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.junit; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import org.hibernate.hql.testing.ForGrammar; 27 | import org.hibernate.hql.testing.internal.junit.GrammarRuleStatements; 28 | import org.hibernate.hql.testing.internal.model.GrammarRuleTestGroupDescriptor; 29 | import org.hibernate.hql.testing.internal.model.GrammarTestDescriptor; 30 | import org.hibernate.hql.testing.internal.parser.GrammarTestParser; 31 | 32 | import org.junit.runner.Description; 33 | import org.junit.runner.Runner; 34 | import org.junit.runner.notification.RunNotifier; 35 | import org.junit.runners.ParentRunner; 36 | import org.junit.runners.model.InitializationError; 37 | 38 | /** 39 | * A JUnit test runner for executing Antlr grammar tests. The grammar test file 40 | * must be specified using the {@link ForGrammar} annotation. Note that this 41 | * runner supports {@code TestRule}s in the test classes but not the 42 | * {@code @Before} and {@code @After} hooks. 43 | * 44 | * @author Gunnar Morling 45 | */ 46 | public class GrammarTestRunner extends ParentRunner { 47 | 48 | private final List runners; 49 | 50 | public GrammarTestRunner(Class testClass) throws InitializationError { 51 | super( testClass ); 52 | 53 | String grammarFileName = getGrammarFileName( testClass ); 54 | GrammarTestDescriptor grammarTest = new GrammarTestParser().getGrammarTest( testClass, grammarFileName ); 55 | runners = getRunners( testClass, grammarTest ); 56 | } 57 | 58 | private String getGrammarFileName(Class testClass) throws InitializationError { 59 | ForGrammar forGrammar = testClass.getAnnotation( ForGrammar.class ); 60 | if ( forGrammar == null ) { 61 | throw new InitializationError( "A grammar test file must be specified via @" + ForGrammar.class.getSimpleName() + "." ); 62 | } 63 | 64 | return forGrammar.value(); 65 | } 66 | 67 | private List getRunners(Class testClass, GrammarTestDescriptor grammarTest) throws InitializationError { 68 | List runners = new ArrayList(); 69 | 70 | for ( GrammarRuleTestGroupDescriptor group : grammarTest.getTestGroups() ) { 71 | runners.add( new GrammarRuleStatements( testClass, grammarTest, group ) ); 72 | } 73 | 74 | return runners; 75 | } 76 | 77 | @Override 78 | protected List getChildren() { 79 | return runners; 80 | } 81 | 82 | @Override 83 | protected Description describeChild(Runner child) { 84 | return child.getDescription(); 85 | } 86 | 87 | @Override 88 | protected void runChild(Runner child, RunNotifier notifier) { 89 | child.run( notifier ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /testing/src/test/antlr/com/example/calculator/Expr.g: -------------------------------------------------------------------------------- 1 | /** 2 | * Test grammar from antlr.org 3 | */ 4 | grammar Expr; 5 | 6 | @header { 7 | package com.example.calculator; 8 | import java.util.HashMap; 9 | } 10 | 11 | @lexer::header {package com.example.calculator;} 12 | 13 | @members { 14 | /** Map variable name to Integer object holding value */ 15 | HashMap memory = new HashMap(); 16 | } 17 | 18 | prog: stat+ ; 19 | 20 | stat: expr NEWLINE {System.out.println($expr.value);} 21 | | ID '=' expr NEWLINE 22 | {memory.put($ID.text, new Integer($expr.value));} 23 | | NEWLINE 24 | ; 25 | 26 | expr returns [int value] 27 | : e=multExpr {$value = $e.value;} 28 | ( '+' e=multExpr {$value += $e.value;} 29 | | '-' e=multExpr {$value -= $e.value;} 30 | )* 31 | ; 32 | 33 | multExpr returns [int value] 34 | : e=atom {$value = $e.value;} ('*' e=atom {$value *= $e.value;})* 35 | ; 36 | 37 | atom returns [int value] 38 | : INT {$value = Integer.parseInt($INT.text);} 39 | | ID 40 | { 41 | Integer v = (Integer)memory.get($ID.text); 42 | if ( v!=null ) $value = v.intValue(); 43 | else System.err.println("undefined variable "+$ID.text); 44 | } 45 | | '(' e=expr ')' {$value = $e.value;} 46 | ; 47 | 48 | ID : ('a'..'z'|'A'..'Z')+ ; 49 | INT : '0'..'9'+ ; 50 | NEWLINE:'\r'? '\n' ; 51 | WS : (' '|'\t')+ {skip();} ; 52 | -------------------------------------------------------------------------------- /testing/src/test/antlr/com/example/calculator/ExprAst.g: -------------------------------------------------------------------------------- 1 | /** 2 | * Test grammar from antlr.org 3 | */ 4 | grammar ExprAst; 5 | 6 | options { output=AST; } 7 | 8 | @header { 9 | package com.example.calculator; 10 | import java.util.HashMap; 11 | } 12 | 13 | @lexer::header {package com.example.calculator;} 14 | 15 | @members { 16 | /** Map variable name to Integer object holding value */ 17 | HashMap memory = new HashMap(); 18 | } 19 | 20 | prog: stat+ ; 21 | 22 | stat: expr NEWLINE {System.out.println($expr.value);} 23 | | ID '=' expr NEWLINE 24 | {memory.put($ID.text, new Integer($expr.value));} 25 | | NEWLINE 26 | ; 27 | 28 | expr returns [int value] 29 | : e=multExpr {$value = $e.value;} 30 | ( '+'^ e=multExpr {$value += $e.value;} 31 | | '-'^ e=multExpr {$value -= $e.value;} 32 | )* 33 | ; 34 | 35 | multExpr returns [int value] 36 | : e=atom {$value = $e.value;} ('*'^ e=atom {$value *= $e.value;})* 37 | ; 38 | 39 | atom returns [int value] 40 | : INT {$value = Integer.parseInt($INT.text);} 41 | | ID 42 | { 43 | Integer v = (Integer)memory.get($ID.text); 44 | if ( v!=null ) $value = v.intValue(); 45 | else System.err.println("undefined variable "+$ID.text); 46 | } 47 | | '(' e=expr ')' {$value = $e.value;} 48 | ; 49 | 50 | ID : ('a'..'z'|'A'..'Z')+ ; 51 | INT : '0'..'9'+ ; 52 | NEWLINE:'\r'? '\n' ; 53 | WS : (' '|'\t')+ {skip();} ; 54 | -------------------------------------------------------------------------------- /testing/src/test/java/org/hibernate/hql/testing/test/junit/GrammarTestRunnerAstTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.test.junit; 22 | 23 | import static org.fest.assertions.Assertions.assertThat; 24 | 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | import org.hibernate.hql.testing.ForGrammar; 29 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 30 | import org.junit.AfterClass; 31 | import org.junit.Rule; 32 | import org.junit.rules.TestRule; 33 | import org.junit.rules.TestWatcher; 34 | import org.junit.runner.Description; 35 | import org.junit.runner.RunWith; 36 | 37 | /** 38 | * Integration test for {@link GrammarTestRunner}. 39 | * 40 | * @author Gunnar Morling 41 | */ 42 | @RunWith(GrammarTestRunner.class) 43 | @ForGrammar("../exprAst.testsuite") 44 | public class GrammarTestRunnerAstTest { 45 | 46 | private static Set testedMethods = new HashSet(); 47 | 48 | @Rule 49 | public TestRule watcher = new TestWatcher() { 50 | 51 | @Override 52 | protected void finished(Description description) { 53 | testedMethods.add( description.getMethodName() ); 54 | } 55 | }; 56 | 57 | @AfterClass 58 | public static void assertExpressionsUnderTest() { 59 | assertThat( testedMethods ).containsOnly( 60 | "line 8: 2 * 3 + 4 -> (+ (* 2 3) 4)", 61 | "line 11: 2 * 3 -> (* 2 3)" 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /testing/src/test/java/org/hibernate/hql/testing/test/junit/GrammarTestRunnerSubGroupsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.test.junit; 22 | 23 | import static org.fest.assertions.Assertions.assertThat; 24 | 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | import org.hibernate.hql.testing.ForGrammar; 29 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 30 | import org.junit.AfterClass; 31 | import org.junit.Rule; 32 | import org.junit.rules.TestRule; 33 | import org.junit.rules.TestWatcher; 34 | import org.junit.runner.Description; 35 | import org.junit.runner.RunWith; 36 | 37 | /** 38 | * Integration test for {@link GrammarTestRunner}. 39 | * 40 | * @author Gunnar Morling 41 | */ 42 | @RunWith(GrammarTestRunner.class) 43 | @ForGrammar("../exprSubGroups.testsuite") 44 | public class GrammarTestRunnerSubGroupsTest { 45 | 46 | private static Set testedMethods = new HashSet(); 47 | 48 | @Rule 49 | public TestRule watcher = new TestWatcher() { 50 | 51 | @Override 52 | protected void finished(Description description) { 53 | testedMethods.add( description.getMethodName() ); 54 | } 55 | }; 56 | 57 | @AfterClass 58 | public static void assertExpressionsUnderTest() { 59 | assertThat( testedMethods ).containsOnly( 60 | "line 8: a - OK", 61 | "line 9: b - OK", 62 | "line 11: c - OK", 63 | "line 12: d - OK", 64 | "line 14: _ - FAIL", 65 | "line 18: a = 1 + 1 - OK", 66 | "line 20: b = 2 * 2 - OK" 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /testing/src/test/java/org/hibernate/hql/testing/test/junit/GrammarTestRunnerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Hibernate, Relational Persistence for Idiomatic Java 3 | * 4 | * JBoss, Home of Professional Open Source 5 | * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors 6 | * as indicated by the @authors tag. All rights reserved. 7 | * See the copyright.txt in the distribution for a 8 | * full listing of individual contributors. 9 | * 10 | * This copyrighted material is made available to anyone wishing to use, 11 | * modify, copy, or redistribute it subject to the terms and conditions 12 | * of the GNU Lesser General Public License, v. 2.1. 13 | * This program is distributed in the hope that it will be useful, but WITHOUT A 14 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 16 | * You should have received a copy of the GNU Lesser General Public License, 17 | * v.2.1 along with this distribution; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301, USA. 20 | */ 21 | package org.hibernate.hql.testing.test.junit; 22 | 23 | import static org.fest.assertions.Assertions.assertThat; 24 | 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | import org.hibernate.hql.testing.ForGrammar; 29 | import org.hibernate.hql.testing.junit.GrammarTestRunner; 30 | import org.junit.AfterClass; 31 | import org.junit.Rule; 32 | import org.junit.rules.TestRule; 33 | import org.junit.rules.TestWatcher; 34 | import org.junit.runner.Description; 35 | import org.junit.runner.RunWith; 36 | 37 | /** 38 | * Integration test for {@link GrammarTestRunner}. 39 | * 40 | * @author Gunnar Morling 41 | */ 42 | @RunWith(GrammarTestRunner.class) 43 | @ForGrammar("../expr.testsuite") 44 | public class GrammarTestRunnerTest { 45 | 46 | private static Set testedMethods = new HashSet(); 47 | 48 | @Rule 49 | public TestRule watcher = new TestWatcher() { 50 | 51 | @Override 52 | protected void finished(Description description) { 53 | testedMethods.add( description.getMethodName() ); 54 | } 55 | }; 56 | 57 | @AfterClass 58 | public static void assertExpressionsUnderTest() { 59 | assertThat( testedMethods ).containsOnly( 60 | "line 12: a - OK", 61 | "line 13: _ - FAIL", 62 | "line 17: 1 - OK", 63 | "line 18: Pi - FAIL", 64 | "line 21: a = 1 + 1 - OK", 65 | "line 25: 4 * 12 - OK", 66 | "line 26: 4 * - FAIL" 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /testing/src/test/resources/org/hibernate/hql/testing/test/expr.testsuite: -------------------------------------------------------------------------------- 1 | gunit Expr; 2 | 3 | @header{ 4 | package com.example.calculator; 5 | } 6 | 7 | /* 8 | A multi-line comment 9 | */ 10 | 11 | ID: 12 | "a" OK 13 | "_" FAIL 14 | 15 | //A single-line comment 16 | INT: 17 | "1" OK 18 | "Pi" FAIL 19 | 20 | prog: 21 | <> OK 23 | 24 | multExpr: 25 | "4 * 12" OK 26 | "4 * " FAIL 27 | -------------------------------------------------------------------------------- /testing/src/test/resources/org/hibernate/hql/testing/test/exprAst.testsuite: -------------------------------------------------------------------------------- 1 | gunit ExprAst; 2 | 3 | @header{ 4 | package com.example.calculator; 5 | } 6 | 7 | expr: 8 | "2 * 3 + 4" -> (+ (* 2 3) 4) 9 | 10 | multExpr: 11 | "2 * 3" -> (* 2 3) 12 | -------------------------------------------------------------------------------- /testing/src/test/resources/org/hibernate/hql/testing/test/exprSubGroups.testsuite: -------------------------------------------------------------------------------- 1 | gunit Expr; 2 | 3 | @header{ 4 | package com.example.calculator; 5 | } 6 | 7 | ID: 8 | "a" OK 9 | "b" OK 10 | [letters] 11 | "c" OK 12 | "d" OK 13 | [others] 14 | "_" FAIL 15 | 16 | prog: 17 | [multi-line] 18 | <> OK 20 | <> OK 22 | --------------------------------------------------------------------------------