Added full project
This commit is contained in:
parent
0c69e02063
commit
6daddc6d2a
37
build.md
Normal file
37
build.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
# TPQuery Building
|
||||
|
||||
## Requirements
|
||||
|
||||
* java sdk 1.8 or higher.
|
||||
* maven 3 or higher.
|
||||
|
||||
## Create build artifacts
|
||||
|
||||
cd project-root/;
|
||||
mvn -Ptpquery-build clean package;
|
||||
|
||||
## Change pom.xml versions
|
||||
|
||||
cd project-root/;
|
||||
mvn versions:set -DnewVersion=2.3.4-SNAPSHOT
|
||||
|
||||
## Make release build
|
||||
|
||||
cd project-root/;
|
||||
mvn -Ptpquery-build clean package;
|
||||
mvn -B -Dusername=(scm_username) clean install release:clean release:prepare release:perform;
|
||||
|
||||
## Make site
|
||||
|
||||
cd project-root/;
|
||||
mvn -Ptpquery-build-site clean install site:site
|
||||
Optional add -DstagingDirectory=/tmp/tpquery-build-fullsite
|
||||
And then manual upload.
|
||||
|
||||
## Check for dependency-updates
|
||||
|
||||
cd project-root/;
|
||||
mvn versions:display-plugin-updates|grep ">"|uniq;
|
||||
mvn versions:display-dependency-updates|grep ">"|uniq;
|
||||
|
21
license.txt
Normal file
21
license.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
Copyright (c) 2015, Willem Cazander
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
478
pom.xml
Normal file
478
pom.xml
Normal file
|
@ -0,0 +1,478 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>tpquery</name>
|
||||
<description>TemplatedPreparedQuery</description>
|
||||
<inceptionYear>2007</inceptionYear>
|
||||
<organization>
|
||||
<name>ForwardFire.net</name>
|
||||
<url>http://www.forwardfire.net/</url>
|
||||
</organization>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>BSD License</name>
|
||||
<url>license.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>BSD 2-Clause License</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<prerequisites>
|
||||
<maven>3.0.1</maven>
|
||||
</prerequisites>
|
||||
<modules>
|
||||
<module>tpquery-executor-jdbc</module>
|
||||
<module>tpquery-executor-jpa</module>
|
||||
<module>tpquery-store</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.sourceVersion>1.8</project.build.sourceVersion>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.187</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>9.1-901-1.jdbc4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>5.0.0.Beta2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>5.2.0.CR1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jasper-el</artifactId>
|
||||
<version>8.0.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.sonar-plugins.java</groupId>
|
||||
<artifactId>sonar-jacoco-listeners</artifactId>
|
||||
<version>3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.0</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<source>${project.build.sourceVersion}</source>
|
||||
<target>${project.build.sourceVersion}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.4</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.doxia</groupId>
|
||||
<artifactId>doxia-module-markdown</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.10.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<version>3.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.15</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>taglist-maven-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.18.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||
<version>2.18.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.7.4.201502262128</version>
|
||||
<!-- invalid format 1007: <version>0.7.5.201505241946</version> -->
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>tpquery-test-none</id>
|
||||
<properties>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tpquery-test-jacoco</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.sonar.java.jacoco.JUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-prepare-agent</id>
|
||||
<phase>initialize</phase>
|
||||
<inherited>true</inherited>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.sonar-plugins.java</groupId>
|
||||
<artifactId>sonar-jacoco-listeners</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tpquery-test-jacoco-merge</id>
|
||||
<!-- mvn -X -Ptpquery-test-jacoco-merge jacoco:merge but is not working
|
||||
in site :( -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<append>true</append>
|
||||
<destFile>../target/jacoco.exec</destFile>
|
||||
<fileSets>
|
||||
<fileSets>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<includes>
|
||||
<include>*.exec</include>
|
||||
</includes>
|
||||
</fileSets>
|
||||
</fileSets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tpquery-build</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tpquery-build-site</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<dependencies><!-- fix for jdk8 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-shared-jar</artifactId>
|
||||
<version>1.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.bcel</groupId>
|
||||
<artifactId>bcel</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>bcel-findbugs</artifactId>
|
||||
<version>6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-project-markdown</id>
|
||||
<phase>generate-sources</phase>
|
||||
<inherited>false</inherited>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<target>
|
||||
<echo>Copy project markdown to site.</echo>
|
||||
<copy verbose="true" file="versions.md" todir="src/site/markdown" />
|
||||
<copy verbose="true" file="todo.md" todir="src/site/markdown" />
|
||||
<copy verbose="true" file="build.md" todir="src/site/markdown" />
|
||||
</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
|
||||
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
|
||||
</configuration>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<!-- TODO: <report>cim</report> -->
|
||||
<report>dependencies</report>
|
||||
<report>dependency-convergence</report>
|
||||
<report>dependency-info</report>
|
||||
<report>dependency-management</report>
|
||||
<!-- <report>distribution-management</report> -->
|
||||
<!-- <report>help</report> -->
|
||||
<!-- <report>index</report> -->
|
||||
<report>issue-tracking</report>
|
||||
<report>license</report>
|
||||
<!-- TODO: <report>mailing-list</report> -->
|
||||
<!-- <report>modules</report> -->
|
||||
<report>plugin-management</report>
|
||||
<report>plugins</report>
|
||||
<!-- TODO:? <report>project-team</report> -->
|
||||
<report>scm</report>
|
||||
<report>summary</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<quiet>true</quiet>
|
||||
<linksource>true</linksource>
|
||||
<maxmemory>512m</maxmemory>
|
||||
<nohelp>true</nohelp>
|
||||
<detectLinks>true</detectLinks>
|
||||
</configuration>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>aggregate</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-pmd-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<linkXref>true</linkXref>
|
||||
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
|
||||
<minimumTokens>100</minimumTokens>
|
||||
<targetJdk>${project.build.javaVersion}</targetJdk>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<findbugsXmlOutput>true</findbugsXmlOutput>
|
||||
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
|
||||
<xmlOutput>true</xmlOutput>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<enableRulesSummary>true</enableRulesSummary>
|
||||
<configLocation>src/config/checkstyle.xml</configLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>taglist-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<tags>
|
||||
<tag>@todo</tag>
|
||||
<tag>@deprecated</tag>
|
||||
<tag>HELP</tag>
|
||||
<tag>TODO</tag>
|
||||
<tag>FIXME</tag>
|
||||
<tag>LATER</tag>
|
||||
<tag>ERROR</tag>
|
||||
<tag>SOMETHING</tag>
|
||||
</tags>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
</configuration>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>report-only</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<goal>report</goal>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tpquery-sonar</id>
|
||||
<properties>
|
||||
<sonar.jdbc.url>jdbc:postgres://localhost/ff-sonar</sonar.jdbc.url>
|
||||
<sonar.jdbc.username>ff-sonar</sonar.jdbc.username>
|
||||
<sonar.jdbc.password>sonar-ff</sonar.jdbc.password>
|
||||
<sonar.host.url>http://localhost:9000</sonar.host.url>
|
||||
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
|
||||
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
153
src/config/checkstyle.xml
Normal file
153
src/config/checkstyle.xml
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- Copyright (c) 2004-2014, Willem Cazander All rights reserved. Redistribution
|
||||
and use in source and binary forms, with or without modification, are permitted
|
||||
provided that the following conditions are met: * Redistributions of source
|
||||
code must retain the above copyright notice, this list of conditions and
|
||||
the following disclaimer. * Redistributions in binary form must reproduce
|
||||
the above copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
|
||||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
|
||||
<module name="Checker">
|
||||
|
||||
<!-- See http://checkstyle.sourceforge.net/config_javadoc.html -->
|
||||
<!-- Checks is package-info.java is present. -->
|
||||
<module name="JavadocPackage" />
|
||||
|
||||
<!-- Checks whether files end with a new line. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
|
||||
<module name="NewlineAtEndOfFile" />
|
||||
|
||||
<!-- Checks that property files contain the same keys. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
|
||||
<module name="Translation" />
|
||||
|
||||
<module name="FileLength">
|
||||
<property name="max" value="1500" />
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
<!-- cache file -->
|
||||
<property name="cacheFile" value="${checkstyle.cache.file}" />
|
||||
|
||||
<!-- Check line length -->
|
||||
<module name="LineLength">
|
||||
<property name="max" value="200" />
|
||||
<property name="ignorePattern" value="^ *\* *[^ ]+$" />
|
||||
</module>
|
||||
|
||||
<!--check for imports -->
|
||||
<module name="AvoidStarImport" />
|
||||
<module name="IllegalImport" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
|
||||
<!--check for equals and hashcode -->
|
||||
<module name="EqualsHashCode" />
|
||||
|
||||
<!--check for final class -->
|
||||
<module name="FinalClass" />
|
||||
|
||||
<!-- Checks for Javadoc comments. -->
|
||||
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||
<module name="JavadocType">
|
||||
<property name="scope" value="public" />
|
||||
<property name="authorFormat" value="\S" />
|
||||
</module>
|
||||
<module name="JavadocMethod">
|
||||
<property name="scope" value="public" />
|
||||
</module>
|
||||
<module name="JavadocVariable">
|
||||
<property name="scope" value="public" />
|
||||
</module>
|
||||
<module name="JavadocStyle">
|
||||
<property name="scope" value="public" />
|
||||
</module>
|
||||
|
||||
<!-- Checks for Naming Conventions. -->
|
||||
<!-- See http://checkstyle.sf.net/config_naming.html -->
|
||||
<module name="ConstantName" />
|
||||
<module name="LocalFinalVariableName" />
|
||||
<module name="LocalVariableName" />
|
||||
<module name="MemberName" />
|
||||
<module name="MethodName" />
|
||||
<module name="PackageName" />
|
||||
<module name="ParameterName" />
|
||||
<module name="StaticVariableName" />
|
||||
<module name="TypeName" />
|
||||
|
||||
<!-- Checks for Size Violations. -->
|
||||
<!-- See http://checkstyle.sf.net/config_sizes.html -->
|
||||
<module name="MethodLength" />
|
||||
<module name="ParameterNumber" />
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
|
||||
<module name="EmptyForIteratorPad" />
|
||||
|
||||
<!-- <module name="MethodParamPad"/> <module name="NoWhitespaceAfter"/>
|
||||
<module name="NoWhitespaceBefore"/> <module name="TabCharacter"/> <module
|
||||
name="WhitespaceAfter"/> <module name="WhitespaceAround"/> <module name="ParenPad"/> -->
|
||||
<module name="OperatorWrap" />
|
||||
<module name="TypecastParenPad" />
|
||||
|
||||
|
||||
<!-- Modifier Checks -->
|
||||
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
|
||||
<module name="ModifierOrder" />
|
||||
<module name="RedundantModifier" />
|
||||
|
||||
<!-- Checks for blocks. You know, those {}'s -->
|
||||
<!-- See http://checkstyle.sf.net/config_blocks.html -->
|
||||
<module name="AvoidNestedBlocks" />
|
||||
<module name="EmptyBlock" />
|
||||
<module name="LeftCurly" />
|
||||
<module name="NeedBraces" />
|
||||
<module name="RightCurly" />
|
||||
|
||||
<!-- Checks for common coding problems -->
|
||||
<!-- See http://checkstyle.sf.net/config_coding.html -->
|
||||
<module name="AvoidInlineConditionals" />
|
||||
<!-- err <module name="DoubleCheckedLocking" /> -->
|
||||
<module name="EmptyStatement" />
|
||||
<module name="HiddenField">
|
||||
<property name="tokens" value="VARIABLE_DEF" />
|
||||
</module>
|
||||
<module name="IllegalInstantiation" />
|
||||
<module name="InnerAssignment" />
|
||||
<module name="MagicNumber"/>
|
||||
<module name="MissingSwitchDefault" />
|
||||
<module name="RedundantThrows" />
|
||||
<module name="SimplifyBooleanExpression" />
|
||||
<module name="SimplifyBooleanReturn" />
|
||||
<module name="NoFinalizer" />
|
||||
<module name="SuperClone" />
|
||||
<module name="SuperFinalize" />
|
||||
|
||||
<!-- we use proxy
|
||||
<module name="IllegalCatch" />
|
||||
<module name="IllegalThrows" />
|
||||
-->
|
||||
|
||||
<!-- Checks for class design -->
|
||||
<!-- See http://checkstyle.sf.net/config_design.html -->
|
||||
<module name="HideUtilityClassConstructor" />
|
||||
<module name="InterfaceIsType" />
|
||||
<module name="VisibilityModifier" />
|
||||
|
||||
<!-- Miscellaneous other checks. -->
|
||||
<!-- See http://checkstyle.sf.net/config_misc.html -->
|
||||
<module name="ArrayTypeStyle" />
|
||||
<module name="TodoComment" />
|
||||
<module name="UpperEll" />
|
||||
</module>
|
||||
</module>
|
32
src/site/markdown/download.md
Normal file
32
src/site/markdown/download.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!--
|
||||
Copyright (c) 2015, Willem Cazander
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-->
|
||||
|
||||
# TPQuery Download
|
||||
|
||||
|
||||
## Download location
|
||||
|
||||
Grep the latest release from: [link](http://todo.org/releases/tpquery/)
|
||||
|
||||
|
||||
|
38
src/site/markdown/index.md
Normal file
38
src/site/markdown/index.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
<!--
|
||||
Copyright (c) 2015, Willem Cazander
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-->
|
||||
|
||||
# TPQuery Home
|
||||
|
||||
TPQuery is templated prepared statement store.
|
||||
|
||||
## Features
|
||||
|
||||
* Named parameters
|
||||
* Include query parts
|
||||
* Default values
|
||||
* Extra parameter types like LIST and RAW
|
||||
* QuerySets are nestable.
|
||||
* Prepared statement cache if possibe.
|
||||
* Multiple languages supported.
|
||||
* Validation
|
||||
|
27
src/site/resources/css/site.css
Normal file
27
src/site/resources/css/site.css
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
.breadcrumb,#bannerLeft,#bannerRight,#poweredBy {
|
||||
display: none
|
||||
}
|
||||
|
BIN
src/site/resources/img/logo/tpquery-topbar.png
Normal file
BIN
src/site/resources/img/logo/tpquery-topbar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
51
src/site/site.xml
Normal file
51
src/site/site.xml
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2015, Willem Cazander All rights reserved. Redistribution
|
||||
and use in source and binary forms, with or without modification, are permitted
|
||||
provided that the following conditions are met: * Redistributions of source
|
||||
code must retain the above copyright notice, this list of conditions and
|
||||
the following disclaimer. * Redistributions in binary form must reproduce
|
||||
the above copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the distribution.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
|
||||
<project>
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</skin>
|
||||
<custom>
|
||||
<fluidoSkin>
|
||||
<topBarEnabled>true</topBarEnabled>
|
||||
<topBarContainerStyle>width: 90%;</topBarContainerStyle>
|
||||
<topBarIcon>
|
||||
<name>TPQuery</name>
|
||||
<alt>${project.name}</alt>
|
||||
<src>/img/logo/tpquery-topbar.png</src>
|
||||
<href>/index.html</href>
|
||||
</topBarIcon>
|
||||
<sideBarEnabled>false</sideBarEnabled>
|
||||
<googleSearch />
|
||||
<sourceLineNumbersEnabled>false</sourceLineNumbersEnabled>
|
||||
<skipGenerationDate>false</skipGenerationDate>
|
||||
</fluidoSkin>
|
||||
</custom>
|
||||
<body>
|
||||
<menu name="TPQuery">
|
||||
<item name="Home" href="index.html" />
|
||||
<item name="Download" href="download.html" />
|
||||
<item name="Versions" href="versions.html" />
|
||||
<item name="Building" href="build.html" />
|
||||
<item name="Todo" href="todo.html" />
|
||||
</menu>
|
||||
<menu ref="reports" />
|
||||
</body>
|
||||
</project>
|
19
todo.md
Normal file
19
todo.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# TPQuery todo
|
||||
|
||||
## Current ERRATA
|
||||
|
||||
* None ?
|
||||
|
||||
## Todo list
|
||||
|
||||
* finish jdoc
|
||||
* finish site
|
||||
* rename prepared writers
|
||||
* Add jmx stats bean
|
||||
|
||||
## Ideas
|
||||
|
||||
* Create eclipse plugin
|
||||
* add mm auto column.
|
||||
* add hibernate config plugin
|
||||
|
19
tpquery-executor-jdbc/pom.xml
Normal file
19
tpquery-executor-jdbc/pom.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>tpquery-executor-jdbc</artifactId>
|
||||
<name>tpquery-executor-jdbc</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>tpquery-store</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor.jdbc;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SQLExceptionRuntime extends RuntimeException {
|
||||
|
||||
public SQLExceptionRuntime(SQLException parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
public static SQLExceptionRuntime wrap(SQLException e) {
|
||||
return new SQLExceptionRuntime(e);
|
||||
}
|
||||
|
||||
public static SQLExceptionRuntime wrapAndClose(AutoCloseable closeable,SQLException e) {
|
||||
return close(closeable,wrap(e));
|
||||
}
|
||||
|
||||
protected static SQLExceptionRuntime close(AutoCloseable closeable,SQLExceptionRuntime parent) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (Exception ee) {
|
||||
parent.addSuppressed(ee);
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
public class TPQExecutorJdbc extends AbstractTPQExecutor<Connection,PreparedStatement> {
|
||||
|
||||
public TPQExecutorJdbc(TPQExecutorContext context) {
|
||||
super(context);
|
||||
registrateStatementCreator(TPQFactory.StatementLanguage.SQL, (connection,statementText) -> {
|
||||
try {
|
||||
return connection.prepareStatement(statementText);
|
||||
} catch (SQLException e) {
|
||||
throw SQLExceptionRuntime.wrap(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PreparedStatement execute(Connection connection,String queryName) {
|
||||
return execute(connection, queryName, null);
|
||||
}
|
||||
|
||||
public PreparedStatement execute(Connection connection,String queryName,Map<String,Object> parameters) {
|
||||
return execute(createPreparedStatement(connection, queryName, parameters));
|
||||
}
|
||||
|
||||
protected PreparedStatement execute(PreparedStatement statement) {
|
||||
Objects.requireNonNull(statement,"Can't execute with null statement.");
|
||||
try {
|
||||
statement.execute();
|
||||
return statement;
|
||||
} catch (SQLException e) {
|
||||
throw SQLExceptionRuntime.wrapAndClose(statement, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int executeUpdate(PreparedStatement statement) {
|
||||
Objects.requireNonNull(statement,"Can't execute update with null statement.");
|
||||
try {
|
||||
int result = statement.executeUpdate();
|
||||
statement.close();
|
||||
return result;
|
||||
} catch (SQLException e) {
|
||||
throw SQLExceptionRuntime.wrapAndClose(statement, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareParameterValue(PreparedStatement statement,int index, Object value) {
|
||||
try {
|
||||
statement.setObject(index,value);
|
||||
} catch (SQLException e) {
|
||||
throw SQLExceptionRuntime.wrap(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTimeout(PreparedStatement statement, Integer timeout) {
|
||||
try {
|
||||
statement.setQueryTimeout(timeout);
|
||||
} catch (SQLException e) {
|
||||
throw SQLExceptionRuntime.wrap(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Jdbc executor.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor.jdbc;
|
|
@ -0,0 +1,240 @@
|
|||
package net.forwardfire.tpquery.store.executor.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.jdbc.SQLExceptionRuntime;
|
||||
import net.forwardfire.tpquery.store.executor.jdbc.TPQExecutorJdbc;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
||||
public class TPQExecutorJdbcTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setupLogging() {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
lc.reset(); // disable logging
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testAutoClose() throws Exception {
|
||||
SQLExceptionRuntime e = new SQLExceptionRuntime(new SQLException("junit"));
|
||||
SQLExceptionRuntime.close(new AutoCloseable() {
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
throw new IllegalArgumentException("test");
|
||||
}
|
||||
}, e);
|
||||
assertTrue(e.getSuppressed().length>0);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testExecuteUpdateNull() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("createTable").appendText("CREATE TABLE test_table (id serial,data int)").build()
|
||||
.createQuery("insertData").appendText("INSERT INTO test_table (data) VALUES (0)").build()
|
||||
.createQuery("queryFail")
|
||||
.parseStatement("update test_table tt set tt.data=$$data$$")
|
||||
.createQueryParameter("data", Integer.class.getName())
|
||||
.setNullable(true)
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("selectData").appendText("SELECT * FROM test_table").build()
|
||||
.createQuery("selectDataNull")
|
||||
.parseStatement("SELECT * FROM test_table tt WHERE (tt.data=$$data$$ OR ($$data$$ IS NULL AND tt.data IS NULL))")
|
||||
.createQueryParameter("data", Integer.class.getName())
|
||||
.setNullable(true)
|
||||
.build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.executeUpdate(connection, "junit.createTable");
|
||||
exe.executeUpdate(connection, "junit.insertData");
|
||||
|
||||
printData(exe.execute(connection, "junit.selectData"));
|
||||
|
||||
exe.executeUpdate(connection, "junit.queryFail");
|
||||
|
||||
printData(exe.execute(connection, "junit.selectData"));
|
||||
|
||||
Map<String,Object> testData = new HashMap<>();
|
||||
testData.put("data",null);
|
||||
|
||||
printData(exe.execute(connection, "junit.selectDataNull",testData));
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SQLExceptionRuntime.class)
|
||||
public void testExecuteUpdateFail() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("createTable").appendText("CREATE TABLE test_table (id serial,data int)").build()
|
||||
.createQuery("insertData").appendText("INSERT INTO test_table (data) VALUES (0)").build()
|
||||
.createQuery("queryFail").appendText("update test_table tt set tt.data=10/(SELECT sum(t1.data) FROM test_table t1)").build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.executeUpdate(connection, "junit.createTable");
|
||||
exe.executeUpdate(connection, "junit.insertData");
|
||||
exe.executeUpdate(connection, "junit.queryFail"); // runtime data failure, as prepared will go correctly
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SQLExceptionRuntime.class)
|
||||
public void testExecuteSelectFail() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("createTable").appendText("CREATE TABLE test_table (id serial,data int)").build()
|
||||
.createQuery("insertData").appendText("INSERT INTO test_table (data) VALUES (0)").build()
|
||||
.createQuery("queryFail").appendText("select tt.* from test_table tt where tt.data=10/(SELECT sum(t1.data) FROM test_table t1)").build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.executeUpdate(connection, "junit.createTable");
|
||||
exe.executeUpdate(connection, "junit.insertData");
|
||||
exe.execute(connection, "junit.queryFail"); // runtime data failure, as prepared will go correctly
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SQLExceptionRuntime.class)
|
||||
public void testExecuteSelectFailPrepare() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:testcaseFail")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("sql-fail").appendText("select * from article").build()
|
||||
.build()
|
||||
.build();
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.execute(connection, "junit.sql-fail");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SQLExceptionRuntime.class)
|
||||
public void testTimeoutFail() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:test")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("createTable").appendText("CREATE TABLE test_table (id serial,data int)").build()
|
||||
.createQuery("test").appendText("select * from test_table").build()
|
||||
.build()
|
||||
.build();
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.executeUpdate(connection, "junit.createTable");
|
||||
PreparedStatement ps = exe.createPreparedStatement(connection, "junit.test", null);
|
||||
ps.close();
|
||||
exe.prepareTimeout(ps, 123);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=SQLExceptionRuntime.class)
|
||||
public void testParameterFail() throws Exception {
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:test")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("createTable").appendText("CREATE TABLE test_table (id serial,data int)").build()
|
||||
.createQuery("test").appendText("select * from test_table").build()
|
||||
.build()
|
||||
.build();
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(store.getQueryExecutorContext());
|
||||
exe.executeUpdate(connection, "junit.createTable");
|
||||
PreparedStatement ps = exe.createPreparedStatement(connection, "junit.test", null);
|
||||
exe.prepareParameterValue(ps, 1, 123);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteBig() throws Exception {
|
||||
int sizeFactor = 1;
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test;")) {
|
||||
TPQManager queryStore = TPQFactory.createManagerBuilder().readQuerySet("net/forwardfire/tpquery/executor/jdbc/test-big.xml").build();
|
||||
TPQExecutorJdbc exe = new TPQExecutorJdbc(queryStore.getQueryExecutorContext());
|
||||
//Thread.sleep(1000*5);
|
||||
|
||||
System.out.println("Creating big table...");
|
||||
int insertCount = exe.executeUpdate(connection, "TestBig.createTable");
|
||||
assertEquals(0,insertCount);
|
||||
|
||||
System.out.println("Creating big test table data...");
|
||||
Map<String,Object> testData = new HashMap<String,Object>();
|
||||
for (int i=0;i<50*sizeFactor;i++) {
|
||||
testData.put("id", i);
|
||||
for (int c=0;c<100;c++) {
|
||||
String colName = String.format("col%03d", c);
|
||||
testData.put(colName, ""+i+c);
|
||||
}
|
||||
insertCount = exe.executeUpdate(connection, "TestBig.insert",testData);
|
||||
assertEquals(1,insertCount);
|
||||
}
|
||||
|
||||
System.out.println("Selecting big test table data...");
|
||||
int rows = 0;
|
||||
testData = new HashMap<String,Object>();
|
||||
for (int i=1;i<30*sizeFactor;i++) {
|
||||
testData.put("col001", ""+1*i);
|
||||
testData.put("col002", ""+2+i);
|
||||
testData.put("col003", ""+3/i);
|
||||
testData.put("col004", ""+4+i);
|
||||
testData.put("col005", ""+5/i);
|
||||
testData.put("col006", ""+6*i);
|
||||
testData.put("col007", ""+7+i);
|
||||
testData.put("col008", ""+8/i);
|
||||
testData.put("col009", ""+9*i);
|
||||
testData.put("col000", ""+0+i);
|
||||
PreparedStatement ps = exe.execute(connection, "TestBig.getBy10Cols", testData);
|
||||
//ps.getParameterMetaData();
|
||||
ResultSet rs = ps.getResultSet();
|
||||
while (rs.next()) {
|
||||
rows++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Done...rows: "+rows);
|
||||
}
|
||||
}
|
||||
|
||||
private void printData(PreparedStatement ps) throws SQLException {
|
||||
ResultSet rs = ps.getResultSet();
|
||||
ps.getParameterMetaData();
|
||||
|
||||
while (rs.next()) {
|
||||
System.out.println("data record:");
|
||||
for (int i=1;i<=ps.getMetaData().getColumnCount();i++) {
|
||||
String name = ps.getMetaData().getColumnName(i);
|
||||
Object value = rs.getObject(i);
|
||||
System.out.println("column: "+name+" value: "+value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<query-set name="TestBig" language="SQL">
|
||||
<query name="createTable" timeout="2000">
|
||||
<statement>CREATE TABLE test_big (
|
||||
id serial,
|
||||
col000 text,col001 text,col002 text,col003 text,col004 text,col005 text,col006 text,col007 text,col008 text,col009 text,
|
||||
col010 text,col011 text,col012 text,col013 text,col014 text,col015 text,col016 text,col017 text,col018 text,col019 text,
|
||||
col020 text,col021 text,col022 text,col023 text,col024 text,col025 text,col026 text,col027 text,col028 text,col029 text,
|
||||
col030 text,col031 text,col032 text,col033 text,col034 text,col035 text,col036 text,col037 text,col038 text,col039 text,
|
||||
col040 text,col041 text,col042 text,col043 text,col044 text,col045 text,col046 text,col047 text,col048 text,col049 text,
|
||||
col050 text,col051 text,col052 text,col053 text,col054 text,col055 text,col056 text,col057 text,col058 text,col059 text,
|
||||
col060 text,col061 text,col062 text,col063 text,col064 text,col065 text,col066 text,col067 text,col068 text,col069 text,
|
||||
col070 text,col071 text,col072 text,col073 text,col074 text,col075 text,col076 text,col077 text,col078 text,col079 text,
|
||||
col080 text,col081 text,col082 text,col083 text,col084 text,col085 text,col086 text,col087 text,col088 text,col089 text,
|
||||
col090 text,col091 text,col092 text,col093 text,col094 text,col095 text,col096 text,col097 text,col098 text,col099 text
|
||||
)
|
||||
</statement>
|
||||
</query>
|
||||
<query name="insertPara">
|
||||
<description>Tests insert parameters as raw</description>
|
||||
<statement>INSERT INTO test_big ($$col_names$$) VALUES ($$col_values$$)</statement>
|
||||
<parameter name="col_names" type="RAW" valueType="text"/>
|
||||
<parameter name="col_values" type="LIST" valueType="text"/>
|
||||
</query>
|
||||
<query name="insert">
|
||||
<statement>INSERT INTO test_big (
|
||||
id,
|
||||
$$inc:TestBig.inc.select.col00X$$ ,
|
||||
$$inc:TestBig.inc.select.col01X$$ ,
|
||||
$$inc:TestBig.inc.select.col02X$$ ,
|
||||
$$inc:TestBig.inc.select.col03X$$ ,
|
||||
$$inc:TestBig.inc.select.col04X$$ ,
|
||||
$$inc:TestBig.inc.select.col05X$$ ,
|
||||
$$inc:TestBig.inc.select.col06X$$ ,
|
||||
$$inc:TestBig.inc.select.col07X$$ ,
|
||||
$$inc:TestBig.inc.select.col08X$$ ,
|
||||
$$inc:TestBig.inc.select.col09X$$
|
||||
) VALUES (
|
||||
$$id$$ ,
|
||||
$$col000$$ ,$$col001$$ ,$$col002$$ ,$$col003$$ ,$$col004$$ ,$$col005$$ ,$$col006$$ ,$$col007$$ ,$$col008$$ ,$$col009$$ ,
|
||||
$$col010$$ ,$$col011$$ ,$$col012$$ ,$$col013$$ ,$$col014$$ ,$$col015$$ ,$$col016$$ ,$$col017$$ ,$$col018$$ ,$$col019$$ ,
|
||||
$$col020$$ ,$$col021$$ ,$$col022$$ ,$$col023$$ ,$$col024$$ ,$$col025$$ ,$$col026$$ ,$$col027$$ ,$$col028$$ ,$$col029$$ ,
|
||||
$$col030$$ ,$$col031$$ ,$$col032$$ ,$$col033$$ ,$$col034$$ ,$$col035$$ ,$$col036$$ ,$$col037$$ ,$$col038$$ ,$$col039$$ ,
|
||||
$$col040$$ ,$$col041$$ ,$$col042$$ ,$$col043$$ ,$$col044$$ ,$$col045$$ ,$$col046$$ ,$$col047$$ ,$$col048$$ ,$$col049$$ ,
|
||||
$$col050$$ ,$$col051$$ ,$$col052$$ ,$$col053$$ ,$$col054$$ ,$$col055$$ ,$$col056$$ ,$$col057$$ ,$$col058$$ ,$$col059$$ ,
|
||||
$$col060$$ ,$$col061$$ ,$$col062$$ ,$$col063$$ ,$$col064$$ ,$$col065$$ ,$$col066$$ ,$$col067$$ ,$$col068$$ ,$$col069$$ ,
|
||||
$$col070$$ ,$$col071$$ ,$$col072$$ ,$$col073$$ ,$$col074$$ ,$$col075$$ ,$$col076$$ ,$$col077$$ ,$$col078$$ ,$$col079$$ ,
|
||||
$$col080$$ ,$$col081$$ ,$$col082$$ ,$$col083$$ ,$$col084$$ ,$$col085$$ ,$$col086$$ ,$$col087$$ ,$$col088$$ ,$$col089$$ ,
|
||||
$$col090$$ ,$$col091$$ ,$$col092$$ ,$$col093$$ ,$$col094$$ ,$$col095$$ ,$$col096$$ ,$$col097$$ ,$$col098$$ ,$$col099$$
|
||||
)
|
||||
</statement>
|
||||
<parameter name="id" valueType="int" />
|
||||
<parameter name="col000" valueType="java.lang.String" />
|
||||
<parameter name="col001" valueType="java.lang.String" />
|
||||
<parameter name="col002" valueType="java.lang.String" />
|
||||
<parameter name="col003" valueType="java.lang.String" />
|
||||
<parameter name="col004" valueType="java.lang.String" />
|
||||
<parameter name="col005" valueType="java.lang.String" />
|
||||
<parameter name="col006" valueType="java.lang.String" />
|
||||
<parameter name="col007" valueType="java.lang.String" />
|
||||
<parameter name="col008" valueType="java.lang.String" />
|
||||
<parameter name="col009" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col010" valueType="java.lang.String" />
|
||||
<parameter name="col011" valueType="java.lang.String" />
|
||||
<parameter name="col012" valueType="java.lang.String" />
|
||||
<parameter name="col013" valueType="java.lang.String" />
|
||||
<parameter name="col014" valueType="java.lang.String" />
|
||||
<parameter name="col015" valueType="java.lang.String" />
|
||||
<parameter name="col016" valueType="java.lang.String" />
|
||||
<parameter name="col017" valueType="java.lang.String" />
|
||||
<parameter name="col018" valueType="java.lang.String" />
|
||||
<parameter name="col019" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col020" valueType="java.lang.String" />
|
||||
<parameter name="col021" valueType="java.lang.String" />
|
||||
<parameter name="col022" valueType="java.lang.String" />
|
||||
<parameter name="col023" valueType="java.lang.String" />
|
||||
<parameter name="col024" valueType="java.lang.String" />
|
||||
<parameter name="col025" valueType="java.lang.String" />
|
||||
<parameter name="col026" valueType="java.lang.String" />
|
||||
<parameter name="col027" valueType="java.lang.String" />
|
||||
<parameter name="col028" valueType="java.lang.String" />
|
||||
<parameter name="col029" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col030" valueType="java.lang.String" />
|
||||
<parameter name="col031" valueType="java.lang.String" />
|
||||
<parameter name="col032" valueType="java.lang.String" />
|
||||
<parameter name="col033" valueType="java.lang.String" />
|
||||
<parameter name="col034" valueType="java.lang.String" />
|
||||
<parameter name="col035" valueType="java.lang.String" />
|
||||
<parameter name="col036" valueType="java.lang.String" />
|
||||
<parameter name="col037" valueType="java.lang.String" />
|
||||
<parameter name="col038" valueType="java.lang.String" />
|
||||
<parameter name="col039" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col040" valueType="java.lang.String" />
|
||||
<parameter name="col041" valueType="java.lang.String" />
|
||||
<parameter name="col042" valueType="java.lang.String" />
|
||||
<parameter name="col043" valueType="java.lang.String" />
|
||||
<parameter name="col044" valueType="java.lang.String" />
|
||||
<parameter name="col045" valueType="java.lang.String" />
|
||||
<parameter name="col046" valueType="java.lang.String" />
|
||||
<parameter name="col047" valueType="java.lang.String" />
|
||||
<parameter name="col048" valueType="java.lang.String" />
|
||||
<parameter name="col049" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col050" valueType="java.lang.String" />
|
||||
<parameter name="col051" valueType="java.lang.String" />
|
||||
<parameter name="col052" valueType="java.lang.String" />
|
||||
<parameter name="col053" valueType="java.lang.String" />
|
||||
<parameter name="col054" valueType="java.lang.String" />
|
||||
<parameter name="col055" valueType="java.lang.String" />
|
||||
<parameter name="col056" valueType="java.lang.String" />
|
||||
<parameter name="col057" valueType="java.lang.String" />
|
||||
<parameter name="col058" valueType="java.lang.String" />
|
||||
<parameter name="col059" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col060" valueType="java.lang.String" />
|
||||
<parameter name="col061" valueType="java.lang.String" />
|
||||
<parameter name="col062" valueType="java.lang.String" />
|
||||
<parameter name="col063" valueType="java.lang.String" />
|
||||
<parameter name="col064" valueType="java.lang.String" />
|
||||
<parameter name="col065" valueType="java.lang.String" />
|
||||
<parameter name="col066" valueType="java.lang.String" />
|
||||
<parameter name="col067" valueType="java.lang.String" />
|
||||
<parameter name="col068" valueType="java.lang.String" />
|
||||
<parameter name="col069" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col070" valueType="java.lang.String" />
|
||||
<parameter name="col071" valueType="java.lang.String" />
|
||||
<parameter name="col072" valueType="java.lang.String" />
|
||||
<parameter name="col073" valueType="java.lang.String" />
|
||||
<parameter name="col074" valueType="java.lang.String" />
|
||||
<parameter name="col075" valueType="java.lang.String" />
|
||||
<parameter name="col076" valueType="java.lang.String" />
|
||||
<parameter name="col077" valueType="java.lang.String" />
|
||||
<parameter name="col078" valueType="java.lang.String" />
|
||||
<parameter name="col079" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col080" valueType="java.lang.String" />
|
||||
<parameter name="col081" valueType="java.lang.String" />
|
||||
<parameter name="col082" valueType="java.lang.String" />
|
||||
<parameter name="col083" valueType="java.lang.String" />
|
||||
<parameter name="col084" valueType="java.lang.String" />
|
||||
<parameter name="col085" valueType="java.lang.String" />
|
||||
<parameter name="col086" valueType="java.lang.String" />
|
||||
<parameter name="col087" valueType="java.lang.String" />
|
||||
<parameter name="col088" valueType="java.lang.String" />
|
||||
<parameter name="col089" valueType="java.lang.String" />
|
||||
|
||||
<parameter name="col090" valueType="java.lang.String" />
|
||||
<parameter name="col091" valueType="java.lang.String" />
|
||||
<parameter name="col092" valueType="java.lang.String" />
|
||||
<parameter name="col093" valueType="java.lang.String" />
|
||||
<parameter name="col094" valueType="java.lang.String" />
|
||||
<parameter name="col095" valueType="java.lang.String" />
|
||||
<parameter name="col096" valueType="java.lang.String" />
|
||||
<parameter name="col097" valueType="java.lang.String" />
|
||||
<parameter name="col098" valueType="java.lang.String" />
|
||||
<parameter name="col099" valueType="java.lang.String" />
|
||||
</query>
|
||||
|
||||
<query name="getAll">
|
||||
<statement>
|
||||
$$inc:TestBig.inc.selectWhere$$
|
||||
$$inc:TestBig.inc.orderBy$$
|
||||
</statement>
|
||||
</query>
|
||||
<query name="getBy10Cols">
|
||||
<statement>
|
||||
$$inc:TestBig.inc.selectWhere$$
|
||||
$$inc:TestBig.inc.where.col000$$
|
||||
$$inc:TestBig.inc.where.col001$$
|
||||
$$inc:TestBig.inc.where.col002$$
|
||||
$$inc:TestBig.inc.where.col003$$
|
||||
$$inc:TestBig.inc.where.col004$$
|
||||
$$inc:TestBig.inc.where.col005$$
|
||||
$$inc:TestBig.inc.where.col006$$
|
||||
$$inc:TestBig.inc.where.col007$$
|
||||
$$inc:TestBig.inc.where.col008$$
|
||||
$$inc:TestBig.inc.where.col009$$
|
||||
$$inc:TestBig.inc.orderBy$$
|
||||
</statement>
|
||||
</query>
|
||||
<query-set name="inc" template="true">
|
||||
<query-set name="select">
|
||||
<query name="col00X">
|
||||
<statement>col000,col001,col002,col003,col004,col005,col006,col007,col008,col009</statement>
|
||||
</query>
|
||||
<query name="col01X">
|
||||
<statement>col010,col011,col012,col013,col014,col015,col016,col017,col018,col019</statement>
|
||||
</query>
|
||||
<query name="col02X">
|
||||
<statement>col020,col021,col022,col023,col024,col025,col026,col027,col028,col029</statement>
|
||||
</query>
|
||||
<query name="col03X">
|
||||
<statement>col030,col031,col032,col033,col034,col035,col036,col037,col038,col039</statement>
|
||||
</query>
|
||||
<query name="col04X">
|
||||
<statement>col040,col041,col042,col043,col044,col045,col046,col047,col048,col049</statement>
|
||||
</query>
|
||||
<query name="col05X">
|
||||
<statement>col050,col051,col052,col053,col054,col055,col056,col057,col058,col059</statement>
|
||||
</query>
|
||||
<query name="col06X">
|
||||
<statement>col060,col061,col062,col063,col064,col065,col066,col067,col068,col069</statement>
|
||||
</query>
|
||||
<query name="col07X">
|
||||
<statement>col070,col071,col072,col073,col074,col075,col076,col077,col078,col079</statement>
|
||||
</query>
|
||||
<query name="col08X">
|
||||
<statement>col080,col081,col082,col083,col084,col085,col086,col087,col088,col089</statement>
|
||||
</query>
|
||||
<query name="col09X">
|
||||
<statement>col090,col091,col092,col093,col094,col095,col096,col097,col098,col099</statement>
|
||||
</query>
|
||||
</query-set>
|
||||
<query name="selectWhere">
|
||||
<statement>
|
||||
SELECT
|
||||
id,
|
||||
$$inc:TestBig.inc.select.col00X$$ ,
|
||||
$$inc:TestBig.inc.select.col01X$$ ,
|
||||
$$inc:TestBig.inc.select.col02X$$ ,
|
||||
$$inc:TestBig.inc.select.col03X$$ ,
|
||||
$$inc:TestBig.inc.select.col04X$$ ,
|
||||
$$inc:TestBig.inc.select.col05X$$ ,
|
||||
$$inc:TestBig.inc.select.col06X$$ ,
|
||||
$$inc:TestBig.inc.select.col07X$$ ,
|
||||
$$inc:TestBig.inc.select.col08X$$ ,
|
||||
$$inc:TestBig.inc.select.col09X$$
|
||||
FROM
|
||||
test_big
|
||||
WHERE
|
||||
true=true
|
||||
</statement>
|
||||
</query>
|
||||
<query-set name="where">
|
||||
<query name="col000">
|
||||
<statement> AND col000 = $$col000$$ </statement>
|
||||
<parameter name="col000" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col001">
|
||||
<statement> AND col001 = $$col001$$ </statement>
|
||||
<parameter name="col001" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col002">
|
||||
<statement> AND col002 = $$col002$$ </statement>
|
||||
<parameter name="col002" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col003">
|
||||
<statement> AND col003 = $$col003$$ </statement>
|
||||
<parameter name="col003" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col004">
|
||||
<statement> AND col004 = $$col004$$ </statement>
|
||||
<parameter name="col004" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col005">
|
||||
<statement> AND col005 = $$col005$$ </statement>
|
||||
<parameter name="col005" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col006">
|
||||
<statement> AND col006 = $$col006$$ </statement>
|
||||
<parameter name="col006" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col007">
|
||||
<statement> AND col007 = $$col007$$ </statement>
|
||||
<parameter name="col007" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col008">
|
||||
<statement> AND col008 = $$col008$$ </statement>
|
||||
<parameter name="col008" valueType="java.lang.String" />
|
||||
</query>
|
||||
<query name="col009">
|
||||
<statement> AND col009 = $$col009$$ </statement>
|
||||
<parameter name="col009" valueType="java.lang.String" />
|
||||
</query>
|
||||
</query-set>
|
||||
<query name="orderBy">
|
||||
<statement>ORDER BY $$orderColumn$$ $$orderDirection$$</statement>
|
||||
<parameter name="orderColumn" type="RAW" defaultValue="id" valueType="java.lang.String" />
|
||||
<parameter name="orderDirection" type="RAW" defaultValue="ASC" valueType="java.lang.String" />
|
||||
</query>
|
||||
</query-set>
|
||||
|
||||
</query-set>
|
||||
|
39
tpquery-executor-jpa/pom.xml
Normal file
39
tpquery-executor-jpa/pom.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>tpquery-executor-jpa</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery-store</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jasper-el</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- note has to be after api-impl -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor.jpa;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
public class TPQExecutorJpa extends AbstractTPQExecutor<EntityManager,Query> {
|
||||
|
||||
private static final String HINT_TIMEOUT = "javax.persistence.query.timeout";
|
||||
|
||||
public TPQExecutorJpa(TPQExecutorContext context) {
|
||||
super(context);
|
||||
registrateStatementCreator(TPQFactory.StatementLanguage.HQL, (em,stmt) -> em.createQuery(stmt));
|
||||
registrateStatementCreator(TPQFactory.StatementLanguage.SQL, (em,stmt) -> em.createNativeQuery(stmt));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> List<E> selectList(EntityManager entityManager,String queryName,Map<String,Object> parameters) {
|
||||
return createPreparedStatement(entityManager, queryName, parameters).getResultList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> E selectObject(EntityManager entityManager,String queryName,Map<String,Object> parameters) {
|
||||
return (E)createPreparedStatement(entityManager, queryName, parameters).getSingleResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int executeUpdate(Query persistenceQuery) {
|
||||
return persistenceQuery.executeUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareParameterValue(Query persistenceQuery, int index,Object value) {
|
||||
persistenceQuery.setParameter(index,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTimeout(Query persistenceQuery, Integer timeout) {
|
||||
persistenceQuery.setHint(HINT_TIMEOUT, timeout);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Persistance executor.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor.jpa;
|
|
@ -0,0 +1,229 @@
|
|||
package net.forwardfire.tpquery.store.executor.jpa;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.statement.AbstractTPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.store.executor.jpa.TPQExecutorJpa;
|
||||
import net.forwardfire.tpquery.store.proxy.TPQueryName;
|
||||
import net.forwardfire.tpquery.store.proxy.TPQueryProxyFactory;
|
||||
import net.forwardfire.tpquery.store.proxy.TPQueryParameterName;
|
||||
import net.forwardfire.tpquery.store.proxy.TPQueryProxy;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
||||
public class TPQExecutorJpaTest {
|
||||
|
||||
private EntityManagerFactory emFactory;
|
||||
private EntityManager em = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupLogging() {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
lc.reset(); // disable logging
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
emFactory = Persistence.createEntityManagerFactory("junit");
|
||||
em = emFactory.createEntityManager();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
em.close();
|
||||
emFactory.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simple() throws Exception {
|
||||
|
||||
TestEntity t = new TestEntity();
|
||||
t.active = true;
|
||||
t.name = "test";
|
||||
t.description = "junit test 012345678901234567890123456789";
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(t);
|
||||
em.getTransaction().commit();
|
||||
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.HQL)
|
||||
.createQuery("test-select-sql")
|
||||
.setLanguage("SQL")
|
||||
.setTimeout(2000)
|
||||
.appendText("SELECT * from TestEntity")
|
||||
.build()
|
||||
.createQuery("test-select").appendText("from TestEntity").build()
|
||||
.createQuery("test-select-single")
|
||||
.appendText("from TestEntity te where te.name=")
|
||||
.appendParameter("name")
|
||||
.createQueryParameter("name","text").build()
|
||||
.build()
|
||||
.createQuery("test-update")
|
||||
.appendText("update TestEntity te set te.name=")
|
||||
.appendParameter("name")
|
||||
.createQueryParameter("name","text").build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
TPQExecutorJpa exe = new TPQExecutorJpa(store.getQueryExecutorContext());
|
||||
|
||||
//TQueryPrepared p = store.getQueryExecutorContext().prepareQuery("junit.test", null);
|
||||
//Query q = em.createQuery(p.getStatement());
|
||||
//q.getSingleResult();
|
||||
//q.getResultList();
|
||||
|
||||
List<TestEntity> resultSql = exe.selectList(em, "junit.test-select-sql", null);
|
||||
assertNotNull(resultSql);
|
||||
assertFalse(resultSql.isEmpty());
|
||||
|
||||
List<TestEntity> result = exe.selectList(em, "junit.test-select", null);
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("name", "foobar");
|
||||
em.getTransaction().begin();
|
||||
int updateResult = exe.executeUpdate(em, "junit.test-update", para);
|
||||
em.getTransaction().commit();
|
||||
assertEquals(1,updateResult);
|
||||
|
||||
TestEntity resultSingle = exe.selectObject(em, "junit.test-select-single", para);
|
||||
assertNotNull(resultSingle);
|
||||
//assertEquals("foobar",resultSingle.name);
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testUnsupportedLanguage() throws Exception {
|
||||
TPQConfig config = new TPQConfig();
|
||||
config.addStatementLanguage(new TPQStatementLanguage() {
|
||||
@Override
|
||||
public String getLanguageType() {
|
||||
return "XQL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementWriter createQueryWriter(Map<String, Object> parameterData) {
|
||||
return new AbstractTPQStatementWriter(parameterData) {
|
||||
};
|
||||
}
|
||||
});
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder(config)
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test")
|
||||
.setLanguage("XQL")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
TPQExecutorJpa exe = new TPQExecutorJpa(store.getQueryExecutorContext());
|
||||
exe.selectList(em, "junit.test", null);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testQueryProxy() throws Exception {
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.HQL)
|
||||
.createQuery("testSelect").appendText("from TestEntity").build()
|
||||
.createQuery("testSelectSingle")
|
||||
.appendText("from TestEntity te where te.name=")
|
||||
.appendParameter("name")
|
||||
.createQueryParameter("name","text").build()
|
||||
.build()
|
||||
.createQuery("testSelectMultiple")
|
||||
.appendText("from TestEntity te where te.name=")
|
||||
.appendParameter("name")
|
||||
.appendText(" and length(te.name) > ")
|
||||
.appendParameter("minLength")
|
||||
.createQueryParameter("name","text").build()
|
||||
.createQueryParameter("minLength","int").build()
|
||||
.build()
|
||||
.createQuery("testUpdate")
|
||||
.appendText("update TestEntity te set te.name=")
|
||||
.appendParameter("name")
|
||||
.createQueryParameter("name","text").build()
|
||||
.build()
|
||||
.createQuerySetTree("TestEntityFooBarDataService")
|
||||
.createQuery("testFoo").appendText("from TestEntity").build()
|
||||
.buildTree()
|
||||
.build()
|
||||
.build();
|
||||
TPQExecutorJpa exe = new TPQExecutorJpa(store.getQueryExecutorContext());
|
||||
|
||||
|
||||
TPQueryProxyFactory proxy = new TPQueryProxyFactory();
|
||||
proxy.registrateResultHandler(Object.class, (queryName,parameters) -> exe.selectObject (em, queryName, parameters));
|
||||
proxy.registrateResultHandler(List.class, (queryName,parameters) -> exe.selectList (em, queryName, parameters));
|
||||
proxy.registrateResultHandler(void.class, (queryName,parameters) -> exe.executeUpdate(em, queryName, parameters));
|
||||
proxy.registrateResultHandler(int.class, (queryName,parameters) -> exe.executeUpdate(em, queryName, parameters));
|
||||
proxy.registrateResultHandler(Integer.class, (queryName,parameters) -> exe.executeUpdate(em, queryName, parameters));
|
||||
|
||||
TestEntityDataService dataService = proxy.newProxyInstance(TestEntityDataService.class);
|
||||
TestEntityFooBarDataService foobarService = proxy.newProxyInstance(TestEntityFooBarDataService.class);
|
||||
|
||||
List<TestEntity> d = dataService.testSelect();
|
||||
assertNotNull(d);
|
||||
|
||||
d = dataService.testSelectMultiple(1,"abc1");
|
||||
d = dataService.testSelectMultiple(2,"abc2");
|
||||
d = dataService.testSelectMultiple(3,"abc3");
|
||||
assertNotNull(d);
|
||||
|
||||
d = foobarService.testFoo();
|
||||
assertNotNull(d);
|
||||
}
|
||||
|
||||
@TPQueryProxy(prefix="junit.")
|
||||
public interface TestEntityDataService {
|
||||
|
||||
List<TestEntity> testSelect();
|
||||
|
||||
@TPQueryName("testSelectSingle")
|
||||
TestEntity testSelectSingle(
|
||||
@TPQueryParameterName("name")
|
||||
String name
|
||||
);
|
||||
|
||||
List<TestEntity> testSelectMultiple(
|
||||
@TPQueryParameterName("minLength")
|
||||
int length,
|
||||
@TPQueryParameterName("name")
|
||||
String name
|
||||
);
|
||||
|
||||
void testUpdate(@TPQueryParameterName("name")String name);
|
||||
}
|
||||
|
||||
@TPQueryProxy(prefix="junit.%s.")
|
||||
interface TestEntityFooBarDataService {
|
||||
|
||||
@TPQueryName()
|
||||
List<TestEntity> testFoo();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package net.forwardfire.tpquery.store.executor.jpa;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
|
||||
@Entity
|
||||
public class TestEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
Long id;
|
||||
|
||||
@Column(nullable=false)
|
||||
@NotNull
|
||||
Boolean active;
|
||||
|
||||
@NotEmpty
|
||||
@Column(unique = true)
|
||||
String name;
|
||||
|
||||
@NotNull
|
||||
@Length(min = 30, max=200)
|
||||
String description;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0">
|
||||
<persistence-unit name="junit" transaction-type="RESOURCE_LOCAL">
|
||||
<class>net.forwardfire.tpquery.store.executor.jpa.TestEntity</class>
|
||||
<properties>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
|
||||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
|
||||
<property name="javax.persistence.jdbc.user" value="" />
|
||||
<property name="javax.persistence.jdbc.password" value="" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
22
tpquery-store/pom.xml
Normal file
22
tpquery-store/pom.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>tpquery-store</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,424 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.sql.JDBCType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.config.TPQConfigInitializer;
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueScripterObjectOrList;
|
||||
import net.forwardfire.tpquery.config.builder.TPQConfigBuilder;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguageHql;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguageSql;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterList;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterRaw;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterValue;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManager;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManagerStatementCache;
|
||||
|
||||
/**
|
||||
* The tpquery factory to create objects.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQFactory {
|
||||
|
||||
private static final String DEFAULT_TREEPATH_SEPERATOR = ".";
|
||||
private static final Boolean DEFAULT_PARAMETER_NULLABLE = false;
|
||||
private static final String DEFAULT_SCRIPT_ENGINE_MINE_TYPE = "text/javascript";
|
||||
private static final List<TPQConfigInitializer> DEFAULT_CONFIG_INITIALIZERS = Collections.unmodifiableList(Arrays.asList(
|
||||
new StatementLanguage(),
|
||||
new StatementParameter(),
|
||||
new ParameterValueTypeAlias(),
|
||||
new ParameterValueFunction(),
|
||||
new TPQConfigInitializer() {
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
// temp here move to better place.
|
||||
config.setTreePathSeperator(TPQFactory.DEFAULT_TREEPATH_SEPERATOR);
|
||||
config.setDefaultParameterNullable(DEFAULT_PARAMETER_NULLABLE);
|
||||
config.setDefaultParameterType(TPQFactory.StatementParameter.VALUE);
|
||||
config.setStatementCache(new TPQStoreManagerStatementCache());
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
protected TPQFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default config.
|
||||
* @return The config.
|
||||
*/
|
||||
public static TPQConfig createConfig() {
|
||||
return createConfig(DEFAULT_CONFIG_INITIALIZERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a empty config and the inits by the configInit list.
|
||||
* @param configInit The config initializers.
|
||||
* @return The config.
|
||||
*/
|
||||
public static TPQConfig createConfig(List<TPQConfigInitializer> configInit) {
|
||||
TPQConfig config = new TPQConfig();
|
||||
configInit.forEach(ci -> ci.initializeConfig(config));
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a manager from the config.
|
||||
* @param config The config for the manager.
|
||||
* @return The manager.
|
||||
*/
|
||||
public static TPQManager createManager(TPQConfig config) {
|
||||
return new TPQStoreManager(config);
|
||||
}
|
||||
|
||||
// ----- builders
|
||||
|
||||
/**
|
||||
* Create a builder that returns a manager.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQManager> createManagerBuilder() throws JAXBException {
|
||||
return createManagerBuilder(createConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns a manager.
|
||||
* @param config The config to build.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQManager> createManagerBuilder(TPQConfig config) throws JAXBException {
|
||||
return new TPQConfigBuilder<TPQManager>(config,() -> createManager(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns the config.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQConfig> createConfigBuilder() throws JAXBException {
|
||||
return createConfigBuilder(createConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns the config.
|
||||
* @param config The config to build.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQConfig> createConfigBuilder(TPQConfig config) throws JAXBException {
|
||||
return new TPQConfigBuilder<TPQConfig>(config,() -> config);
|
||||
}
|
||||
|
||||
// ----- classes
|
||||
|
||||
public static final class StatementLanguage implements TPQConfigInitializer {
|
||||
|
||||
public static final String SQL = "SQL";
|
||||
public static final String HQL = "HQL";
|
||||
|
||||
private StatementLanguage() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addStatementLanguage(new TPQStatementLanguageSql(SQL));
|
||||
config.addStatementLanguage(new TPQStatementLanguageHql(HQL));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class StatementParameter implements TPQConfigInitializer {
|
||||
public static final String VALUE = "VALUE";
|
||||
public static final String LIST = "LIST";
|
||||
public static final String RAW = "RAW";
|
||||
public static final String RAW_NULL = "RAW_NULL";
|
||||
|
||||
private StatementParameter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addStatementParameter(new TPQStatementParameterValue(VALUE));
|
||||
config.addStatementParameter(new TPQStatementParameterList(LIST));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW,""));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW_NULL,"null"));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueType {
|
||||
// java type
|
||||
public static final String JAVA_OBJECT = Object.class.getName();
|
||||
public static final String BIGDECIMAL = java.math.BigDecimal.class.getName();
|
||||
public static final String BOOLEAN = Boolean.class.getName();
|
||||
public static final String INTEGER = Integer.class.getName();
|
||||
public static final String STRING = String.class.getName();
|
||||
public static final String DOUBLE = Double.class.getName();
|
||||
public static final String LONG = Long.class.getName();
|
||||
public static final String FLOAT = Float.class.getName();
|
||||
public static final String SHORT = Short.class.getName();
|
||||
public static final String URL = java.net.URL.class.getName();
|
||||
public static final String BYTE_DATA = byte[].class.getName();
|
||||
|
||||
// jdbc types
|
||||
public static final String SQL_ARRAY = java.sql.Array.class.getName();
|
||||
public static final String SQL_BLOB = java.sql.Blob.class.getName();
|
||||
public static final String SQL_CLOB = java.sql.Clob.class.getName();
|
||||
public static final String SQL_DATE = java.sql.Date.class.getName();
|
||||
public static final String SQL_NCLOB = java.sql.NClob.class.getName();
|
||||
public static final String SQL_REF = java.sql.Ref.class.getName();
|
||||
public static final String SQL_ROWID = java.sql.RowId.class.getName();
|
||||
public static final String SQL_STRUCT = java.sql.Struct.class.getName();
|
||||
public static final String SQL_XML = java.sql.SQLXML.class.getName();
|
||||
public static final String SQL_TIME = java.sql.Time.class.getName();
|
||||
public static final String SQL_TIMESTAMP = java.sql.Timestamp.class.getName();
|
||||
|
||||
protected ParameterValueType() {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueTypeAlias implements TPQConfigInitializer {
|
||||
public static final String NUMERIC = "numeric";
|
||||
|
||||
public static final String SHORT = "short";
|
||||
public static final String INT2 = "int2";
|
||||
public static final String SMALLINT = "smallint";
|
||||
|
||||
public static final String INTEGER = "integer";
|
||||
public static final String INT = "int";
|
||||
public static final String INT4 = "int4";
|
||||
|
||||
public static final String LONG = "long";
|
||||
public static final String INT8 = "int8";
|
||||
public static final String BIGINT = "bigint";
|
||||
|
||||
public static final String BOOLEAN = "boolean";
|
||||
public static final String BOOL = "bool";
|
||||
|
||||
public static final String FLOAT = "float";
|
||||
public static final String FLOAT4 = "float4";
|
||||
public static final String REAL = "real";
|
||||
|
||||
public static final String DOUBLE = "double";
|
||||
public static final String FLOAT8 = "float8";
|
||||
public static final String DOUBLE_PRECISION = "double precision";
|
||||
|
||||
public static final String STRING = "string";
|
||||
public static final String TEXT = "text";
|
||||
public static final String VARCHAR = "varchar";
|
||||
public static final String LONGVARCHAR = "longvarchar";
|
||||
public static final String CHARACTER_VARYING = "character varying";
|
||||
public static final String CHAR = "char";
|
||||
public static final String CHARACTER = "character";
|
||||
|
||||
public static final String DATE = "date";
|
||||
public static final String TIME = "time";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
|
||||
private ParameterValueTypeAlias() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addValueTypeAlias(NUMERIC, ParameterValueType.BIGDECIMAL);
|
||||
|
||||
config.addValueTypeAlias(SHORT, ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(INT2, ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(SMALLINT, ParameterValueType.SHORT);
|
||||
|
||||
config.addValueTypeAlias(INTEGER, ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(INT, ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(INT4, ParameterValueType.INTEGER);
|
||||
|
||||
config.addValueTypeAlias(LONG, ParameterValueType.LONG);
|
||||
config.addValueTypeAlias(INT8, ParameterValueType.LONG);
|
||||
config.addValueTypeAlias(BIGINT, ParameterValueType.LONG);
|
||||
|
||||
config.addValueTypeAlias(BOOLEAN, ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(BOOL, ParameterValueType.BOOLEAN);
|
||||
|
||||
config.addValueTypeAlias(FLOAT, ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(FLOAT4, ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(REAL, ParameterValueType.FLOAT);
|
||||
|
||||
config.addValueTypeAlias(DOUBLE, ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(DOUBLE_PRECISION, ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(FLOAT8, ParameterValueType.DOUBLE);
|
||||
|
||||
config.addValueTypeAlias(STRING, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(TEXT, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(VARCHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(LONGVARCHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHARACTER_VARYING, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHARACTER, ParameterValueType.STRING);
|
||||
|
||||
config.addValueTypeAlias(DATE, ParameterValueType.SQL_DATE);
|
||||
config.addValueTypeAlias(TIME, ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(TIMESTAMP, ParameterValueType.SQL_TIMESTAMP);
|
||||
|
||||
// new jdbc names (missing; DISTINCT and REF_CURSOR)
|
||||
config.addValueTypeAlias(JDBCType.ARRAY.name(), ParameterValueType.SQL_ARRAY);
|
||||
config.addValueTypeAlias(JDBCType.BIGINT.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.BINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.BIT.name(), ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(JDBCType.BLOB.name(), ParameterValueType.SQL_BLOB);
|
||||
config.addValueTypeAlias(JDBCType.BOOLEAN.name(), ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(JDBCType.CHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.CLOB.name(), ParameterValueType.SQL_CLOB);
|
||||
config.addValueTypeAlias(JDBCType.DATALINK.name(), ParameterValueType.URL);
|
||||
config.addValueTypeAlias(JDBCType.DATE.name(), ParameterValueType.SQL_DATE);
|
||||
config.addValueTypeAlias(JDBCType.DECIMAL.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.DOUBLE.name(), ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(JDBCType.FLOAT.name(), ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(JDBCType.INTEGER.name(), ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(JDBCType.JAVA_OBJECT.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.LONGNVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.LONGVARBINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.LONGVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.NCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.NCLOB.name(), ParameterValueType.SQL_NCLOB);
|
||||
config.addValueTypeAlias(JDBCType.NULL.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.NUMERIC.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.NVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.OTHER.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.REAL.name(), ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(JDBCType.REF.name(), ParameterValueType.SQL_REF);
|
||||
config.addValueTypeAlias(JDBCType.ROWID.name(), ParameterValueType.SQL_ROWID);
|
||||
config.addValueTypeAlias(JDBCType.SMALLINT.name(), ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(JDBCType.SQLXML.name(), ParameterValueType.SQL_XML);
|
||||
config.addValueTypeAlias(JDBCType.STRUCT.name(), ParameterValueType.SQL_STRUCT);
|
||||
config.addValueTypeAlias(JDBCType.TIME.name(), ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(JDBCType.TIME_WITH_TIMEZONE.name(), ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(JDBCType.TIMESTAMP.name(), ParameterValueType.SQL_TIMESTAMP);
|
||||
config.addValueTypeAlias(JDBCType.TIMESTAMP_WITH_TIMEZONE.name(), ParameterValueType.SQL_TIMESTAMP);
|
||||
config.addValueTypeAlias(JDBCType.TINYINT.name(), ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(JDBCType.VARBINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.VARCHAR.name(), ParameterValueType.STRING);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueFunction implements TPQConfigInitializer {
|
||||
|
||||
private static final String NEW_PREFIX = "new ";
|
||||
private static final String FUNCTION_PREFIX = "function ";
|
||||
private static final String FUNCTION_ARGS_BEGIN = "(";
|
||||
private static final String FUNCTION_ARGS_END = ")";
|
||||
private static final String FUNCTION_ARGS_EMPTY = FUNCTION_ARGS_BEGIN+FUNCTION_ARGS_END;
|
||||
|
||||
public static final String CREATE_OBJECT = "createObject";
|
||||
public static final String CREATE_ARRAY_LIST = "createArrayList";
|
||||
public static final String CREATE_HASH_MAP = "createHashMap";
|
||||
public static final String CREATE_OBJECT_LIST = "createObjectList";
|
||||
public static final String CREATE_VALUE_HOLDER = "createValueHolder";
|
||||
public static final String EPOCH = "epoch";
|
||||
public static final String DATE = "date";
|
||||
public static final String TIME = "time";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
|
||||
private ParameterValueFunction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
|
||||
config.addParameterValueScript(FUNCTION_PREFIX
|
||||
+CREATE_OBJECT+"(clazz,value) {\n"
|
||||
+"\tif (value) {\n"
|
||||
+"\t return "+NEW_PREFIX+"clazz(value);\n"
|
||||
+"\t} else {\n"
|
||||
+"\t return "+NEW_PREFIX+"clazz();\n"
|
||||
+"\t}\n"
|
||||
+"}\n");
|
||||
config.addParameterValueScript(FUNCTION_PREFIX
|
||||
+CREATE_OBJECT_LIST+"(clazz,value) {\n"
|
||||
+"\tvar values = value.split(',');\n"
|
||||
+"\tvar result = "+CREATE_ARRAY_LIST+"();\n"
|
||||
+"\tfor (var i = 0; i < values.length; i++) {\n"
|
||||
+"\t result.add("+CREATE_OBJECT+"(clazz,values[i]));\n"
|
||||
+"\t}\n"
|
||||
+"\treturn result;\n"
|
||||
+"}\n");
|
||||
|
||||
config.addParameterValueScript(FUNCTION_PREFIX+CREATE_VALUE_HOLDER+"(value) { return new Packages."+TPQConfigParameterValueHolder.class.getName()+"(value); }");
|
||||
|
||||
config.addParameterValueScript(buildFunctionCreateObject(CREATE_ARRAY_LIST,ArrayList.class.getName()));
|
||||
config.addParameterValueScript(buildFunctionCreateObject(CREATE_HASH_MAP,HashMap.class.getName()));
|
||||
|
||||
config.addParameterValueScript(buildFunctionReturn(EPOCH,System.class.getName()+".currentTimeMillis()"));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(DATE,ParameterValueType.SQL_DATE));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(TIME,ParameterValueType.SQL_TIME));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(TIMESTAMP,ParameterValueType.SQL_TIMESTAMP));
|
||||
|
||||
config.setParameterValueEngine(createScriptEngine());
|
||||
config.setParameterValueScripter(new TPQConfigParameterValueScripterObjectOrList());
|
||||
}
|
||||
|
||||
private TPQueryStoreScriptEngine createScriptEngine() {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType(DEFAULT_SCRIPT_ENGINE_MINE_TYPE);
|
||||
Validate.isInstanceOf(Compilable.class, engine, "ScriptEngine does not implement Compilable interface.");
|
||||
Validate.isInstanceOf(Invocable.class, engine, "ScriptEngine does not implement Invocable interface.");
|
||||
return (TPQueryStoreScriptEngine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{TPQueryStoreScriptEngine.class}, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return method.invoke(engine, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String buildFunctionReturn(String name,String body) {
|
||||
return FUNCTION_PREFIX+name+FUNCTION_ARGS_EMPTY+" { return "+body+"; }";
|
||||
}
|
||||
|
||||
private String buildFunctionEpochObject(String name,String epochClass) {
|
||||
return buildFunctionReturn(name,NEW_PREFIX+epochClass+FUNCTION_ARGS_BEGIN+EPOCH+FUNCTION_ARGS_EMPTY+FUNCTION_ARGS_END);
|
||||
}
|
||||
|
||||
private String buildFunctionCreateObject(String name,String className) {
|
||||
return buildFunctionReturn(name,CREATE_OBJECT+FUNCTION_ARGS_BEGIN+className+FUNCTION_ARGS_END);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
/**
|
||||
* The manager holds the query store and executor context.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 14, 2015
|
||||
*/
|
||||
public interface TPQManager {
|
||||
|
||||
/**
|
||||
* Returns the query store.
|
||||
* @return The query store.
|
||||
*/
|
||||
TPQueryStore getQueryStore();
|
||||
|
||||
/**
|
||||
* Returns the query executor context.
|
||||
* @return The query executor context.
|
||||
*/
|
||||
TPQExecutorContext getQueryExecutorContext();
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidator;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementCache;
|
||||
|
||||
/**
|
||||
* Abstract config data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQConfig {
|
||||
|
||||
protected String treePathSeperator;
|
||||
protected String defaultParameterType;
|
||||
protected Boolean defaultParameterNullable;
|
||||
protected TPQueryStoreStatementCache statementCache;
|
||||
protected TPQueryStoreScriptEngine parameterValueEngine;
|
||||
protected TPQConfigParameterValueScripter parameterValueScripter;
|
||||
protected final Map<String,TPQuerySet> querySets;
|
||||
protected final Map<String,TPQStatementParameter> statementParameters;
|
||||
protected final Map<String,TPQStatementLanguage> statementLanguages;
|
||||
protected final Map<String,String> valueTypeAliases;
|
||||
protected final List<TPQConfigValidator> configValidators;
|
||||
protected final List<String> parameterValueScripts;
|
||||
|
||||
protected AbstractTPQConfig() {
|
||||
this(new HashMap<>(),new HashMap<>(),new HashMap<>(),new HashMap<>(),new ArrayList<>(),new ArrayList<>());
|
||||
}
|
||||
|
||||
protected AbstractTPQConfig(
|
||||
Map<String,TPQuerySet> querySets,
|
||||
Map<String,TPQStatementParameter> statementParameters,
|
||||
Map<String,TPQStatementLanguage> statementLanguages,
|
||||
Map<String,String> valueTypeAliases,
|
||||
List<TPQConfigValidator> configValidators,
|
||||
List<String> parameterValueScripts
|
||||
) {
|
||||
this.querySets=querySets;
|
||||
this.statementParameters=statementParameters;
|
||||
this.statementLanguages=statementLanguages;
|
||||
this.valueTypeAliases=valueTypeAliases;
|
||||
this.configValidators=configValidators;
|
||||
this.parameterValueScripts=parameterValueScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the treePathSeperator
|
||||
*/
|
||||
public String getTreePathSeperator() {
|
||||
return treePathSeperator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultParameterType
|
||||
*/
|
||||
public String getDefaultParameterType() {
|
||||
return defaultParameterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultParameterNullable
|
||||
*/
|
||||
public Boolean getDefaultParameterNullable() {
|
||||
return defaultParameterNullable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementCache
|
||||
*/
|
||||
public TPQueryStoreStatementCache getStatementCache() {
|
||||
return statementCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueEngine
|
||||
*/
|
||||
public TPQueryStoreScriptEngine getParameterValueEngine() {
|
||||
return parameterValueEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueScripter
|
||||
*/
|
||||
public TPQConfigParameterValueScripter getParameterValueScripter() {
|
||||
return parameterValueScripter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the querySets
|
||||
*/
|
||||
public Map<String, TPQuerySet> getQuerySets() {
|
||||
return querySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementParameters
|
||||
*/
|
||||
public Map<String, TPQStatementParameter> getStatementParameters() {
|
||||
return statementParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementLanguages
|
||||
*/
|
||||
public Map<String, TPQStatementLanguage> getStatementLanguages() {
|
||||
return statementLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueTypeAliases
|
||||
*/
|
||||
public Map<String, String> getValueTypeAliases() {
|
||||
return valueTypeAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configValidators
|
||||
*/
|
||||
public List<TPQConfigValidator> getConfigValidators() {
|
||||
return configValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueScripts
|
||||
*/
|
||||
public List<String> getParameterValueScripts() {
|
||||
return parameterValueScripts;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidator;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheck;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementCache;
|
||||
|
||||
/**
|
||||
* Holds the config to build the query manager.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQConfig extends AbstractTPQConfig {
|
||||
|
||||
/**
|
||||
* Creates a empty TPQStore.
|
||||
*/
|
||||
public TPQConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param treePathSeperator the treePathSeperator to set.
|
||||
*/
|
||||
public void setTreePathSeperator(String treePathSeperator) {
|
||||
this.treePathSeperator = Validate.notNull(treePathSeperator,"Can't set treePathSeperator to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultParameterType the defaultParameterType to set
|
||||
*/
|
||||
public void setDefaultParameterType(String defaultParameterType) {
|
||||
this.defaultParameterType = Validate.notNull(defaultParameterType,"Can't set defaultParameterType to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultParameterNullable the defaultParameterNullable to set
|
||||
*/
|
||||
public void setDefaultParameterNullable(Boolean defaultParameterNullable) {
|
||||
this.defaultParameterNullable = Validate.notNull(defaultParameterNullable,"Can't set defaultParameterNullable to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param statementCache the statementCache to set
|
||||
*/
|
||||
public void setStatementCache(TPQueryStoreStatementCache statementCache) {
|
||||
this.statementCache = Validate.notNull(statementCache,"Can't set statementCache to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterValueScripter the parameterValueScripter to set
|
||||
*/
|
||||
public void setParameterValueScripter(TPQConfigParameterValueScripter parameterValueScripter) {
|
||||
this.parameterValueScripter = Validate.notNull(parameterValueScripter,"Can't set parameterValueScripter to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterValueEngine the parameterValueEngine to set
|
||||
*/
|
||||
public void setParameterValueEngine(TPQueryStoreScriptEngine parameterValueEngine) {
|
||||
this.parameterValueEngine = Validate.notNull(parameterValueEngine,"Can't set parameterValueEngine to null");
|
||||
}
|
||||
|
||||
private <K,V> void mapAdd(Map<K,V> map,K key,V value) {
|
||||
Validate.notNull(map);
|
||||
Validate.notNull(key);
|
||||
Validate.notNull(value);
|
||||
Validate.isTrue(Objects.isNull(map.get(key)),"Cannot handle key twice: %s",key);
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
private <K,V> void mapRemove(Map<K,V> map,K key) {
|
||||
Validate.notNull(Validate.notNull(map).remove(Validate.notNull(key)),"No object for key %s",key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @param systemId The systemId from which the query set was loaded.
|
||||
*/
|
||||
public void addQuerySet(String systemId,TPQuerySet qs) {
|
||||
mapAdd(querySets, systemId, qs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a query set.
|
||||
* @param systemId The systemId of the query set to remove.
|
||||
*/
|
||||
public void removeQuerySet(String systemId) {
|
||||
mapRemove(querySets,systemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a statement parameter.
|
||||
* @param statementParameter The statement parameter to add.
|
||||
*/
|
||||
public void addStatementParameter(TPQStatementParameter statementParameter) {
|
||||
mapAdd(statementParameters, statementParameter.getParameterType(), statementParameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a statement parameter.
|
||||
* @param statementParameterKey The parameter key.
|
||||
*/
|
||||
public void removeStatementParameter(String statementParameterKey) {
|
||||
mapRemove(statementParameters,statementParameterKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a statement language.
|
||||
* @param statementLanguage The statement language to add.
|
||||
*/
|
||||
public void addStatementLanguage(TPQStatementLanguage statementLanguage) {
|
||||
mapAdd(statementLanguages, statementLanguage.getLanguageType(), statementLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a statement language.
|
||||
* @param statementLanguageKey The statement language key.
|
||||
*/
|
||||
public void removeStatementLanguage(String statementLanguageKey) {
|
||||
mapRemove(statementLanguages, statementLanguageKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value alias.
|
||||
* @param alias The alias to add.
|
||||
* @param valueType The aliases valueType.
|
||||
*/
|
||||
public void addValueTypeAlias(String alias,String valueType) {
|
||||
mapAdd(valueTypeAliases, alias, valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a value type alias.
|
||||
* @param alias The alias to remove.
|
||||
*/
|
||||
public void removeValueTypeAlias(String alias) {
|
||||
mapRemove(valueTypeAliases, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a config validator.
|
||||
* @param namePattern The pattern where to check.
|
||||
* @param validatorChecker The checker validator.
|
||||
* @return The validator.
|
||||
*/
|
||||
public TPQConfigValidator addConfigValidator(String namePattern,TPQConfigValidatorCheck validatorChecker) {
|
||||
TPQConfigValidator result = new TPQConfigValidator(namePattern,validatorChecker); // validator does null check
|
||||
configValidators.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a config validator.
|
||||
* @param validator The validator to remove.
|
||||
*/
|
||||
public void removeConfigValidator(TPQConfigValidator validator) {
|
||||
configValidators.remove(Validate.notNull(validator,"Can't remove null validator"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value script.
|
||||
* @param script The script to add.
|
||||
*/
|
||||
public void addParameterValueScript(String script) {
|
||||
parameterValueScripts.add(Validate.notNull(script,"Can't add null script."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value script.
|
||||
* @param script The script to remove.
|
||||
*/
|
||||
public void removeParameterValueScript(String script) {
|
||||
parameterValueScripts.remove(Validate.notNull(script,"Can't remove null script."));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
/**
|
||||
* Interface to split the config init over classes.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 1, 2015
|
||||
*/
|
||||
public interface TPQConfigInitializer {
|
||||
|
||||
/**
|
||||
* init config.
|
||||
* @param config The config to init.
|
||||
*/
|
||||
void initializeConfig(TPQConfig config);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
/**
|
||||
* Caches a default value as a value so it only need to be resolved once.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 28, 2015
|
||||
*/
|
||||
public final class TPQConfigParameterValueHolder {
|
||||
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Creates this value holder.
|
||||
* @param value The value to hold.
|
||||
*/
|
||||
public TPQConfigParameterValueHolder(Object value) {
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constant value.
|
||||
* @return The value.
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Convert a default value to a script to resolve the value as object.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 26, 2015
|
||||
*/
|
||||
public interface TPQConfigParameterValueScripter {
|
||||
|
||||
/**
|
||||
* Convert the defaultValue to script form.
|
||||
* @param queryParameter The query parameter to create de script for.
|
||||
* @return The text of the script.
|
||||
*/
|
||||
String convertDefaultValueToScript(TPQueryParameter queryParameter);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Can convert objects and list to a js script value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQConfigParameterValueScripterObjectOrList implements TPQConfigParameterValueScripter {
|
||||
|
||||
protected static final String PREFIX_JS = "js:";
|
||||
|
||||
@Override
|
||||
public String convertDefaultValueToScript(TPQueryParameter queryParameter) {
|
||||
String defaultValue = queryParameter.getDefaultValue();
|
||||
if (defaultValue.startsWith(PREFIX_JS)) {
|
||||
return defaultValue.substring(PREFIX_JS.length());
|
||||
} else {
|
||||
return createDefaultValueToScript(queryParameter);
|
||||
}
|
||||
}
|
||||
|
||||
private String createDefaultValueToScript(TPQueryParameter queryParameter) {
|
||||
// Create object function wrappers
|
||||
String functionName = TPQFactory.ParameterValueFunction.CREATE_OBJECT;
|
||||
if (TPQFactory.StatementParameter.LIST.equals(queryParameter.getType())) {
|
||||
functionName = TPQFactory.ParameterValueFunction.CREATE_OBJECT_LIST;
|
||||
}
|
||||
String value = queryParameter.getDefaultValue().replaceAll("'", "\\\\'");
|
||||
String function = functionName+"("+queryParameter.getValueType()+",'"+value+"')";
|
||||
|
||||
// Wrap in value holder because these values will not change anymore.
|
||||
return PREFIX_JS+TPQFactory.ParameterValueFunction.CREATE_VALUE_HOLDER+"("+function+");";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Abstract object builder with parent builder.
|
||||
*
|
||||
*
|
||||
* @param <P> The parent builder.
|
||||
* @param <T> The object to build.
|
||||
* @param <B> This builder.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQBuilder<P,T,B> {
|
||||
|
||||
private final P parent;
|
||||
private final T value;
|
||||
|
||||
/**
|
||||
* Creates the builder.
|
||||
* @param parent The parent builder.
|
||||
* @param value The object to build.
|
||||
*/
|
||||
public AbstractTPQBuilder(P parent,T value) {
|
||||
this.parent=parent;
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
protected P getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
protected abstract B getBuilder();
|
||||
|
||||
/**
|
||||
* Builds the result.
|
||||
* @return The result.
|
||||
*/
|
||||
public final P build() {
|
||||
buildParent();
|
||||
return getParent();
|
||||
}
|
||||
|
||||
protected abstract void buildParent();
|
||||
|
||||
protected B make(Consumer<T> mixer) {
|
||||
mixer.accept(getValue());
|
||||
return getBuilder();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractTPQueryNode;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
|
||||
/**
|
||||
* Abstract query node builder for the shared properties of the AbstractTPQueryNode.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQueryNodeBuilder<P,T extends AbstractTPQueryNode,B> extends AbstractTPQBuilder<P,T,B> {
|
||||
|
||||
public AbstractTPQueryNodeBuilder(P parent, T build) {
|
||||
super(parent, build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language.
|
||||
* @param language The langauge.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setLanguage(String language) {
|
||||
return make(build -> build.setLanguage(language));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description.
|
||||
* @param description The description.
|
||||
* @return The builder;
|
||||
*/
|
||||
public B setDescription(String description) {
|
||||
return make(build -> build.setDescription(description));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template option.
|
||||
* @param template The template option.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setTemplate(Boolean template) {
|
||||
return make(build -> build.setTemplate(template));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout.
|
||||
* @param timeout The timeout.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setTimeout(Integer timeout) {
|
||||
return make(build -> build.setTimeout(timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an query hint.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B addQueryHint(String name,String value) {
|
||||
return make(build -> build.addQueryHint(new TPQueryHint(name,value)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshaller;
|
||||
|
||||
/**
|
||||
* The root config builder.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public class TPQConfigBuilder<T> {
|
||||
|
||||
private final TPQConfig storeConfig;
|
||||
private final Supplier<T> resultBuilder;
|
||||
private final TPQuerySetXMLMarshaller xmlDriver;
|
||||
private final TPQStatementMarshaller statementMarshaller;
|
||||
|
||||
/**
|
||||
* Creates a config builder.
|
||||
* @param storeConfig The config to build.
|
||||
* @param resultBuilder the result of this builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public TPQConfigBuilder(TPQConfig storeConfig,Supplier<T> resultBuilder) throws JAXBException {
|
||||
Objects.requireNonNull(storeConfig,"Can't build null config.");
|
||||
Objects.requireNonNull(resultBuilder,"Can't build with null builder.");
|
||||
this.storeConfig = storeConfig;
|
||||
this.resultBuilder = resultBuilder;
|
||||
this.xmlDriver = new TPQuerySetXMLMarshaller();
|
||||
this.statementMarshaller = new TPQStatementMarshaller();
|
||||
}
|
||||
|
||||
protected TPQStatementMarshaller getStatementMarshaller() {
|
||||
return statementMarshaller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the result.
|
||||
* @return The result.
|
||||
*/
|
||||
public T build() {
|
||||
return resultBuilder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an query set.
|
||||
* @param systemId The systemId of the query set.
|
||||
* @param querySet The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQConfigBuilder<T> addQuerySet(String systemId,TPQuerySet querySet) {
|
||||
storeConfig.addQuerySet(systemId,querySet);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
|
||||
Objects.requireNonNull(input, "Can't read null InputStream");
|
||||
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an query set.
|
||||
* @param resource The resource to read.
|
||||
* @return The builder.
|
||||
* @throws JAXBException When marshall error.
|
||||
*/
|
||||
public TPQConfigBuilder<T> readQuerySet(String resource) throws JAXBException {
|
||||
Objects.requireNonNull(resource, "Can't read null resource");
|
||||
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an query set.
|
||||
* @param file The file to read.
|
||||
* @return The builder.
|
||||
* @throws JAXBException When marshall error.
|
||||
*/
|
||||
public TPQConfigBuilder<T> readQuerySet(File file) throws JAXBException {
|
||||
Objects.requireNonNull(file, "Can't read null File");
|
||||
try {
|
||||
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an query set.
|
||||
* @param name The query set name.
|
||||
* @param systemId The query set systemId.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> createQuerySet(String name,String systemId) {
|
||||
return new TPQuerySetBuilder<T>(this,name,systemId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||
|
||||
/**
|
||||
* Builds queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQueryBuilder<T,P> extends AbstractTPQueryNodeBuilder<P,TPQuery,TPQueryBuilder<T,P>> {
|
||||
|
||||
private final TPQConfigBuilder<T> configBuilder;
|
||||
private final TPQueryBuilderParent builderParent;
|
||||
|
||||
/**
|
||||
* Creates the query builder.
|
||||
* @param configBuilder The parent config builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The name of the query.
|
||||
* @param builderParent The callback to build the parent.
|
||||
*/
|
||||
public TPQueryBuilder(TPQConfigBuilder<T> configBuilder,P parent,String name,TPQueryBuilderParent builderParent) {
|
||||
super(parent,new TPQuery(name));
|
||||
this.configBuilder = configBuilder;
|
||||
this.builderParent = builderParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQueryBuilder<T,P> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
builderParent.buildChild(getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query parameter.
|
||||
* @param name The parameter name.
|
||||
* @param valueType The parameter value type.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> createQueryParameter(String name,String valueType) {
|
||||
return new TPQueryParameterBuilder<T,P>(this,name,valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query parameter.
|
||||
* @param name The parameter name.
|
||||
* @param valueTypeClass The parameter value type.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> createQueryParameter(String name,Class<?> valueTypeClass) {
|
||||
Validate.notNull(valueTypeClass, "Can't append null valueTypeClass");
|
||||
return createQueryParameter(name, valueTypeClass.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Addes an query part.
|
||||
* @param queryPart The part to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> addQueryPart(TPQStatement queryPart) {
|
||||
Validate.notNull(queryPart, "Can't append null queryPart");
|
||||
getValue().addQueryPart(queryPart);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed the statement into parts.
|
||||
* @param value The statement value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> parseStatement(String value) {
|
||||
Validate.notNull(value, "Can't parse null value");
|
||||
getValue().getQueryParts().addAll(configBuilder.getStatementMarshaller().unmarshal(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends text part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendText(String value) {
|
||||
return addQueryPart(new TPQStatementPartText(Validate.notNull(value, "Can't append null textvalue")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends parameter part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendParameter(String value) {
|
||||
return addQueryPart(new TPQStatementPartParameter(Validate.notNull(value, "Can't append null template value")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends include part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendInclude(String value) {
|
||||
return addQueryPart(new TPQStatementPartInclude(Validate.notNull(value, "Can't append null include value")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Build the parent for when we don't know the parent.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public interface TPQueryBuilderParent {
|
||||
|
||||
/**
|
||||
* Build the query child to the parent.
|
||||
* @param query The child query.
|
||||
*/
|
||||
void buildChild(TPQuery query);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Builds query parameters.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQueryParameterBuilder<T,P> extends AbstractTPQBuilder<TPQueryBuilder<T,P>,TPQueryParameter,TPQueryParameterBuilder<T,P>> {
|
||||
|
||||
public TPQueryParameterBuilder(TPQueryBuilder<T,P> parent,String name,String valueType) {
|
||||
super(parent,new TPQueryParameter(name,valueType));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQueryParameterBuilder<T, P> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
getParent().getValue().addQueryParameter(getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Sets the parameter type.
|
||||
* @param type The type to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setType(String type) {
|
||||
return make(build -> build.setType(Validate.notNull(type, "Can't set null type")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter default value.
|
||||
* @param defaultValue The defaultValue to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setDefaultValue(String defaultValue) {
|
||||
return make(build -> build.setDefaultValue(Validate.notNull(defaultValue, "Can't set null default value")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter nullable.
|
||||
* @param nullable The nullable to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setNullable(Boolean nullable) {
|
||||
return make(build -> build.setNullable(Validate.notNull(nullable, "Can't set null nullable")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Builds query set.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQuerySetBuilder<T> extends AbstractTPQueryNodeBuilder<TPQConfigBuilder<T>,TPQuerySet,TPQuerySetBuilder<T>> {
|
||||
|
||||
private final String systemId;
|
||||
|
||||
/**
|
||||
* Creates an query set builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The name of the query set.
|
||||
* @param systemId The systemId of the query set.
|
||||
*/
|
||||
public TPQuerySetBuilder(TPQConfigBuilder<T> parent,String name,String systemId) {
|
||||
super(parent,new TPQuerySet(name));
|
||||
this.systemId=systemId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQuerySetBuilder<T> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
getParent().addQuerySet(systemId, getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query.
|
||||
* @param name The query name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,TPQuerySetBuilder<T>> createQuery(String name) {
|
||||
return new TPQueryBuilder<T,TPQuerySetBuilder<T>>(getParent(),this,name,new TPQueryBuilderParent() {
|
||||
@Override
|
||||
public void buildChild(TPQuery query) {
|
||||
getValue().addQuery(query);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> addQuerySet(TPQuerySet qs) {
|
||||
return make(build -> build.addQuerySet(qs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query set tree.
|
||||
* @param name The query set name.
|
||||
* @return The tree builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> createQuerySetTree(String name) {
|
||||
return new TPQuerySetNodeBuilder<T>(this,null,name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Builds query set as tree.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQuerySetNodeBuilder<T> extends AbstractTPQueryNodeBuilder<TPQuerySetNodeBuilder<T>,TPQuerySet,TPQuerySetNodeBuilder<T>> {
|
||||
|
||||
private final TPQuerySetBuilder<T> treeRoot;
|
||||
|
||||
/**
|
||||
* Creates an query set node.
|
||||
* @param treeRoot The root query set builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The query set name.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder(TPQuerySetBuilder<T> treeRoot,TPQuerySetNodeBuilder<T> parent,String name) {
|
||||
super(parent,new TPQuerySet(name));
|
||||
this.treeRoot=treeRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQuerySetNodeBuilder<T> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
Validate.validState(Objects.nonNull(getParent()),"build() on root node is illegal use buildTree()");
|
||||
getParent().addQuerySet(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the tree and returns the parent query set builder.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> buildTree() {
|
||||
Validate.validState(Objects.isNull(getParent()),"buildTree() only works on tree root node.");
|
||||
treeRoot.addQuerySet(getValue());
|
||||
return treeRoot;
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query.
|
||||
* @param name The query name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,TPQuerySetNodeBuilder<T>> createQuery(String name) {
|
||||
return new TPQueryBuilder<T,TPQuerySetNodeBuilder<T>>(treeRoot.getParent(),this,name,new TPQueryBuilderParent() {
|
||||
@Override
|
||||
public void buildChild(TPQuery query) {
|
||||
getValue().addQuery(query);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> addQuerySet(TPQuerySet qs) {
|
||||
return make(build -> build.addQuerySet(qs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query set.
|
||||
* @param name The query set name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> createQuerySet(String name) {
|
||||
return new TPQuerySetNodeBuilder<T>(treeRoot,this,name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Builders for query-sets and queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Config of the queries and languages,types,etc.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Abstract pattern checker which used an Function to get the value to check the pattern against.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQConfigValidatorParameterPattern implements TPQConfigValidatorCheck {
|
||||
|
||||
private final String pattern;
|
||||
private final Function<TPQueryParameter,String> patternValue;
|
||||
|
||||
/**
|
||||
* Creates this pattern check.
|
||||
* @param pattern The pattern to check.
|
||||
* @param patternValue The function to get value to check.
|
||||
*/
|
||||
public AbstractTPQConfigValidatorParameterPattern(String pattern,Function<TPQueryParameter,String> patternValue) {
|
||||
Validate.notNull(patternValue);
|
||||
this.pattern=pattern;
|
||||
this.patternValue=patternValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
query.getQueryParameters().forEach(p -> {
|
||||
String value = patternValue.apply(p);
|
||||
Validate.notNull(value,"%s need non null value",this.getClass().getName());
|
||||
Validate.matchesPattern(value, pattern, "validation failed on query %s, parameter: %s value: %s does not match %s",query.getName(),p.getName(),value,pattern);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Holds the query name pattern fot he config validator checker.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public class TPQConfigValidator {
|
||||
|
||||
private final String pattern;
|
||||
private final TPQConfigValidatorCheck check;
|
||||
|
||||
/**
|
||||
* Creates an config validator.
|
||||
* @param pattern The query name pattern.
|
||||
* @param check The checker to validate the queries which match the pattern.
|
||||
*/
|
||||
public TPQConfigValidator(String pattern, TPQConfigValidatorCheck check) {
|
||||
Validate.notBlank(pattern);
|
||||
Validate.notNull(check);
|
||||
this.pattern = pattern;
|
||||
this.check = check;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pattern
|
||||
*/
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the check
|
||||
*/
|
||||
public TPQConfigValidatorCheck getCheck() {
|
||||
return check;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* validates the given query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public interface TPQConfigValidatorCheck {
|
||||
|
||||
/**
|
||||
* Validate this query.
|
||||
* @param query The query to validate.
|
||||
*/
|
||||
void validateQuery(TPQuery query);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query description to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckDescriptionNotBlank implements TPQConfigValidatorCheck {
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
Validate.notBlank(query.getDescription());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query name to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckNamePattern implements TPQConfigValidatorCheck {
|
||||
|
||||
private final String pattern;
|
||||
|
||||
public TPQConfigValidatorCheckNamePattern(String pattern) {
|
||||
Validate.matchesPattern("", pattern);
|
||||
this.pattern=pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
Validate.matchesPattern(query.getName(), pattern);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query parameters default value to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckParameterDefaultValueNotBlank implements TPQConfigValidatorCheck {
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
query.getQueryParameters().forEach(p -> Validate.notBlank(p.getDefaultValue()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters name to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckParameterNamePattern extends AbstractTPQConfigValidatorParameterPattern {
|
||||
|
||||
public TPQConfigValidatorCheckParameterNamePattern(String pattern) {
|
||||
super(pattern,p -> p.getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters type to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckParameterTypePattern extends AbstractTPQConfigValidatorParameterPattern {
|
||||
|
||||
public TPQConfigValidatorCheckParameterTypePattern(String pattern) {
|
||||
super(pattern,p -> p.getType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters value type to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckParameterValueTypePattern extends AbstractTPQConfigValidatorParameterPattern {
|
||||
|
||||
public TPQConfigValidatorCheckParameterValueTypePattern(String pattern) {
|
||||
super(pattern,p -> p.getValueType());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Extra query model validation checks.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
|
||||
/**
|
||||
* AbstractTPQueryNode has the shared properties of an query(set) node.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQueryNode {
|
||||
|
||||
private String name = null;
|
||||
private String description = null;
|
||||
private String language = null;
|
||||
private Boolean template = null;
|
||||
private Integer timeout = null;
|
||||
private final List<TPQueryHint> queryHints;
|
||||
|
||||
public AbstractTPQueryNode() {
|
||||
queryHints = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_DESCRIPTION)
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the language
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.LANGUAGE)
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language the language to set
|
||||
*/
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the template
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TEMPLATE)
|
||||
public Boolean getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param template the template to set
|
||||
*/
|
||||
public void setTemplate(Boolean template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timeout
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TIMEOUT)
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeout the timeout to set
|
||||
*/
|
||||
public void setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryHints
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_HINT)
|
||||
public List<TPQueryHint> getQueryHints() {
|
||||
return queryHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryHint the queryHint to add
|
||||
*/
|
||||
public void addQueryHint(TPQueryHint queryHint) {
|
||||
Objects.requireNonNull(queryHint);
|
||||
queryHints.add(queryHint);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
/**
|
||||
* AbstractXMLMarshaller has all jaxb meta info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
abstract class AbstractXMLMarshaller {
|
||||
|
||||
protected static final String XML_ENCODING = "UTF-8";
|
||||
|
||||
protected AbstractXMLMarshaller() {
|
||||
}
|
||||
|
||||
protected static class Meta {
|
||||
protected static final boolean REQUIRED = true;
|
||||
protected Meta() {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Element {
|
||||
protected static final String QUERY_SET = "query-set";
|
||||
protected static final String QUERY = "query";
|
||||
protected static final String QUERY_DESCRIPTION = "description";
|
||||
protected static final String QUERY_HINT = "hint";
|
||||
protected static final String QUERY_PARAMETER = "parameter";
|
||||
protected static final String QUERY_PART = "statement";
|
||||
protected Element() {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Attribute {
|
||||
protected static final String NAME = "name";
|
||||
protected static final String VALUE = "value";
|
||||
protected static final String TYPE = "type";
|
||||
protected static final String DEFAULT_VALUE = "defaultValue";
|
||||
protected static final String TIMEOUT = "timeout";
|
||||
protected static final String TEMPLATE = "template";
|
||||
protected static final String LANGUAGE = "language";
|
||||
protected static final String VALUE_TYPE = "valueType";
|
||||
protected static final String NULLABLE = "nullable";
|
||||
protected Attribute() {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
|
||||
|
||||
/**
|
||||
* Defines a query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQuery extends AbstractTPQueryNode {
|
||||
|
||||
private List<TPQStatement> queryParts;
|
||||
private final List<TPQueryParameter> queryParameters;
|
||||
|
||||
public TPQuery() {
|
||||
queryParts = new ArrayList<>();
|
||||
queryParameters = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TPQuery(String name) {
|
||||
this();
|
||||
setName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryParts
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_PART,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlJavaTypeAdapter(TPQStatementMarshallerAdapter.class)
|
||||
public List<TPQStatement> getQueryParts() {
|
||||
return queryParts;
|
||||
}
|
||||
|
||||
public void setQueryParts(List<TPQStatement> parts) {
|
||||
Objects.requireNonNull(parts,"Can't set null list");
|
||||
queryParts = parts;
|
||||
}
|
||||
|
||||
public void addQueryPart(TPQStatement queryPart) {
|
||||
Objects.requireNonNull(queryPart,"Can't add null");
|
||||
queryParts.add(queryPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryParameters
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_PARAMETER)
|
||||
public List<TPQueryParameter> getQueryParameters() {
|
||||
return queryParameters;
|
||||
}
|
||||
|
||||
public void addQueryParameter(TPQueryParameter queryParameter) {
|
||||
Objects.requireNonNull(queryParameter,"Can't add null");
|
||||
Objects.requireNonNull(queryParameter.getName(),"TQueryParameter.getName() is null.");
|
||||
queryParameters.add(queryParameter);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
|
||||
/**
|
||||
* Query hint are optional hint.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQueryHint {
|
||||
|
||||
private String name = null;
|
||||
private String value = null;
|
||||
|
||||
public TPQueryHint() {
|
||||
}
|
||||
|
||||
public TPQueryHint(String name) {
|
||||
this();
|
||||
setName(name);
|
||||
}
|
||||
|
||||
public TPQueryHint(String name,String value) {
|
||||
this(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
|
||||
/**
|
||||
* Defines the query parameter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQueryParameter {
|
||||
|
||||
private String name = null;
|
||||
private String defaultValue = null;
|
||||
private String type = null;
|
||||
private String valueType = null;
|
||||
private Boolean nullable = null;
|
||||
|
||||
public TPQueryParameter() {
|
||||
}
|
||||
|
||||
public TPQueryParameter(String name,String valueType) {
|
||||
setName(name);
|
||||
setValueType(valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultValue
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.DEFAULT_VALUE)
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultValue the defaultValue to set
|
||||
*/
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TYPE)
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE_TYPE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueType the valueType to set
|
||||
*/
|
||||
public void setValueType(String valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nullable
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NULLABLE)
|
||||
public Boolean getNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nullable the nullable to set
|
||||
*/
|
||||
public void setNullable(Boolean nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
|
||||
/**
|
||||
* Query sets is an tree node which holds more query sets and queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
@XmlRootElement(name=Element.QUERY_SET)
|
||||
public class TPQuerySet extends AbstractTPQueryNode {
|
||||
|
||||
private final List<TPQuerySet> querySets;
|
||||
private final List<TPQuery> queries;
|
||||
|
||||
public TPQuerySet() {
|
||||
queries = new ArrayList<>();
|
||||
querySets = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TPQuerySet(String name) {
|
||||
this();
|
||||
setName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queries
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY)
|
||||
public List<TPQuery> getQueries() {
|
||||
return queries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to add
|
||||
*/
|
||||
public void addQuery(TPQuery query) {
|
||||
queries.add(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the querySets
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_SET)
|
||||
public List<TPQuerySet> getQuerySets() {
|
||||
return querySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param querySet the querySet to add
|
||||
*/
|
||||
public void addQuerySet(TPQuerySet querySet) {
|
||||
querySets.add(querySet);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
/**
|
||||
* Jaxb marshaller of the query sets.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
|
||||
|
||||
private final JAXBContext querySetContext;
|
||||
|
||||
public TPQuerySetXMLMarshaller() throws JAXBException {
|
||||
this(JAXBContext.newInstance(TPQuerySet.class));
|
||||
}
|
||||
|
||||
public TPQuerySetXMLMarshaller(JAXBContext querySetContext) {
|
||||
Objects.requireNonNull(querySetContext,"querySetContext is null.");
|
||||
this.querySetContext = querySetContext;
|
||||
}
|
||||
|
||||
public void marshal(TPQuerySet querySet, OutputStream output) throws JAXBException {
|
||||
Objects.requireNonNull(querySet,"querySet is null.");
|
||||
Objects.requireNonNull(output,"OutputStream is null.");
|
||||
|
||||
Marshaller marshaller = querySetContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING);
|
||||
marshaller.marshal(querySet, output);
|
||||
}
|
||||
|
||||
public TPQuerySet unmarshal(InputStream input) throws JAXBException {
|
||||
Objects.requireNonNull(input,"InputStream is null.");
|
||||
|
||||
Unmarshaller unmarshaller = querySetContext.createUnmarshaller();
|
||||
return (TPQuerySet) unmarshaller.unmarshal(input);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* The query data model.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Templated Prepared Query manager and factory.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Abstract implementation of a statement.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 21, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatement implements TPQStatement {
|
||||
|
||||
private final String statementPart;
|
||||
private TPQStatementContext context;
|
||||
private TPQuery query;
|
||||
|
||||
public AbstractTPQStatement(String statementPart) {
|
||||
Validate.notNull(statementPart,"statementPart is null");
|
||||
this.statementPart=statementPart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void prepareInit(TPQStatementContext context, TPQuery query) {
|
||||
this.context=context;
|
||||
this.query=query;
|
||||
prepareInit();
|
||||
}
|
||||
|
||||
protected void prepareInit() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getStatementPart() {
|
||||
return statementPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context
|
||||
*/
|
||||
public final TPQStatementContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public final TPQuery getQuery() {
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the statement writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 20, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementWriter implements TPQStatementWriter {
|
||||
|
||||
protected static final String PARAMETER_PREPARED = "?";
|
||||
protected static final String PARAMETER_NEXT = ",";
|
||||
private static final int OUTPUT_START_SIZE = 384;
|
||||
|
||||
protected boolean flagValueBased = false;
|
||||
protected final StringBuilder output;
|
||||
protected final List<TPQueryStoreStatementMapper> queryParameterMapping;
|
||||
protected final Map<String,Object> queryParameterData;
|
||||
|
||||
public AbstractTPQStatementWriter(Map<String,Object> queryParameterData) {
|
||||
Validate.notNull(queryParameterData);
|
||||
this.queryParameterData=queryParameterData;
|
||||
this.output = new StringBuilder(OUTPUT_START_SIZE);
|
||||
this.queryParameterMapping = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeQuery(TPQuery query) {
|
||||
Validate.notNull(query,"Can' write null query ");
|
||||
query.getQueryParts().forEach(part -> part.prepare(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(TPQueryParameter parameter) {
|
||||
return queryParameterData.get(parameter.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueMappedWriter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryText(String text) {
|
||||
Validate.notNull(text, "Can't add null text.");
|
||||
output.append(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryParameter(TPQueryStoreStatementMapper mapper) {
|
||||
Validate.notNull(mapper);
|
||||
queryParameterMapping.add(mapper);
|
||||
output.append(PARAMETER_PREPARED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryParameterSeperator() {
|
||||
output.append(PARAMETER_NEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TPQueryStoreStatementMapper> getQueryParameterMapping() {
|
||||
return queryParameterMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText() {
|
||||
return output.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Defines an query statement part.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public interface TPQStatement {
|
||||
|
||||
/**
|
||||
* Init the query.
|
||||
* @param context The prepare context.
|
||||
* @param query The query to prepare.
|
||||
*/
|
||||
void prepareInit(TPQStatementContext context,TPQuery query);
|
||||
|
||||
/**
|
||||
* Writers all prepares statement parts to the query writer.
|
||||
* @param queryWriter The query writer to build the prepared query with.
|
||||
*/
|
||||
void prepare(TPQStatementWriter queryWriter);
|
||||
|
||||
/**
|
||||
* @return the value of the statement part.
|
||||
*/
|
||||
String getStatementPart();
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
|
||||
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
|
||||
/**
|
||||
* Gives statement parts the needed references to data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 14, 2015
|
||||
*/
|
||||
public interface TPQStatementContext {
|
||||
|
||||
/**
|
||||
* Get a query by name.
|
||||
* @param name The name of the query.
|
||||
* @return The query.
|
||||
*/
|
||||
TPQuery getQuery(String name);
|
||||
|
||||
/**
|
||||
* Returns a statement type based on the parameter.
|
||||
* @param param The parameter to get the statement parameter type for.
|
||||
* @return The statement parameter.
|
||||
*/
|
||||
TPQStatementParameter getParameterType(TPQueryParameter param);
|
||||
|
||||
/**
|
||||
* Returns a statement language based on the query.
|
||||
* @param query The query to get the statement language for.
|
||||
* @return The statement language.
|
||||
*/
|
||||
TPQStatementLanguage getStatementLanguage(TPQuery query);
|
||||
|
||||
/**
|
||||
* Gets a query parameter by name.
|
||||
* note: may move back to TPQuery
|
||||
*
|
||||
* @param query The query having the parameter.
|
||||
* @param name The name of the paramter.
|
||||
* @return The query parameter.
|
||||
*/
|
||||
TPQueryParameter getQueryParameterByName(TPQuery query,String name);
|
||||
|
||||
/**
|
||||
* Retuns an map to store context in while writing an prepared statement.
|
||||
* @return The context map.
|
||||
*/
|
||||
Map<String,Object> getContextState();
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Prints and parse the different statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public class TPQStatementMarshaller {
|
||||
|
||||
protected static final String DELIMITER = "$$";
|
||||
protected static final String INCLUDE_PREFIX = "inc:";
|
||||
private static final int DEFAULT_PRINT_SIZE = 384;
|
||||
|
||||
public String marshal(List<TPQStatement> parts) {
|
||||
Objects.requireNonNull(parts,"Can't print null list.");
|
||||
StringBuilder buf = new StringBuilder(DEFAULT_PRINT_SIZE);
|
||||
for (TPQStatement part : parts) {
|
||||
if (part instanceof TPQStatementPartParameter) {
|
||||
buf.append(DELIMITER);
|
||||
buf.append(part.getStatementPart());
|
||||
buf.append(DELIMITER);
|
||||
} else if (part instanceof TPQStatementPartInclude) {
|
||||
buf.append(DELIMITER);
|
||||
buf.append(INCLUDE_PREFIX);
|
||||
buf.append(part.getStatementPart());
|
||||
buf.append(DELIMITER);
|
||||
} else {
|
||||
buf.append(part.getStatementPart());
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public List<TPQStatement> unmarshal(String statementTemplateText) {
|
||||
Objects.requireNonNull(statementTemplateText,"Can't parse null text.");
|
||||
List<TPQStatement> result = new ArrayList<>();
|
||||
parseLoop(result,statementTemplateText);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void appendText(List<TPQStatement> result,String text) {
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
result.add(new TPQStatementPartText(text));
|
||||
}
|
||||
|
||||
private void parseLoop(List<TPQStatement> result,String value) {
|
||||
|
||||
// search for start delimiter
|
||||
int searchIndex = value.indexOf(DELIMITER);
|
||||
if (searchIndex < 0) {
|
||||
appendText(result,value);
|
||||
return; // only text
|
||||
}
|
||||
|
||||
// search for end delimiter
|
||||
int searchIndexEnd = value.indexOf(DELIMITER, searchIndex + DELIMITER.length());
|
||||
Validate.isTrue(searchIndexEnd > 0, "Can't parse token without end delimiter: %s",DELIMITER);
|
||||
|
||||
// Split the template
|
||||
String pre = value.substring(0,searchIndex);
|
||||
String token = value.substring(searchIndex + DELIMITER.length(),searchIndexEnd);
|
||||
String next = value.substring(searchIndexEnd + DELIMITER.length());
|
||||
|
||||
// Handle split results.
|
||||
appendText(result,pre);
|
||||
parseToken(result,token);
|
||||
parseLoop(result,next);
|
||||
}
|
||||
|
||||
private void parseToken(List<TPQStatement> result,String token) {
|
||||
Validate.notEmpty(token,"Can't parse empty token.");
|
||||
if (token.startsWith(INCLUDE_PREFIX)) {
|
||||
result.add(new TPQStatementPartInclude(token.substring(INCLUDE_PREFIX.length())));
|
||||
} else {
|
||||
result.add(new TPQStatementPartParameter(token));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* jaxb adapter to marshall the statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 15, 2015
|
||||
*/
|
||||
public class TPQStatementMarshallerAdapter extends XmlAdapter<String, List<TPQStatement>> {
|
||||
|
||||
protected final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
|
||||
|
||||
@Override
|
||||
public String marshal(List<TPQStatement> parts) throws Exception {
|
||||
return statementMarshaller.marshal(ObjectUtils.defaultIfNull(parts, new ArrayList<TPQStatement>()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TPQStatement> unmarshal(String value) throws Exception {
|
||||
return statementMarshaller.unmarshal(StringUtils.defaultString(value));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Handles query include statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
public class TPQStatementPartInclude extends AbstractTPQStatement {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStatementPartInclude.class);
|
||||
private TPQuery includeQuery;
|
||||
|
||||
/**
|
||||
* Creates an query include part.
|
||||
* @param value The part value.
|
||||
*/
|
||||
public TPQStatementPartInclude(String value) {
|
||||
super(value);
|
||||
LOG.trace("<init> include part created {}",value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareInit() {
|
||||
String key = getQuery().getName();
|
||||
LOG.trace("init add loop lock: {}",key);
|
||||
Validate.isTrue(Objects.isNull(getContext().getContextState().get(key)), "Duplicate treeLock key: %s", key);
|
||||
getContext().getContextState().put(key,getClass().getName());
|
||||
|
||||
LOG.trace("init lookup query: {}",getStatementPart());
|
||||
includeQuery = getContext().getQuery(getStatementPart());
|
||||
Validate.isTrue(includeQuery.getTemplate(), "query: %s is not a template.", includeQuery.getName());
|
||||
|
||||
LOG.trace("init prepare included query."); // so all parameters are copies down the tree.
|
||||
includeQuery.getQueryParts().forEach(part -> part.prepareInit(getContext(), includeQuery));
|
||||
|
||||
LOG.debug("init copy parameters: {} to: {}",includeQuery.getQueryParameters().size(),getQuery().getQueryParameters().size());
|
||||
getQuery().getQueryParameters().addAll(includeQuery.getQueryParameters());
|
||||
|
||||
LOG.trace("init remove loop lock: {}",key);
|
||||
getContext().getContextState().remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
queryWriter.writeQuery(includeQuery);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Handles parameter statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
public class TPQStatementPartParameter extends AbstractTPQStatement {
|
||||
|
||||
private TPQueryParameter parameter;
|
||||
|
||||
/**
|
||||
* Creates parameter statement part.
|
||||
* @param value The part value.
|
||||
*/
|
||||
public TPQStatementPartParameter(String value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareInit() {
|
||||
parameter = getContext().getQueryParameterByName(getQuery(),getStatementPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
getContext().getParameterType(parameter).prepareParameter(queryWriter, parameter, queryWriter.getParameterValue(parameter));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
/**
|
||||
* Handles query text statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 15, 2015
|
||||
*/
|
||||
public class TPQStatementPartText extends AbstractTPQStatement {
|
||||
|
||||
public TPQStatementPartText(String statementPart) {
|
||||
super(statementPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
queryWriter.appendQueryText(getStatementPart());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Writes the statement query as text, and holds the parameter mapping for it.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public interface TPQStatementWriter {
|
||||
|
||||
/**
|
||||
* Write all query parts.
|
||||
* @param query The query to write.
|
||||
*/
|
||||
void writeQuery(TPQuery query);
|
||||
|
||||
|
||||
Object getParameterValue(TPQueryParameter parameter);
|
||||
|
||||
/**
|
||||
* Defines if this writer supports the statement value mapper.
|
||||
* @return false if the mapper are used directly by this writer.
|
||||
*/
|
||||
boolean isValueMappedWriter();
|
||||
|
||||
/**
|
||||
* Append query text to the statement.
|
||||
* @param text The query part text to add.
|
||||
*/
|
||||
void appendQueryText(String text);
|
||||
|
||||
void appendQueryParameter(TPQueryStoreStatementMapper valueMapper);
|
||||
|
||||
void appendQueryParameterSeperator();
|
||||
|
||||
/**
|
||||
* @return The parameter mapping for the writen query.
|
||||
*/
|
||||
List<TPQueryStoreStatementMapper> getQueryParameterMapping();
|
||||
|
||||
/**
|
||||
* The statement query text.
|
||||
* @return The statement query text.
|
||||
*/
|
||||
String getQueryText();
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.statement.AbstractTPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* AbstractTQueryLanguageType holds the languageType key value and implements some default methods.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementLanguage implements TPQStatementLanguage {
|
||||
|
||||
private final String languageType;
|
||||
|
||||
/**
|
||||
* Creates the abstract language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public AbstractTPQStatementLanguage(String languageType) {
|
||||
Validate.notNull(languageType, "languageType is null.");
|
||||
this.languageType=languageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getLanguageType() {
|
||||
return languageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementWriter createQueryWriter(Map<String,Object> parameterData) {
|
||||
return new TQueryStatementWriterPrepared(parameterData);
|
||||
}
|
||||
|
||||
private class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter {
|
||||
private TQueryStatementWriterPrepared(Map<String, Object> queryParameterData) {
|
||||
super(queryParameterData);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Allows for different language writers to define how the query is writen as statement text.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public interface TPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* The language type.
|
||||
* @return The type of language.
|
||||
*/
|
||||
String getLanguageType();
|
||||
|
||||
/**
|
||||
* Creates a statement writer for this language.
|
||||
* @param parameterData The request parameter data.
|
||||
* @return The writer for this data.
|
||||
*/
|
||||
TPQStatementWriter createQueryWriter(Map<String,Object> parameterData);
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.statement.AbstractTPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Writes parameters as jpa ordered query syntax.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public class TPQStatementLanguageHql extends AbstractTPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* Creates the hql language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public TPQStatementLanguageHql(String languageType) {
|
||||
super(languageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementWriter createQueryWriter(Map<String,Object> parameterData) {
|
||||
return new TQueryStatementWriterPreparedHql(parameterData);
|
||||
}
|
||||
|
||||
private class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter {
|
||||
private TQueryStatementWriterPreparedHql(Map<String, Object> queryParameterData) {
|
||||
super(queryParameterData);
|
||||
}
|
||||
@Override
|
||||
public void appendQueryParameter(TPQueryStoreStatementMapper valueMapper) {
|
||||
super.appendQueryParameter(valueMapper);
|
||||
output.append(this.queryParameterMapping.size());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
/**
|
||||
* Writes parameters as jdbc prepared statement syntax.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public class TPQStatementLanguageSql extends AbstractTPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* Creates the sql language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public TPQStatementLanguageSql(String languageType) {
|
||||
super(languageType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Writer support for different parameterized query languages.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Query statements are written from parts: TEXT,PARAMETER,INCLUDE
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* AbstractTQueryTemplateType holds the templateType key value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementParameter implements TPQStatementParameter {
|
||||
|
||||
private final String templateType;
|
||||
|
||||
/**
|
||||
* Creates the abstract template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public AbstractTPQStatementParameter(String templateType) {
|
||||
Validate.notNull(templateType, "templateType is null.");
|
||||
this.templateType=templateType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getParameterType() {
|
||||
return templateType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object paramValue) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* writes,validate and creates cacheKey for parameter type.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 16, 2015
|
||||
*/
|
||||
public interface TPQStatementParameter {
|
||||
|
||||
/**
|
||||
* @return The parameter type to handle.
|
||||
*/
|
||||
String getParameterType();
|
||||
|
||||
/**
|
||||
* Validates the parameter value.
|
||||
* @param param The query parameter.
|
||||
* @param valueType The resolved query parameter type.
|
||||
* @param value The parameter value.
|
||||
*/
|
||||
void prepareValidate(TPQueryParameter param, Class<?> valueType, Object value);
|
||||
|
||||
/**
|
||||
* Appends cache key for this parameter if needed.
|
||||
* @param keyBuf The cacheKey buffer to append to.
|
||||
* @param param The query parameter.
|
||||
* @param value The query parameter value.
|
||||
* @return returns true if parameter is cachable, false if not.
|
||||
*/
|
||||
boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value);
|
||||
|
||||
/**
|
||||
* Appends the query parameter to the writer.
|
||||
* @param queryWriter The statement writer.
|
||||
* @param param The query parameter.
|
||||
* @param value The parameter value.
|
||||
*/
|
||||
void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value);
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Appends the query parameter list values to the writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterList extends AbstractTPQStatementParameter {
|
||||
|
||||
/**
|
||||
* Creates the parameter list template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public TPQStatementParameterList(String templateType) {
|
||||
super(templateType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object value) {
|
||||
Validate.notNull(value, "List parameter requires non null value.");
|
||||
Validate.isInstanceOf(List.class, value, "List parameter requires java.util.List type not: %s",value.getClass().getName());
|
||||
List<?> valueList = (List<?>)value;
|
||||
Validate.isTrue(!valueList.isEmpty(), "List parameter requires none empty list.");
|
||||
Object checkFirst = valueList.get(0);
|
||||
Validate.isInstanceOf(valueType, checkFirst , "List parameter value with name: "+param.getName()+" has wong type: "+param.getValueType()+" but is: "+checkFirst.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
keyBuf.append(((List<?>)value).size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
writeList(queryWriter, param.getName(), (List<Object>)value);
|
||||
}
|
||||
|
||||
private void writeList(TPQStatementWriter queryWriter,String parameterName, List<Object> valueList) {
|
||||
for (int i=0;i<valueList.size();i++) {
|
||||
queryWriter.appendQueryParameter(new TPQStatementParameterListMapper(parameterName, i));
|
||||
if (i<valueList.size()-1) {
|
||||
queryWriter.appendQueryParameterSeperator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Maps indexed list value from parameter value as statement value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQStatementParameterListMapper implements TPQueryStoreStatementMapper {
|
||||
|
||||
private String parameterName;
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* Creates an list mapping.
|
||||
* @param parameterName The parameter name containing the List.
|
||||
* @param index The index of the list value.
|
||||
*/
|
||||
public TPQStatementParameterListMapper(String parameterName,int index) {
|
||||
this.index=index;
|
||||
this.parameterName=parameterName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(Map<String, Object> parameters) {
|
||||
List<?> listData = (List<?>)parameters.get(parameterName);
|
||||
return listData.get(index);
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(parameterName);
|
||||
out.writeInt(index);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
parameterName = in.readUTF();
|
||||
index = in.readInt();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Prints the parameter value as text in the prepared statement.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterRaw extends AbstractTPQStatementParameter {
|
||||
|
||||
private final String printNull;
|
||||
|
||||
/**
|
||||
* Creates the raw template type.
|
||||
* @param templateType The templateType key.
|
||||
* @param printNull The null string to print if the value is null.
|
||||
*/
|
||||
public TPQStatementParameterRaw(String templateType,String printNull) {
|
||||
super(templateType);
|
||||
Validate.notNull(printNull, "printNull is null");
|
||||
this.printNull=printNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
queryWriter.appendQueryText(Objects.toString(value, printNull));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Appends the query parameter to the writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterValue extends AbstractTPQStatementParameter {
|
||||
|
||||
/**
|
||||
* Creates the parameter template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public TPQStatementParameterValue(String templateType) {
|
||||
super(templateType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object paramValue) {
|
||||
if (paramValue == null) {
|
||||
return;
|
||||
}
|
||||
Validate.isInstanceOf(valueType, paramValue, "Parameter with name: "+param.getName()+" has wong type: "+param.getValueType()+" but is: "+paramValue.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
queryWriter.appendQueryParameter(new TPQStatementParameterValueMapper(param.getName()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Maps a parameter value as statement value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQStatementParameterValueMapper implements TPQueryStoreStatementMapper {
|
||||
|
||||
private String parameterName;
|
||||
|
||||
/**
|
||||
* Creates a parameter value mapping.
|
||||
* @param parameterName The parameter name to map.
|
||||
*/
|
||||
public TPQStatementParameterValueMapper(String parameterName) {
|
||||
this.parameterName=parameterName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(Map<String, Object> parameters) {
|
||||
return parameters.get(parameterName);
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(parameterName);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
parameterName = in.readUTF();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* Statement parameter types: VALUE,LIST,RAW
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Gives access to the parameter meta data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public interface TPQueryParameterMetaData {
|
||||
|
||||
/**
|
||||
* @return The name of the parameter.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return The valueType of the parameter.
|
||||
*/
|
||||
Class<?> getValueType();
|
||||
|
||||
/**
|
||||
* @return True if the parameter is allowed null.
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
/**
|
||||
* @return True is the parameter is required.
|
||||
*/
|
||||
boolean isRequired();
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TPQueryStore validates and configures the config from the query store config.
|
||||
* And provides access to the prepared queries and parameters.
|
||||
* s
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 14, 2015
|
||||
*/
|
||||
public interface TPQueryStore {
|
||||
|
||||
/**
|
||||
* @return Returns sorted list of all queries able to execute.
|
||||
*/
|
||||
List<String> getQueryNames();
|
||||
|
||||
/**
|
||||
* Returns the parameter meta data of an query.
|
||||
* @param queryName The query to get the parameter meta data for.
|
||||
* @return The map with the parameter meta data.
|
||||
*/
|
||||
Map<String,TPQueryParameterMetaData> getParameterMetaData(String queryName);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
/**
|
||||
* Wrapped the optional script engine interfaces into a single interface.
|
||||
*
|
||||
* This can be used with an proxy instance so there are no casts needed in code.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 4, 2015
|
||||
*/
|
||||
public interface TPQueryStoreScriptEngine extends ScriptEngine,Compilable,Invocable {
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Wrappes script exceptions to runtime exception.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 7, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQueryStoreScriptEngineException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* @param cause The cause of this exception.
|
||||
*/
|
||||
public TPQueryStoreScriptEngineException(Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message The message of this exception.
|
||||
* @param cause The cause of this exception.
|
||||
*/
|
||||
public TPQueryStoreScriptEngineException(String message,Exception cause) {
|
||||
super(message,cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Holds the written statements and meta info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQueryStoreStatement implements Serializable {
|
||||
|
||||
private String name;
|
||||
private String statement;
|
||||
private String language;
|
||||
private Integer timeout;
|
||||
private Map<String,String> properties;
|
||||
private List<TPQueryStoreStatementMapper> valueMapping;
|
||||
|
||||
public TPQueryStoreStatement(String name,String statement,String language,Integer timeout,Map<String,String> properties,List<TPQueryStoreStatementMapper> valueMapping) {
|
||||
Objects.requireNonNull(name,"name is null");
|
||||
Objects.requireNonNull(statement,"statement is null");
|
||||
Objects.requireNonNull(language,"language is null");
|
||||
Objects.requireNonNull(properties,"properties is null");
|
||||
this.name=name;
|
||||
this.statement=statement;
|
||||
this.timeout=timeout; // null is no timeout
|
||||
this.language=language;
|
||||
this.properties=Collections.unmodifiableMap(properties);
|
||||
this.valueMapping=Collections.unmodifiableList(valueMapping);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getStatement() {
|
||||
return statement;
|
||||
}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public Map<String,String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public List<TPQueryStoreStatementMapper> getValueMapping() {
|
||||
return valueMapping;
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(name);
|
||||
out.writeUTF(statement);
|
||||
out.writeUTF(language);
|
||||
out.writeObject(timeout);
|
||||
out.writeObject(new HashMap<>(properties));
|
||||
out.writeObject(new ArrayList<>(valueMapping));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
name = in.readUTF();
|
||||
statement = in.readUTF();
|
||||
language = in.readUTF();
|
||||
timeout = (Integer)in.readObject();
|
||||
properties = Collections.unmodifiableMap((Map<String, String>) in.readObject());
|
||||
valueMapping = Collections.unmodifiableList((List<TPQueryStoreStatementMapper>) in.readObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Stores and retreives statements from a cache.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
public interface TPQueryStoreStatementCache {
|
||||
|
||||
/**
|
||||
* Store statement in cache.
|
||||
* @param key The key to store the statement under.
|
||||
* @param value The statement store in the cache.
|
||||
*/
|
||||
void put(String key,TPQueryStoreStatement value);
|
||||
|
||||
/**
|
||||
* Retreives an statement from the cache.
|
||||
* @param key The key of the statement to retreive.
|
||||
* @return The statement or null.
|
||||
*/
|
||||
TPQueryStoreStatement get(String key);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Maps a single the named parameter to an ordered value.
|
||||
*
|
||||
* note: Don't inner-class this interface as it is Serializable.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public interface TPQueryStoreStatementMapper extends Serializable {
|
||||
|
||||
/**
|
||||
* map the value from parameters.
|
||||
* @param parameters The parameter map which contains our value.
|
||||
* @return The value we need to have.
|
||||
*/
|
||||
Object getParameterValue(Map<String,Object> parameters);
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public abstract class AbstractTPQExecutor<C,S> {
|
||||
|
||||
private static final int PARAMETER_INDEX_START = 1;
|
||||
private final TPQExecutorContext context;
|
||||
private final Map<String,BiFunction<C,String,S>> backendTypes;
|
||||
|
||||
public AbstractTPQExecutor(TPQExecutorContext context) {
|
||||
Objects.requireNonNull(context,"Can't execute with null context.");
|
||||
this.context = context;
|
||||
backendTypes = new HashMap<>();
|
||||
}
|
||||
|
||||
protected void registrateStatementCreator(String language,BiFunction<C,String,S> statementCreator) {
|
||||
Objects.requireNonNull(language,"Can't registrate null language");
|
||||
Objects.requireNonNull(statementCreator,"Can't registrate null StatementCreator");
|
||||
backendTypes.put(language, statementCreator);
|
||||
}
|
||||
|
||||
protected final TPQExecutorContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public S createPreparedStatement(C connection,String queryName,Map<String,Object> parameters) {
|
||||
return prepare(connection,getContext().prepareQuery(queryName,parameters));
|
||||
}
|
||||
|
||||
public int executeUpdate(C connection,String queryName) {
|
||||
return executeUpdate(connection, queryName, null);
|
||||
}
|
||||
|
||||
public int executeUpdate(C connection,String queryName,Map<String,Object> parameters) {
|
||||
return executeUpdate(createPreparedStatement(connection, queryName, parameters));
|
||||
}
|
||||
|
||||
protected abstract int executeUpdate(S statement);
|
||||
|
||||
protected abstract void prepareParameterValue(S statement,int index,Object value);
|
||||
|
||||
protected void prepareParameters(S statement,TPQExecutorStatement query) {
|
||||
List<Object> orderedParameters = query.getParameters();
|
||||
int parameterIndex=PARAMETER_INDEX_START;
|
||||
for ( int i=0;i<orderedParameters.size();i++ ) {
|
||||
Object para = orderedParameters.get(i);
|
||||
prepareParameterValue(statement, parameterIndex, para);
|
||||
parameterIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void prepareTimeout(S statement,Integer timeout);
|
||||
|
||||
protected S prepare(C connection,TPQExecutorStatement query) {
|
||||
BiFunction<C,String,S> statementCreator = backendTypes.get(query.getLanguage());
|
||||
Objects.requireNonNull(statementCreator,"Unsupported language type: "+query.getLanguage());
|
||||
S result = statementCreator.apply(connection, query.getStatement());
|
||||
prepareParameters(result, query);
|
||||
Integer timeout = query.getTimeout();
|
||||
if (timeout != null) {
|
||||
prepareTimeout(result, timeout);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TQueryExecutorContext creates and prepared statement for the executor.
|
||||
*
|
||||
* later: add logQueryTime(); etc
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 19, 2015
|
||||
*/
|
||||
public interface TPQExecutorContext {
|
||||
|
||||
/**
|
||||
* Creates an TQueryPrepared with statement for the queryName and parameters.
|
||||
* @param queryName The queryName to prepare.
|
||||
* @param parameters The parameters for statement.
|
||||
* @return The TQueryPrepared.
|
||||
*/
|
||||
TPQExecutorStatement prepareQuery(String queryName,Map<String,Object> parameters);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public interface TPQExecutorStatement {
|
||||
|
||||
String getName();
|
||||
|
||||
String getStatement();
|
||||
|
||||
List<Object> getParameters();
|
||||
|
||||
Integer getTimeout();
|
||||
|
||||
String getLanguage();
|
||||
|
||||
Map<String,String> getProperties();
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
/**
|
||||
* The objects which are for the executor.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementContext;
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngineException;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Holds the query store and the executor context.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQStoreManager implements TPQManager {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStoreManager.class);
|
||||
private final TPQueryStore queryStore;
|
||||
private final TPQExecutorContext executorContext;
|
||||
|
||||
/**
|
||||
* Creates an TPQStoreManager with the config.
|
||||
* @param config The config to create this manager for.
|
||||
*/
|
||||
public TPQStoreManager(TPQConfig config) {
|
||||
this(new TPQStoreManagerConfig(config));
|
||||
}
|
||||
|
||||
private TPQStoreManager(TPQStoreManagerConfig config) {
|
||||
Objects.requireNonNull(config);
|
||||
this.queryStore = new TPQStoreManagerEntryView(config);
|
||||
TPQStatementContext statementContext = new TPQStoreManagerStatementContext(config);
|
||||
this.executorContext = new TPQStoreManagerExecutorContext(config,statementContext);
|
||||
|
||||
initStore(config,statementContext);
|
||||
}
|
||||
|
||||
protected void initStore(TPQStoreManagerConfig config,TPQStatementContext statementContext) {
|
||||
|
||||
LOG.debug("init value scripts: {}",config.getParameterValueScripts().size());
|
||||
config.getParameterValueScripts().forEach(scriptBody -> {
|
||||
LOG.trace("init value script: \n{}",scriptBody);
|
||||
try {
|
||||
config.getParameterValueEngine().eval(scriptBody);
|
||||
} catch (Exception e) {
|
||||
throw new TPQueryStoreScriptEngineException(e);
|
||||
}
|
||||
});
|
||||
|
||||
LOG.debug("init query entries: {}",config.getEntries().size());
|
||||
for (String qName:config.getEntries().keySet()) {
|
||||
TPQStoreManagerEntry entry = config.getEntries().get(qName);
|
||||
if (entry.getQuery().getTemplate()) {
|
||||
continue; // are done by include
|
||||
}
|
||||
LOG.trace("init query entry: {}",qName);
|
||||
|
||||
entry.getQuery().getQueryParts().forEach(part -> part.prepareInit(statementContext, entry.getQuery()));
|
||||
entry.initEntry();
|
||||
entry.getQuery().getQueryParameters().forEach(param -> {
|
||||
if (param.getDefaultValue()==null) {
|
||||
return;
|
||||
}
|
||||
String scriptBody = config.getParameterValueScripter().convertDefaultValueToScript(param);
|
||||
|
||||
LOG.trace("compiled parameter: {} default: {} into script: \n{}",param.getName(),param.getDefaultValue() ,scriptBody);
|
||||
try {
|
||||
CompiledScript script = config.getParameterValueEngine().compile(scriptBody);
|
||||
entry.getParameterDefaultCompiledScripts().put(param.getName(), script);
|
||||
} catch (Exception e) {
|
||||
throw new TPQueryStoreScriptEngineException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
LOG.info("StoreManager created with: {} queries.", config.getEntries().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQueryStore getQueryStore() {
|
||||
return queryStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQExecutorContext getQueryExecutorContext() {
|
||||
return executorContext;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.forwardfire.tpquery.config.AbstractTPQConfig;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.model.AbstractTPQueryNode;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Hold the config for the manager.
|
||||
*
|
||||
* This copies all collections to read only once, then does some null checking.
|
||||
* And most importandt build all the entry which hold the queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerConfig extends AbstractTPQConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStoreManagerConfig.class);
|
||||
private final Map<String,TPQStoreManagerEntry> entries;
|
||||
private final List<String> queryNames;
|
||||
|
||||
/**
|
||||
* Creates this manager config.
|
||||
* @param config The config to create this config for.
|
||||
*/
|
||||
public TPQStoreManagerConfig(TPQConfig config) {
|
||||
super(
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getQuerySets())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getStatementParameters())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getStatementLanguages())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getValueTypeAliases())),
|
||||
Collections.unmodifiableList(new ArrayList<>(config.getConfigValidators())),
|
||||
Collections.unmodifiableList(new ArrayList<>(config.getParameterValueScripts()))
|
||||
);
|
||||
treePathSeperator = config.getTreePathSeperator();
|
||||
defaultParameterType = config.getDefaultParameterType();
|
||||
defaultParameterNullable = config.getDefaultParameterNullable();
|
||||
statementCache = config.getStatementCache();
|
||||
parameterValueScripter = config.getParameterValueScripter();
|
||||
parameterValueEngine = config.getParameterValueEngine();
|
||||
LOG.trace("init<> created cloned config");
|
||||
|
||||
LOG.trace("init<> null validation");
|
||||
validateMap(getQuerySets(), "querySets");
|
||||
validateMap(getStatementParameters(), "statementParameters");
|
||||
validateMap(getStatementLanguages(), "statementLanguages");
|
||||
validateMap(getValueTypeAliases(), "valueTypeAliases");
|
||||
Validate.notNull(getTreePathSeperator(), "null treePathSeperator");
|
||||
Validate.notNull(getDefaultParameterType(), "null defaultParameterType");
|
||||
Validate.notNull(getDefaultParameterNullable(),"null defaultParameterNullable");
|
||||
Validate.notNull(getStatementCache(), "null statementCache");
|
||||
Validate.notNull(getParameterValueScripter(), "null parameterValueScripter");
|
||||
Validate.notNull(getParameterValueEngine(), "null parameterValueEngine");
|
||||
|
||||
LOG.trace("init<> build internal data");
|
||||
entries = Collections.unmodifiableMap(createEntries(config));
|
||||
queryNames = Collections.unmodifiableList(entries.keySet().stream().sorted().collect(Collectors.toList()));
|
||||
|
||||
LOG.debug("init<> managed config created with {} queries.",entries.size());
|
||||
}
|
||||
|
||||
private <K,V> void validateMap(Map<K,V> m,String name) {
|
||||
Validate.notNull(m,"Map %m may not be null",name);
|
||||
m.forEach((key,value) -> {
|
||||
Validate.notNull(key,"key may not be null in %s",name);
|
||||
Validate.notNull(value,"value may not be null in %s",name);
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String,TPQStoreManagerEntry> createEntries(TPQConfig config) {
|
||||
Map<String,TPQStoreManagerEntry> result = new HashMap<>();
|
||||
config.getQuerySets().forEach((String key,TPQuerySet qs) -> walkQuerySet(result,qs.getName(),qs,key) );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entries
|
||||
*/
|
||||
public Map<String, TPQStoreManagerEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryNames
|
||||
*/
|
||||
public List<String> getQueryNames() {
|
||||
return queryNames;
|
||||
}
|
||||
|
||||
private void walkQuerySet(Map<String,TPQStoreManagerEntry> result,String name,TPQuerySet qs,String systemId) {
|
||||
Validate.notBlank(qs.getName(),"query set name may not be blank");
|
||||
qs.getQueryHints().forEach(hint -> {
|
||||
Validate.notNull(hint.getName(), "query hint name not be null.");
|
||||
Validate.notNull(hint.getValue(), "query hint value not be null of: "+hint.getName());
|
||||
});
|
||||
|
||||
// note: only imported on root sets as rest is handled by copyToChild because calling here again.
|
||||
if (qs.getTemplate() == null) {
|
||||
qs.setTemplate(false);
|
||||
LOG.debug("Set default template value: {} on: {}.",qs.getTemplate(),name);
|
||||
}
|
||||
|
||||
for (TPQuerySet qsNode:qs.getQuerySets()) {
|
||||
Validate.notNull(qsNode, "query set may not be null.");
|
||||
|
||||
copyToChild(qs,qsNode);
|
||||
walkQuerySet(result,name+getTreePathSeperator()+qsNode.getName(),qsNode,systemId);
|
||||
}
|
||||
for (TPQuery q:qs.getQueries()) {
|
||||
Validate.notNull(q, "query may not be null.");
|
||||
Validate.notBlank(q.getName(),"query name may not be blank");
|
||||
q.getQueryParameters().forEach(param -> {
|
||||
Validate.notNull(param, "query parameter may not be null.");
|
||||
Validate.notNull(param.getName(), "query parameter.getName() may not be null.");
|
||||
Validate.notNull(param.getValueType(), "query parameter valueType may not be null.");
|
||||
});
|
||||
|
||||
copyToChild(qs,q);
|
||||
q.setName(name+getTreePathSeperator()+q.getName()); // set tree name.
|
||||
|
||||
TPQStoreManagerEntry entry = createQueryEntry(q,systemId); // create fillQuery() ? and move back below.
|
||||
|
||||
getConfigValidators().forEach(validator -> {
|
||||
if (Pattern.matches(validator.getPattern(), q.getName())) {
|
||||
LOG.debug("validation by: {} on query: {} because matched: {}",validator.getCheck().getClass().getSimpleName(),q.getName(),validator.getPattern());
|
||||
validator.getCheck().validateQuery(q);
|
||||
}
|
||||
});
|
||||
|
||||
result.put(entry.getQuery().getName(),entry);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyToChild(AbstractTPQueryNode parent,AbstractTPQueryNode child) {
|
||||
|
||||
child.setLanguage(ObjectUtils.defaultIfNull(child.getLanguage(), parent.getLanguage()));
|
||||
child.setTimeout( ObjectUtils.defaultIfNull(child.getTimeout(), parent.getTimeout()));
|
||||
child.setTemplate(ObjectUtils.defaultIfNull(child.getTemplate(), parent.getTemplate()));
|
||||
|
||||
for (TPQueryHint hint:parent.getQueryHints()) {
|
||||
boolean add = true;
|
||||
for (TPQueryHint childHint:child.getQueryHints()) {
|
||||
if (hint.getName().equals(childHint.getName())) {
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
child.addQueryHint(hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TPQStoreManagerEntry createQueryEntry(TPQuery q,String systemId) {
|
||||
TPQStoreManagerEntry entry = new TPQStoreManagerEntry(q,systemId);
|
||||
|
||||
LOG.debug("Created store entry for query: {} systemId: {}",entry.getQuery().getName(),entry.getSystemId());
|
||||
|
||||
q.getQueryHints().forEach(hint -> {
|
||||
entry.getNamedProperties().put(hint.getName(), hint.getValue());
|
||||
LOG.trace("Mapped query hint name: {} value {}",hint.getName(),hint.getValue());
|
||||
});
|
||||
|
||||
for (TPQueryParameter qp:q.getQueryParameters()) {
|
||||
LOG.trace("Check parameter {}",qp.getName());
|
||||
|
||||
if (qp.getType() == null) {
|
||||
qp.setType(getDefaultParameterType());
|
||||
LOG.debug("Set type on parameter: {} value: {} as default type.",qp.getName(),qp.getType());
|
||||
}
|
||||
|
||||
// Autofill aliases to classes.
|
||||
String valueTypeOld = qp.getValueType();
|
||||
qp.setValueType(ObjectUtils.defaultIfNull(getValueTypeAliases().get(qp.getValueType()), qp.getValueType()));
|
||||
if (!valueTypeOld.equals(qp.getValueType())) {
|
||||
LOG.debug("Converted alias for parameter: {} old: {} new: {}",qp.getName(),valueTypeOld,qp.getValueType());
|
||||
}
|
||||
|
||||
if (qp.getNullable() == null) {
|
||||
qp.setNullable(getDefaultParameterNullable());
|
||||
LOG.debug("Set nullable on parameter: {} value: {} as default type.",qp.getName(),qp.getNullable());
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
|
||||
/**
|
||||
* Hold al extra objects to prepare query the query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerEntry {
|
||||
|
||||
private long countPrepared = 0;
|
||||
private long countCacheHit = 0;
|
||||
private long countWrite = 0;
|
||||
private final TPQuery query;
|
||||
private final String systemId;
|
||||
private boolean valueMappedWriter = true;
|
||||
private boolean validateParameters = true;
|
||||
private final Map<String,String> namedProperties;
|
||||
private final Map<String,CompiledScript> parameterDefaultCompiledScripts;
|
||||
private final Map<String,TPQConfigParameterValueHolder> parameterDefaultValues;
|
||||
private Map<String,TPQueryParameterMetaData> parameterMetaData;
|
||||
private static final String HINT_VALIDATE = "net.forwardfire.tpquery.validate"; // LATER move to ?
|
||||
|
||||
/**
|
||||
* Create an entry for an query.
|
||||
* @param query The query to create this entry for.
|
||||
* @param systemId The systemId of the query.
|
||||
*/
|
||||
public TPQStoreManagerEntry(TPQuery query,String systemId) {
|
||||
Objects.requireNonNull(query);
|
||||
Objects.requireNonNull(systemId);
|
||||
this.query=query;
|
||||
this.systemId=systemId;
|
||||
this.namedProperties=new HashMap<>();
|
||||
this.parameterDefaultCompiledScripts=new HashMap<>();
|
||||
this.parameterDefaultValues=new HashMap<>();
|
||||
for (TPQueryHint hint:query.getQueryHints()) {
|
||||
if (HINT_VALIDATE.equals(hint.getName())) {
|
||||
validateParameters = Boolean.parseBoolean(hint.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init extra data.
|
||||
*/
|
||||
public void initEntry() {
|
||||
Map<String,TPQueryParameterMetaData> parameterMetaDataBuild = new HashMap<>();
|
||||
getQuery().getQueryParameters().forEach(p ->
|
||||
parameterMetaDataBuild.put(p.getName(),
|
||||
new TPQStoreManagerEntryParameterMetaData(
|
||||
p.getName(),loadValueType(p.getValueType()),p.getNullable(),defineRequired(p)
|
||||
)
|
||||
)
|
||||
);
|
||||
this.parameterMetaData=Collections.unmodifiableMap(parameterMetaDataBuild);
|
||||
}
|
||||
|
||||
private Class<?> loadValueType(String valueType) {
|
||||
try {
|
||||
return ClassUtils.getClass(valueType);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean defineRequired(TPQueryParameter p) {
|
||||
return !p.getNullable() && Objects.isNull(p.getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public TPQuery getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the systemId
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the properties
|
||||
*/
|
||||
public Map<String, String> getNamedProperties() {
|
||||
return namedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterDefaultCompiledScripts
|
||||
*/
|
||||
public Map<String, CompiledScript> getParameterDefaultCompiledScripts() {
|
||||
return parameterDefaultCompiledScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterDefaultValues
|
||||
*/
|
||||
public Map<String, TPQConfigParameterValueHolder> getParameterDefaultValues() {
|
||||
return parameterDefaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countPrepared
|
||||
*/
|
||||
public long getCountPrepared() {
|
||||
return countPrepared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the prepared counter.
|
||||
*/
|
||||
public void incCountPrepared() {
|
||||
countPrepared++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countCacheHit
|
||||
*/
|
||||
public long getCountCacheHit() {
|
||||
return countCacheHit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the cacheHit counter.
|
||||
*/
|
||||
public void incCountCacheHit() {
|
||||
countCacheHit++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countWrite
|
||||
*/
|
||||
public long getCountWrite() {
|
||||
return countWrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the write counter.
|
||||
*/
|
||||
public void incCountWrite() {
|
||||
countWrite++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterMetaData
|
||||
*/
|
||||
public Map<String,TPQueryParameterMetaData> getParameterMetaData() {
|
||||
return parameterMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueMappedWriter
|
||||
*/
|
||||
public boolean isValueMappedWriter() {
|
||||
return valueMappedWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueMappedWriter the valueMappedWriter to set
|
||||
*/
|
||||
public void setValueMappedWriter(boolean valueMappedWriter) {
|
||||
this.valueMappedWriter = valueMappedWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the validateParameters
|
||||
*/
|
||||
public boolean isValidateParameters() {
|
||||
return validateParameters;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
|
||||
/**
|
||||
* Public implementation of the query parameter meta data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 28, 2015
|
||||
*/
|
||||
public class TPQStoreManagerEntryParameterMetaData implements TPQueryParameterMetaData {
|
||||
|
||||
private final String name;
|
||||
private final Class<?> valueType;
|
||||
private final boolean nullable;
|
||||
private final boolean required;
|
||||
|
||||
/**
|
||||
* Create an info for the parameter.
|
||||
* @param name The parameter name.
|
||||
* @param valueType The parameter type.
|
||||
*/
|
||||
public TPQStoreManagerEntryParameterMetaData(String name,Class<?> valueType,boolean nullable,boolean required) {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(valueType);
|
||||
this.name=name;
|
||||
this.valueType=valueType;
|
||||
this.nullable=nullable;
|
||||
this.required=required;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
|
||||
/**
|
||||
* Provides access to the query store meta-info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerEntryView implements TPQueryStore {
|
||||
|
||||
private final TPQStoreManagerConfig config;
|
||||
|
||||
/**
|
||||
* Creates an TPQueryStore view based on the manager config.
|
||||
* @param config The config from which the data comes.
|
||||
*/
|
||||
public TPQStoreManagerEntryView(TPQStoreManagerConfig config) {
|
||||
Objects.requireNonNull(config);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getQueryNames() {
|
||||
return config.getQueryNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,TPQueryParameterMetaData> getParameterMetaData(String queryName) {
|
||||
return config.getEntries().get(queryName).getParameterMetaData();
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue