Query API

Qi4j sports a new innovative Query API, which uses the domain model and business interfaces to express queries in refactoring-safe Java and no text expressions.
The matter of fact is that we use Java to make the Query to look like Java was involved and evaluating every item, but it is in reality a Domain Specific Language without defining any new language elements, just a set of constraints, methods and algorithms to capture the Java intent, which an underlying Query/Indexing Extension can translate into a native query language, such as SQL or SPARQL.

So how does this look like in reality. Let's look at a simple example;

QueryBuilderFactory factory = ...;
QueryBuilder<Person> builder = factory.newQueryBuilder( Person.class );

Name name  = builder.parameter( Name.class );
Expression expression = eq( name.getFirstName(), "Niclas" );
builder.where( expression ).setMaxResults( 10 );
Query<Person> query = builder.newQuery();

for( Person person : query )
{
    // Process each of the maximum 10 person objects
    // in the result set.
}

Powered by SiteVisionexternal link.