Frozen Queries

Ultra fast and unmodifible 

From the very beginning, Daobab is able to work with SQL as a regular Java code by the flexible Daobab Queries.

Building the entire Daobab Query, with all the necessary SQL functionalities may need a few milliseconds though. Also, building a SQL query from it takes some additional time.

However, there are many situations where the query is unmodifiable and the most important requirement is performance.

For that reason, a new feature 'Frozen Queries' was introduced in version 1.7.

Frozen Query may be created from Daobab Query object and the idea is to have SQL already built and cached internally.

Once built, Frozen Query can be used to findOne or findMany objects without crafting the correct SQL for every JDBC call.

The query can be built from any regular Daobab query:

        var frozenQuery = db.select(tabCustomer.colFirstName())
                .whereLess(tabCustomer.colID(), 10)
                .freezeQuery();


In that form the frozen query is ready to use:

        var result = frozenQuery.findMany();Frozen Query has the performance very similar to regular JDBC call.

Since the SQL command is already built, the query acts like a native SQL and the number of retrieved parameters cannot be changed.

Although Frozen Query is unmodifiable, it can still accept some parameters from a where clause for example.

So that it may works like a regular Hibernate or JPA @Query expression.

To build Frozen Query with dynamic  parameters,  

Building a Frozen Query with dynamic parameters:

        frozenQuery = db.select(tabCustomer.colFirstName())
                        .whereLess(tabCustomer.colID(), param(1))
                        .freezeQuery();


After that, provide the parameter array by the withParameters(Object[] params) method:


Adding the parameters and retrieving the result:

        return frozenQuery.withParameters(10).findMany();
Daobab replaces the parameters in the query, using the array order.



Frozen query can be unfrozen.

After unfreeze, it is a regular Daobab Query againa, so it's possible to add for example additional conditions to it:


var unfrozenQuery = fistFrozenQuery.unfreeze();
var secondQuery = unfrozenQuery.orderDescBy(tabCustomer.colFirstName());
var secondFrozenQuery = secondQuery.freezeQuery();




© Copyright 2018-2023 Elephant Software Klaudiusz Wojtkowiak 
e-mail: contact@daobab.io