Digest for jooq-user@googlegroups.com - 9 updates in 3 topics

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Digest for jooq-user@googlegroups.com - 9 updates in 3 topics

http://groups.google.com/group/jooq-user/topics mailing list
Costa Basil <[hidden email]>: Dec 06 01:53AM -0800

I am having a hard time trying to generate JOOQ tables code from a
postgresql database and getting it to compile successfully.
 
Here is the xml file passed to the GenerationTool:
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd">
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/postgres</url>
<user>UserName</user>
<password>***</password>
</jdbc>
<generator>
<name>org.jooq.util.ScalaGenerator</name>
<database>
<name>org.jooq.util.postgres.PostgresDatabase</name>
<inputSchema>math_derby</inputSchema>
<includes>.*</includes>
<!--<excludes></excludes>-->
</database>
<target>
<packageName></packageName>
<directory>target/scala-2.12/src_managed/main</directory>
</target>
</generator>
</configuration>
 
 
build.sbt
 
name := "Orders"

version := "1.0"

lazy val `orders` = (project in file(".")).enablePlugins(PlayScala)
 
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"

resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"

scalaVersion := "2.12.4"
 
val jooqVersion = "3.10.2"
 
libraryDependencies ++= Seq(
jdbc ,
ehcache ,
ws ,
specs2 % Test ,
guice ,
"org.postgresql" % "postgresql" % "42.1.4",
"org.jooq" % "jooq" % jooqVersion,
"org.jooq" % "jooq-codegen-maven" % jooqVersion,
"org.jooq" % "jooq-meta" % jooqVersion
 
)
 
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
 
val generateJOOQ = taskKey[Seq[File]]("Generate JooQ classes")
 
generateJOOQ := {
val r = (runner in Compile).value
val cp = (fullClasspath in Compile).value
//println(Path.makeString(cp.files))
val res = r.run("org.jooq.util.GenerationTool", cp.files, Array[String]("conf/orders.xml"), streams.value.log)
 
((sourceManaged.value / "main" ) ** "*.scala").get
}
 
//generateJOOQ := myGenTask //generateJOOQTask
 
 
unmanagedSourceDirectories in Compile += sourceManaged.value / "main"
 
 
 
 
In this particular case the generated code is placed under
target/scala-2.12/src_managed/main/org/jooq/generated. However, I cannot
reference the org.jooq.generated.Tables object. I am getting:
 
object generated is not a member of package org.jooq
[error] import org.jooq.generated.Tables
 
when I try to compile this.
 
I tried all sorts of permutations but they all fail with some errors.
 
When I tried to place the generated code in my own package I started to get:
 
method createIndex in object AbstractKeys cannot be accessed in object
org.jooq.impl.AbstractKeys
[error] Access to protected method createIndex not permitted because
[error] prefix type org.jooq.impl.AbstractKeys.type does not conform to
[error] object Indexes0 in object Indexes where the access takes place
[error] val PK_SUBMISSION : Index =
AbstractKeys.createIndex("pk_submission", Submission.SUBMISSION,
Array[OrderField [_] ](Submission.SUBMISSION.ID), true)
 
I am giving up. I need help. Any ideas or suggestions?
 
Thanks
Costa Basil <[hidden email]>: Dec 06 02:42AM -0800

I was able to compile the program by placing the Indexes & Keys classes
under org.jooq.impl and prefixing the Array call with 'scala.', i.e.
scala.Array etc.
 
I wonder if the scala code generated compiles under 2.12.4. If you have an
insight into this please let me know.
Costa Basil <[hidden email]>: Dec 06 02:44AM -0800

I was able to compile the program by placing the Indexes & Keys classes
under org.jooq.impl and prefixing the Array call with 'scala.', i.e.
scala.Array etc.
 
I wonder if the scala code generated compiles under 2.12.4. If you have an
insight into this please let me know.
Lukas Eder <[hidden email]>: Dec 06 06:39PM +0100

Hello Costa,
 
Thank you very much for your message. This might be the same issue as:
https://github.com/jOOQ/jOOQ/issues/6875
 
... a potential regression in a recent jOOQ version. I'll look into this
shortly
 
Thanks,
Lukas
 
Costa Basil <[hidden email]>: Dec 06 09:57AM -0800

Yes, this is it, it is the same issue.
Stan Svec <[hidden email]>: Dec 06 09:26AM -0800

I fixed it currently by converting custom Java enum instances into enum
data type fields before passing them into in(..) method:
public Set<Field<VisitorDevice>> getVisitorDevicesAsEnumDataType() {
return visitorDevices.stream().map(dev -> cast(dev, PostgresDataType.
VARCHAR.asEnumDataType(VisitorDevice.class))).collect(toSet());
}
[hidden email]: Dec 06 05:55AM -0800

There is a convenient builder for Select queries, e.g. SelectQuery query =
selectDistinct().from( myTable ).getQuery(); and then
query.addConditions(...); query.addFrom(...) etc.
 
Is there a similar builder for Delete and Update statements? Like
deleteFrom(table).getQuery().addConditions(...).
Lukas Eder <[hidden email]>: Dec 06 06:12PM +0100

Hello,
 
In fact, that getQuery() method is a leftover from early jOOQ versions,
which exposes jOOQ's internal model API from the DSL API [1]. The standard
way to access the model API is by using DSLContext.selectQuery(),
DSLContext.insertQuery(), DSLContext.deleteQuery(),
DSLContext.updateQuery().
 
I hope this helps,
Lukas
 
[1]:
https://www.jooq.org/doc/latest/manual/sql-building/sql-statements/dsl-and-non-dsl/
[hidden email]: Dec 06 09:21AM -0800

Awesome, thanks! Wasn't aware of these methods before, and that's right the
uniformity I needed.
 
On Wednesday, December 6, 2017 at 7:12:52 PM UTC+2, Lukas Eder wrote:
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to [hidden email].