This commit is contained in:
lukaseder 2018-07-09 09:36:46 +02:00
parent a8034df369
commit e090634332
13 changed files with 0 additions and 551 deletions

View File

@ -1,2 +0,0 @@
/target
/*.iml

View File

@ -1,19 +0,0 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Other licenses:
-----------------------------------------------------------------------------
Commercial licenses for this work are available. These replace the above
ASL 2.0 and offer limited warranties, support, maintenance, and commercial
database integrations.
For more information, please visit: http://www.jooq.org/licenses

View File

@ -1,12 +0,0 @@
Thanks for downloading jOOQ.
Please visit http://www.jooq.org for more information.
To install and run this example, simply check it out and run the following Maven command
```
$ pwd
/path/to/checkout/dir
$ cd jOOQ-examples/jOOQ-nashorn-example
...
$ mvn clean install
```

View File

@ -1,193 +0,0 @@
<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>org.jooq</groupId>
<artifactId>jooq-nashorn-example</artifactId>
<version>1.0</version>
<name>jOOQ Nashorn Example</name>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.jooq.org/inc/LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>3.2.6.RELEASE</org.springframework.version>
<org.jooq.version>3.12.0-SNAPSHOT</org.jooq.version>
<org.h2.version>1.4.197</org.h2.version>
</properties>
<dependencies>
<!-- Database access -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${org.jooq.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${org.h2.version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- The resources element will replace available properties in all matching
resources. We use this to provide H2 connection configuration to various
configuration elements -->
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<fork>true</fork>
<maxmem>1024m</maxmem>
<meminitial>256m</meminitial>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
<!-- [#2413] Make compiler warnings a bit more visible
But don't fail (yet) -->
<compilerArgs>
<arg>-Xlint:varargs</arg>
</compilerArgs>
</configuration>
</plugin>
<!-- We're using the properties plugin to load external properties into Maven.
See this excellent blog post for an explanation:
http://www.petrikainulainen.net/programming/tips-and-tricks/creating-profile-specific-configuration-files-with-maven/ -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<!-- The H2 test schema is loaded here -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<skip>${maven.test.skip}</skip>
<forkMode>always</forkMode>
</configuration>
<executions>
<execution>
<id>create-database-h2</id>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<driver>${db.driver}</driver>
<url>${db.url}</url>
<username>${db.username}</username>
<password>${db.password}</password>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>src/main/resources/db-h2.sql</srcFile>
</srcFiles>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${org.h2.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- The jOOQ code generator plugin -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${org.jooq.version}</version>
<executions>
<execution>
<id>generate-h2</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>${db.driver}</driver>
<url>${db.url}</url>
<user>${db.username}</user>
<password>${db.password}</password>
</jdbc>
<generator>
<database>
<inputSchema>PUBLIC</inputSchema>
</database>
<target>
<packageName>org.jooq.example.db.h2</packageName>
<directory>target/generated-sources/jooq-h2</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,19 +0,0 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Other licenses:
-----------------------------------------------------------------------------
Commercial licenses for this work are available. These replace the above
ASL 2.0 and offer limited warranties, support, maintenance, and commercial
database integrations.
For more information, please visit: http://www.jooq.org/licenses

View File

@ -1,2 +0,0 @@
Thanks for downloading jOOQ.
Please visit http://www.jooq.org for more information.

View File

@ -1,11 +0,0 @@
#Database Configuration
db.driver=org.h2.Driver
db.url=jdbc:h2:~/jooq-nashorn-example
db.username=sa
db.password=
#jOOQ Configuration
jooq.sql.dialect=H2
#DB Schema
db.schema.script=db-h2.sql

View File

@ -1,78 +0,0 @@
DROP TABLE IF EXISTS book_to_book_store;
DROP TABLE IF EXISTS book_store;
DROP TABLE IF EXISTS book;
DROP TABLE IF EXISTS author;
DROP SEQUENCE IF EXISTS s_author_id;
CREATE SEQUENCE s_author_id START WITH 1;
CREATE TABLE author (
id INT NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50) NOT NULL,
date_of_birth DATE,
year_of_birth INT,
address VARCHAR(50),
CONSTRAINT pk_t_author PRIMARY KEY (ID)
);
CREATE TABLE book (
id INT NOT NULL,
author_id INT NOT NULL,
co_author_id INT,
details_id INT,
title VARCHAR(400) NOT NULL,
published_in INT,
language_id INT,
content_text CLOB,
content_pdf BLOB,
rec_version INT,
rec_timestamp TIMESTAMP,
CONSTRAINT pk_t_book PRIMARY KEY (id),
CONSTRAINT fk_t_book_author_id FOREIGN KEY (author_id) REFERENCES author(id),
CONSTRAINT fk_t_book_co_author_id FOREIGN KEY (co_author_id) REFERENCES author(id)
);
CREATE TABLE book_store (
name VARCHAR(400) NOT NULL,
CONSTRAINT uk_t_book_store_name PRIMARY KEY(name)
);
CREATE TABLE book_to_book_store (
book_store_name VARCHAR(400) NOT NULL,
book_id INTEGER NOT NULL,
stock INTEGER,
CONSTRAINT pk_b2bs PRIMARY KEY(book_store_name, book_id),
CONSTRAINT fk_b2bs_bs_name FOREIGN KEY (book_store_name)
REFERENCES book_store (name)
ON DELETE CASCADE,
CONSTRAINT fk_b2bs_b_id FOREIGN KEY (book_id)
REFERENCES book (id)
ON DELETE CASCADE
);
INSERT INTO author VALUES (next value for s_author_id, 'George', 'Orwell', '1903-06-25', 1903, null);
INSERT INTO author VALUES (next value for s_author_id, 'Paulo', 'Coelho', '1947-08-24', 1947, null);
INSERT INTO book VALUES (1, 1, null, null, '1984', 1948, 1, 'To know and not to know, to be conscious of complete truthfulness while telling carefully constructed lies, to hold simultaneously two opinions which cancelled out, knowing them to be contradictory and believing in both of them, to use logic against logic, to repudiate morality while laying claim to it, to believe that democracy was impossible and that the Party was the guardian of democracy, to forget, whatever it was necessary to forget, then to draw it back into memory again at the moment when it was needed, and then promptly to forget it again, and above all, to apply the same process to the process itself -- that was the ultimate subtlety; consciously to induce unconsciousness, and then, once again, to become unconscious of the act of hypnosis you had just performed. Even to understand the word ''doublethink'' involved the use of doublethink..', null, 1, '2010-01-01 00:00:00');
INSERT INTO book VALUES (2, 1, null, null, 'Animal Farm', 1945, 1, null, null, null, '2010-01-01 00:00:00');
INSERT INTO book VALUES (3, 2, null, null, 'O Alquimista', 1988, 4, null, null, 1, null);
INSERT INTO book VALUES (4, 2, null, null, 'Brida', 1990, 2, null, null, null, null);
INSERT INTO book_store (name) VALUES
('Orell Füssli'),
('Ex Libris'),
('Buchhandlung im Volkshaus');
INSERT INTO book_to_book_store VALUES
('Orell Füssli', 1, 10),
('Orell Füssli', 2, 10),
('Orell Füssli', 3, 10),
('Ex Libris', 1, 1),
('Ex Libris', 3, 2),
('Buchhandlung im Volkshaus', 3, 1);

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p [%-70c{4}] - %m%n" />
</layout>
</appender>
<logger name="org.springframework.core">
<level value="info"/>
</logger>
<logger name="org.springframework.beans">
<level value="info"/>
</logger>
<logger name="org.springframework.context">
<level value="info"/>
</logger>
<logger name="org.springframework.web">
<level value="info"/>
</logger>
<logger name="org.jooq.impl">
<level value="debug"/>
</logger>
<root>
<priority value="debug"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>

View File

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{ABSOLUTE} %5p [%-50c{4}] - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.springframework.core" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.springframework.beans" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.springframework.context" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.springframework.web" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.jooq.impl" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -1,96 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.example;
import static javax.script.ScriptContext.ENGINE_SCOPE;
import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
import java.util.stream.Stream;
import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author Lukas Eder
*/
public class NashornTest {
private static Connection connection;
@BeforeClass
public static void before() throws Exception {
Properties properties = new Properties();
properties.load(NashornTest.class.getResourceAsStream("/config.properties"));
Class.forName(properties.getProperty("db.driver"));
connection = DriverManager.getConnection(
properties.getProperty("db.url"),
properties.getProperty("db.username"),
properties.getProperty("db.password")
);
}
@Test
public void testScripts() throws Exception {
Stream.of(
new File(getClass().getResource("/org/jooq/example/test").toURI()).listFiles((dir, name) -> name.endsWith(".js"))
).forEach(file -> {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
Bindings bindings = engine.getBindings(ENGINE_SCOPE);
bindings.put("connection", connection);
try {
engine.eval(new FileReader(file));
}
catch (Exception e) {
throw new RuntimeException("Error while running " + file, e);
}
});
}
}

