Fixed Nashorn example

This commit is contained in:
lukaseder 2014-11-27 08:28:15 +01:00
parent 63bf2d39fc
commit ba9557e700
4 changed files with 58 additions and 3 deletions

View File

@ -17,6 +17,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/jooq-h2"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">

View File

@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>3.2.6.RELEASE</org.springframework.version>
<org.jooq.version>3.6.0-SNAPSHOT</org.jooq.version>
<org.h2.version>1.4.181</org.h2.version>
</properties>
<dependencies>
@ -33,7 +34,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
<version>${org.h2.version}</version>
</dependency>
<!-- Logging -->
@ -154,7 +155,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
<version>${org.h2.version}</version>
</dependency>
</dependencies>
</plugin>
@ -205,7 +206,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.168</version>
<version>${org.h2.version}</version>
</dependency>
</dependencies>
</plugin>

View File

@ -0,0 +1,33 @@
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

@ -0,0 +1,16 @@
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);