Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jklingsporn/vertx-jooq-async
Deprecated, use vertx-jooq instead:
https://github.com/jklingsporn/vertx-jooq-async
java jooq vertx
Last synced: 1 day ago
JSON representation
Deprecated, use vertx-jooq instead:
- Host: GitHub
- URL: https://github.com/jklingsporn/vertx-jooq-async
- Owner: jklingsporn
- License: mit
- Archived: true
- Created: 2017-06-22T08:52:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T10:13:40.000Z (almost 7 years ago)
- Last Synced: 2024-12-22T02:13:15.662Z (30 days ago)
- Topics: java, jooq, vertx
- Language: Java
- Homepage: https://github.com/jklingsporn/vertx-jooq
- Size: 212 KB
- Stars: 28
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deprecation warning
I started vertx-jooq-async a couple months after working on [vertx-jooq](https://github.com/jklingsporn/vertx-jooq) to allow the same
features but using the async driver. First, I tried to incorproate it into vertx-jooq but it couldn't be done without a major
refactoring (which I didn't have the time for), so I created this repository. In the following weeks it bothered me more and more,
that if I had to fix a bug, it had to be done two times. Also both projects shared a similar API: again a lot of duplicate code.In the last weeks I finally found some time to refactor vertx-jooq so it incorporates now both, the JDBC and the async driver.
**Because of that, vertx-jooq-async will no longer be maintained.**# vertx-jooq-async
The _real_ async version of [vertx-jooq](https://github.com/jklingsporn/vertx-jooq): a [jOOQ](http://www.jooq.org/)-CodeGenerator to create [vertx](http://vertx.io/)-ified DAOs and POJOs!
This time with a [_real_ asynchronous driver](https://github.com/mauricio/postgresql-async). That's right - no JDBC.## differences to vertx-jooq
This project uses jOOQ for code-generation and to render queries. The query execution is done by the `AsyncJooqSQLClient`
which wraps a `io.vertx.ext.asyncsql.AsyncSQLClient`. The `executeAsync`-method has been removed from `VertxDao`, instead
you need to call the `client()` method on the DAO to execute custom SQL-statements (see example below) on the `AsyncJooqSQLClient`.## example
```
//Setup your jOOQ configuration
Configuration configuration = new DefaultConfiguration();
configuration.set(SQLDialect.MYSQL); //or SQLDialect.POSTGRES
//no other DB-Configuration necessary because jOOQ is only used to render our statements - not for excecution//setup Vertx
Vertx vertx = Vertx.vertx();
//setup the client
JsonObject config = new JsonObject().put("host", "127.0.0.1").put("username", "vertx").putNull("password").put("database","vertx");
AsyncJooqSQLClient client = AsyncJooqSQLClient.create(vertx,MySQLClient.createNonShared(vertx, config))//instantiate a DAO (which is generated for you)
SomethingDao dao = new SomethingDao(configuration);
dao.setVertx(vertx);
dao.setClient(client);//fetch something with ID 123...
CompletableFuture sendFuture =
dao.findByIdAsync(123).
thenAccept(something->
vertx.eventBus().send("sendSomething",something.toJson())
);//maybe consume it in another verticle
vertx.eventBus().consumer("sendSomething", jsonEvent->{
JsonObject message = jsonEvent.body();
//Convert it back into a POJO...
Something something = new Something(message);
//... change some values
something.setSomeregularnumber(456);
//... and update it into the DB
CompletableFuture updatedFuture = dao.updateAsync(something);//or do you prefer writing your own typesafe SQL?
CompletableFuture selectFuture = dao.client().fetchOne(DSL.using(dao.configuration()).selectFrom(Tables.SOMETHING).orderBy(Tables.SOMETHING.SOMEID.desc()).limit(1),dao.jsonMapper());
//check for completion
selectFuture.whenComplete((something,ex)->{
if(ex==null){
System.out.println("It's something! "+something.toJson());
}else{
System.err.println("Something failed badly: "+ex.getMessage());
}
});
});
```# callback? future? rx?
Again, this library comes in different flavors:
- the classic callback-handler style.
- a API that returns a [vertx-ified implementation](https://github.com/cescoffier/vertx-completable-future)
of `java.util.concurrent.CompletableFuture` for all async DAO operations and thus makes chaining your async operations easier.
It has some limitations which you need to be aware about (see [known issues](https://github.com/jklingsporn/vertx-jooq#known-issues)).
- a RX Java based APIDepending on your needs, you have to include one of the following dependencies into your pom:
- [`vertx-jooq-async-classic`](https://github.com/jklingsporn/vertx-jooq/tree/master/vertx-jooq-async-classic) is the module containing the callback handler API.
- [`vertx-jooq-async-future`](https://github.com/jklingsporn/vertx-jooq/tree/master/vertx-jooq-async-future) is the module containing the `CompletableFuture` based API.
- [`vertx-jooq-async-rx`](https://github.com/jklingsporn/vertx-jooq/tree/master/vertx-jooq-async-rx) is the module containing the RX Java based API# maven
```io.github.jklingsporn
vertx-jooq-async-future
0.4```
# maven code generator configuration example for mysql
The following code-snippet can be copy-pasted into your pom.xml to generate code from your MySQL database schema.**Watch out for placeholders beginning with 'YOUR_xyz' though! E.g. you have to define credentials for DB access and specify the target directory where jOOQ
should put the generated code into, otherwise it won't run!**After you replaced all placeholders with valid values, you should be able to run `mvn generate-sources` which creates all POJOs and DAOs into the target directory you specified.
If you are new to jOOQ, I recommend to read the awesome [jOOQ documentation](http://www.jooq.org/doc/latest/manual/), especially the chapter about
[code generation](http://www.jooq.org/doc/latest/manual/code-generation/).```
...your project configuration here...
...your other dependencies...
org.jooq
jooq
3.9.2
io.github.jklingsporn
vertx-jooq-async-future
0.4
org.jooq
jooq-codegen-maven
3.9.2
generate
mysql
mysql-connector-java
5.1.37
io.github.jklingsporn
vertx-jooq-async-generate
0.4
com.mysql.jdbc.Driver
YOUR_JDBC_URL_HERE
YOUR_DB_USER_HERE
YOUR_DB_PASSWORD_HERE
io.github.jklingsporn.vertx.jooq.async.generate.future.FutureAsyncVertxGenerator
org.jooq.util.mysql.MySQLDatabase
.*
YOUR_INPUT_SCHEMA
YOUR_OUTPUT_SCHEMA
false
BOOLEAN
(?i:TINYINT)
io.vertx.core.json.JsonObject
io.github.jklingsporn.vertx.jooq.async.shared.JsonObjectConverter
someJsonObject
.*
io.vertx.core.json.JsonArray
Jio.github.jklingsporn.vertx.jooq.async.shared.sonArrayConverter
someJsonArray
.*
YOUR_TARGET_PACKAGE_HERE
YOUR_TARGET_DIRECTORY_HERE
true
true
true
true
io.github.jklingsporn.vertx.jooq.async.generate.future.FutureAsyncGeneratorStrategy
```
# programmatic configuration of the code generator
See the [TestTool](https://github.com/jklingsporn/vertx-jooq-async/blob/master/vertx-jooq-async-generate/src/test/java/io/github/jklingsporn/vertx/jooq/async/generate/TestTool.java)
of how to setup the generator programmatically.# known issues
- `insertReturningPrimary`-method only works for MySQL and numeric keys.
- Only available for MySQL and Postgres.
- Nobody can prevent you from calling one of the blocking `fetch`- or `execute`-methods on the VertxDAO or a jOOQ-query. If you
do it, jOOQ will try to execute the query by itself using JDBC (if properly configured). So try to avoid it at any cost.
- Currently no Guice support