- Notifications
You must be signed in to change notification settings - Fork54
A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs.
License
jklingsporn/vertx-jooq
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
AjOOQ-CodeGenerator to createvertx-ified DAOs and POJOs!Perform all CRUD-operations asynchronously and convert your POJOs from/into aio.vertx.core.json.JsonObject
using the API anddriver of your choice.
- Fix Use enum literal instead of toString for datatype conversion#209
- Update to jooq 3.17.3
- Update to vertx 4.3.3
- Update mutiny dependencies
- Update rx dependencies
Before you start generating code using vertx-jooq, you have to answer these questions:
- Which API do you want to use?
- How do you want to communicate with the database?
- Using good old JDBC, check for the modules with
-jdbc
suffix. - Using thereactive vertx database driver, check for
-reactive
modules.
- Using good old JDBC, check for the modules with
- Do you need extras?
- Support forGuice dependency injection
- Generation of
io.vertx.codegen.annotations.@DataObject
-annotations for your POJOs
Once you made your choice, you can start to configure the code-generator. This can be either done programmatically orusing a maven- / gradle-plugin (recommended way).Please check the documentation in the module of the API and driver of your choice how to set it up and how to use it:
vertx-jooq-classic-jdbc
vertx-jooq-classic-reactive
vertx-jooq-rx-jdbc
vertx-jooq-rx-reactive
vertx-jooq-rx3-jdbc
vertx-jooq-rx3-reactive
vertx-jooq-mutiny-jdbc
vertx-jooq-mutiny-reactive
Once the generator is set up, it can create DAOs like in the code snippet below (classic-API, JDBC, no dependency injection):
//Setup your jOOQ configurationConfigurationconfiguration = ...//setup VertxVertxvertx =Vertx.vertx();//instantiate a DAO (which is generated for you)SomethingDaodao =newSomethingDao(configuration,vertx);//fetch something with ID 123...dao.findOneById(123) .onComplete(res->{if(res.succeeded()){vertx.eventBus().send("sendSomething",res.result().toJson()) }else{System.err.println("Something failed badly: "+res.cause().getMessage()); } });//maybe consume it in another verticlevertx.eventBus().<JsonObject>consumer("sendSomething",jsonEvent->{JsonObjectmessage =jsonEvent.body();//Convert it back into a POJO...Somethingsomething =newSomething(message);//... change some valuessomething.setSomeregularnumber(456);//... and update it into the DBFuture<Integer>updatedFuture =dao.update(something);});//or do you prefer writing your own type-safe SQL? Use the QueryExecutor from the DAO...ClassicQueryExecutorqueryExecutor =dao.queryExecutor();//... or create a new one when there is no DAO around :)queryExecutor =newJDBCClassicGenericQueryExecutor(configuration,vertx);Future<Integer>updatedCustom =queryExecutor.execute(dslContext ->dslContext.update(Tables.SOMETHING).set(Tables.SOMETHING.SOMEREGULARNUMBER,456).where(Tables.SOMETHING.SOMEID.eq(something.getSomeid())).execute());//check for completionupdatedCustom.onComplete(res->{if(res.succeeded()){System.out.println("Rows updated: "+res.result());}else{System.err.println("Something failed badly: "+res.cause().getMessage());}});
More examples can be foundhere,here andhere.
Checkoutthis repository to figure out how to utilize vertx-jooq to create Quarkus-compatible classes.
The generator will omit datatypes that it does not know, e.g.java.sql.Timestamp
. To fix this, you can subclass the generator, handle these types and generate the code using your generator.See thehandleCustomTypeFromJson
andhandleCustomTypeToJson
methods in theAbstractVertxGenerator
or checkout theCustomVertxGenerator
from the tests.
Starting with version6.4.0
, vertx-jooq implicitly requires Java 11, as this is the minimum required version by the non-commercial version of jOOQ3.15
.If you're stuck with Java 8, the latest version you can use is6.3.0
.
Yes! There aremany integration tests that cover most usecases.Check them out if you're interested.
The tests are executed against two docker containers. Please refer tothis readme of how to set them up.
Increase your file limits. Unfortunately the solution differs by each OS version, so you have to do some research.
This library comes without any warranty - just take it or leave it. Also, the author is neither connected to thecompany behind vertx nor the one behind jOOQ.
About
A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs.