Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In addition to writing SQL queries, what is the effort needed for executing SQL queries? (e.g., database setup? configuration file? mapping object/database?) #2

Open
acherm opened this issue Oct 16, 2016 · 6 comments

Comments

@acherm
Copy link
Owner

acherm commented Oct 16, 2016

No description provided.

@cheisda
Copy link

cheisda commented Oct 17, 2016

I have the intention to close this issue =)

@RomainG93
Copy link

I'm on it

@MikaelPhilip
Copy link

I work on it too

@MikaelPhilip
Copy link

MikaelPhilip commented Nov 3, 2016

There are two mains steps:

1)Configuration

  1. First, you need to create your sql database.
  2. Next, it's necessary to make a configuration file (xml) to launch JOOQ code generation. In this xml file, there is:
  • All informations to find and to use database (driver, url, user, password).
  • Information to indicate what librarie to use to translate SQL in Java code and which part of database you need to select (all tables, one tables, all tables except one or two...).
  • You can, also, indicate a few flags about generation.
  • And you setup the target (package name,directory): where the generated java class will be stored.
  1. After, you need to launch JOOQ code generator with this xml file to create all JAVA objects (These objects are the maps of your tables).

2)Use

  1. With JDBC, launch your connection in Java (Keep your connection in a connection object).
  2. To finish, create a DSLContext which use your previously launched connection object .

This DSLContext can be use for queries.

Links:

@RomainG93
Copy link

RomainG93 commented Nov 5, 2016

Notes on the xml configuration file:

  • The "jdbc" section contains the information to access the database (driver, url, user, password)
  • The "generator" section contains the following sections:
    • "name": contains the generator used to generate the schema (JavaGenerator, ScalaGenrator)
    • "database": contains the following sections:
      • "name": used to define the database type (eg: MySQL)
      • "include" and "exclude": tweaking options used for the generation of the schema (include/exclude of some of the elements)
    • "target": defines destination package of the generated classes and the destination directory of the generated classes

Notes on the generation of the classes:

Schema generation can then be done by using JOOQ's command line tools. To do so, 3 JOOQ jar files, the MySQL Connector jar file and the xml configuration file are necessary.
Then the following command can be launched:

java -classpath jooq-3.8.6.jar;jooq-meta-3.8.6.jar;jooq-codegen-3.8.6.jar;mysql-connector-java-5.1.18-bin.jar;.
  org.jooq.util.GenerationTool ConfigurationFile.xml

Note: jOOQ will try loading the xml configuration file from the classpath. This is also why there is a trailing period (.) on the classpath. If the file cannot be found on the classpath, jOOQ will look on the file system from the current working directory.

@cheisda
Copy link

cheisda commented Nov 5, 2016

Notes on the generation of the classes :

It's possible a create a property file instead of a xml file.

#Database connection
jdbc.Driver=com.mysql.jdbc.Driver
jdbc.URL=jdbc:mysql://localhost:port/databaseName
jdbc.Schema=databaseName
jdbc.User=username
jdbc.Password=

We can also specify, the following items :

  • The default code generator (you can override this one to generate your own code style)
  • The database type
  • All elements that are generated from your schema
  • All elements that are excluded from your schema
  • Primary key / foreign key relations should be generated and used.
    • This will be a prerequisite for various advanced features
    • Generate deprecated code for backwards compatibility
  • The destination package of your generated classes (within the destination directory)
  • The destination directory of your generated classes

Then, type the following command :

java -classpath jooq-1.6.8.jar:jooq-meta-1.6.8.jar:jooq-codegen-1.6.8.jar:mysql-connector-java-5.1.18-bin.jar:. org.jooq.util.GenerationTool /fileName.properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants