The add-on provides:
- QueryDSL integration for CUBA applications. QueryDSL enables the construction of unified type-safe database queries for Java. Instead of writing queries, you can use a fluent API.
- View Builder based on QueryDSL classes
See the demo project, using this add-on.
QueryDSL provides suggestions in your IDE:
QueryDSL guarantees that the compiler will check that your database queries and CUBA view are type-safe. It also helps you adapt better to refactoring changes.
The add-on can be added to your project in one of the ways described below. Installation from the Marketplace is the simplest way. The last version of the add-on compatible with the used version of the platform will be installed. Also, you can install the add-on by coordinates choosing the required version of the add-on from the table.
In case you want to install the add-on by manual editing or by building from sources see the complete add-ons installation guide in CUBA Platform documentation.
- Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
- Go to CUBA -> Marketplace in the main menu.
- Find the QueryDSL add-on there.
- Click Install and apply the changes. The add-on corresponding to the used platform version will be installed.
-
Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
-
Go to CUBA -> Marketplace in the main menu.
-
Click the icon in the upper-right corner.
- Paste the add-on coordinates in the corresponding field as follows:
ru.udya.querydsl.cuba:querydsl-cuba-global:<add-on version>
where <add-on version>
is compatible with the used version of the CUBA platform.
Platform Version | Component Version |
---|---|
7.2.X | 1.0.0 |
- Click Install and apply the changes. The add-on will be installed to your project.
After adding the add-on in your application, you need to configure it:
- Configure
global
module in thebuild.gradle
file of your project.
configure(globalModule) {
dependencies {
// begin: generated by CUBA Studio
if (!JavaVersion.current().isJava8()) {
runtime('javax.xml.bind:jaxb-api:2.3.1')
runtime('org.glassfish.jaxb:jaxb-runtime:2.3.1')
}
// end: generated by CUBA Studio
// begin: add by yourself
compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.4'
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: '4.1.4', classifier: 'jpa'
annotationProcessor configurations.compile
// end: add by yourself
}
}
- Assemble the project. This part is needed to generate QueryDSL classes.
Now you can use type-safe queries in your application.
The Demo project demonstrates the usage of the add-on.
Here is an example from the demo project:
Query example
CubaQueryFactory queryFactory = new CubaQueryFactory(txDm, metadata);
QOrder order = new QOrder("o");
QOrderStorageItem orderStorageItem = QOrderStorageItem.orderStorageItem;
return queryFactory.select(order)
.from(orderStorageItem).join(orderStorageItem.order, order)
.where(orderStorageItem.storage.id.eq(storageId.getValue()))
.orderBy(order.updateTs.desc())
.fetch(view);
View example
@Inject
protected TypedViewFactory typedViewFactory;
var qStorage = QStorage.storage;
View storageView = typedViewFactory.view(qStorage, qStorage.name)
.property(qStorage.storageItems, (qsi, qsib) -> qsib.properties(qsi.count)
.property(qsi.product, (qp, qpb) -> qpb.properties(qp.name))).build();