This module helps integrate Querydsl SQL with Plume Database. It contains mainly:
TransactionManagerQuerydsl
: the main class of this module; it will read the configuration, initialize the SQL connection pool and provide helper methods to create Querydsl queries,- The generic DAO
CrudDaoQuerydsl
for CRUD operations.
Querydsl queries can be created:
- without a
Connection
: that means that the query will be executed with a connection from the SQL connection pool. TheConnection
object will be automaticely released in the pool once the query is executed. - with a
Connection
: that means that the query will be executed on this supplied connection. This mode is almost always used when a transaction is needed:
transactionManager.execute(connection -> {
transactionManager.insert(QTable.table, connection).populate(bean).execute();
transactionManager.delete(QTable.table, connection).where(predicate).execute();
// the connection is set to autocommit=false and will be commited at the end of the lambda
});
To use the CRUD DAO CrudDaoQuerydsl
, entities must have a primary key on a column named id
mapped with the Java type long
.
A CRUD DAO example
is provided in the demo project.
For Querydsl documentation, see the official Querydsl documentation.
Maven:
<dependency>
<groupId>com.coreoz</groupId>
<artifactId>plume-db-querydsl</artifactId>
</dependency>
<dependency>
<groupId>com.coreoz</groupId>
<artifactId>plume-db-querydsl-codegen</artifactId>
<optional>true</optional>
</dependency>
<!-- do not forget to also include the database driver -->
Guice: install(new GuiceQuerydslModule());
The properties db.dialect
can one value among : MYSQL
, H2
, ORACLE
, POSTGRE
, SQL_SERVEUR
.
See the Plume Database configuration for other configuration keys.
See how it is done with Plume Database.
To generate Querydsl entities, a good choice is to use this Querydsl code generator.