View File

@ -1,33 +0,0 @@
var DSL = Java.type("org.jooq.impl.DSL");
var Settings = Java.type("org.jooq.conf.Settings");
var RenderNameStyle = Java.type("org.jooq.conf.RenderNameStyle");
var Assert = Java.type("org.junit.Assert");
var Arrays = Java.type("java.util.Arrays");
var Tables = Java.type("org.jooq.example.db.h2.Tables");
var b = Tables.BOOK;
var a = Tables.AUTHOR;
// Unfortunately, there is a Nashorn / Java interoperablility issue documented here:
// http://stackoverflow.com/q/25603191/521799
//
// To work around this issue, tables should probably be supplied in JavaScript arrays,
// in order to explicitly invoke the method accepting varargs, instead of the overloaded method
var authors = DSL.using(connection, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS))
.select(a.ID)
.from([a])
.orderBy(a.ID)
.fetch(a.ID);
Assert.assertEquals(Arrays.asList([1, 2]), authors);
var authors = DSL.using(connection, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS))
.select(a.ID)
.from([DSL.tableByName("author")])
.orderBy(a.ID)
.fetch(a.ID);
Assert.assertEquals(Arrays.asList([1, 2]), authors);

View File

@ -1,16 +0,0 @@
var DSL = Java.type("org.jooq.impl.DSL");
var Assert = Java.type("org.junit.Assert");
var Arrays = Java.type("java.util.Arrays");
var Tables = Java.type("org.jooq.example.db.h2.Tables");
var b = Tables.BOOK;
var a = Tables.AUTHOR;
var books = DSL.using(connection)
.select(b.ID)
.from(b)
.orderBy(b.ID)
.fetch(b.ID);
Assert.assertEquals(Arrays.asList([1, 2, 3, 4]), books);