Results

Once you have concatenated criterias together, you can execute the query via the execution methods. Please remember that these methods return the results, so they must be executed last.

So the idea is the you request a query, add all kinds of restrictions and modifiers and then you request the results from it.

Method

Description

count( propertyName="" )

Note, count() can't be called on a criteria after list() has been executed.

get( [properties=""] )

Get a single entity. If you pass in the properties then you will get a struct of those properties.

getOrFail( [properties=""] )

Convenience method to return a single instance that matches the built up criterias query, or throws an exception if the query returns no results

list(

max,

offset,

timeout,

sortOrder,

ignoreCase,

asQuery=false

asStream=false

)

Execute the criterias and give you the results.

count( propertyName = "' )

Get the record count using hibernate projections for the given criterias. You can optionally pass in the name of the property to do the count on, else it doesn * by default.

service
    .newCriteria()
    .joinTo( "categories", "categories" )
    .isEq( "categories.categoryID", getCategoryID() )
    .isTrue( "isPublished" )
    .isLE( "publishedDate", now() )
    .isEq( "passwordProtection", "" )
    .$or(
        service.getRestrictions().isNull( "expireDate" ),
        service.getRestrictions().isGT( "expireDate", now() )
    )
    .cache( true )
    .count( "contentID" );

get( properties="" )

Convenience method to return a single instance that matches the built up criterias, or null if the query returns no results. It can also throw the following exception: NonUniqueResultException - if there is more than one matching result. It can also take in a property list in the properties argument so instead of giving you a full ORM entity object, it will give you a struct of those properties.

getOrFail( properties="" )

Convenience method to return a single instance that matches the built up criterias, or throw an exception (EntityNotFound) if the query returns no results. It can also throw the following exception: NonUniqueResultException - if there is more than one matching result. It can also take in a property list in the properties argument so instead of giving you a full ORM entity object, it will give you a struct of those properties.

list( ... )

Execute the criteria queries you have defined and return the results, you can pass optional parameters to manipulate the way the results are sent back to you. Let's look at the method signature for this awesome method:

As you can see from the signature above, the first two arguments (offset, max) are used for pagination. So you can easily paginate the result set. The timeout argument can be used if the query is expected to be heavy duty, we want to make sure we timeout the execution (throws exception). The ignorecase is only used for sorting orders.

Then we get to the last two arguments: asQuery, asStream. By default the list() method will return an array of objects. However, if you want different results you can use this two modifiers to give you a ColdFusion query or a Java stream.

Last updated

Was this helpful?