Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
These methods allows you to tap into the Criteria Queries API so you can do fluent and functional queries with your ORM objects.
The Base ORM Service has a ton of methods to assist you with your ORM needs. We have compiled them under this section under several different categories:
Criteria Queries
Creation - Population
Counters
Deleting Entities
Entity Convenience
Finders
Getters
ORM Session
Querying
Saving
Utility
Like always, you can find the latest in the link below:
Adobe ColdFusion will throw an "Invalid CFML construct" for certain CBORM methods that match reserved operator names, such as .and(), .or(), and .eq(). To avoid these errors and build cross-engine compatible code, use .$and(), .$or(), and .isEq().
// Get an instance of the restrictions
var restrictions = ormService.getRestrictions();
// Restrictions used with criteria queries
var r = ormService.getRestrictions();
var users = ormService.newCriteria("User")
.or( r.eq("lastName","majano"), r.gt("createDate", now()) )
.list();These methods allow you to create entities and populate them from external data like structures, json, xml, queries and much more.
These methods allow you to do counting on entities with or without filtering.
Finders are convenience methods that will help you find a single entity or a collection of entities by using criterias. If you want to use primary keys, then use the getters.
These methods are used for doing a-la-carte querying of entities with extra pizzaz!
Here is a collection of useful getter methods for entities by primary identifiers. Getters mostly deal with retrieving entities by primary keys instead of finders which rely on criteria operations. You can use the get() for a single entity, getOrFail() for throwing exceptions if an entity is not found and getAll() for multiple entities.
These methods allow you to delete one or more entities in cascade style or bulk styles.
Deletes entities by using name value pairs as arguments to this function. One mandatory argument is to pass the 'entityName'. The rest of the arguments are used in the where class using AND notation and parameterized. Ex: deleteWhere(entityName="User",age="4",isActive=true);
This function returns numeric
These collection of methods will give you information about the currently loaded entity or the entity class itself.
Key
Type
Required
Default
Description
entity
string
Yes
---
var properties = ormService.getPropertyNames("User");This function returns void
Key
Type
Required
Description
entities
any
Yes
The argument can be one persistence entity or an array of entities to evict
ormService.evict( thisEntity );Key
Type
Required
Default
Description
entity
string
Yes
---
var persistedTable = ormService.getTableName( "Category" );Key
Type
Required
Default
Description
entity
string
Yes
---
The entity to inspect for it's id
var pkValue = ormService.getKeyValue( "User" );Key
Type
Required
Default
Description
entity
Any
Yes
---
The entity object
if( ormService.isDirty( entity ) ){
// The values have been modified
log.debug( "entity values modified", ormService.getDirtyPropertyNames( entity ) );
}Key
Type
Required
Default
Description
entity
any
Yes
---
var user = storage.getVar("UserSession");
ormService.refresh( user );
var users = [user1,user2,user3];
ormService.refresh( users );Key
Type
Required
Default
Description
entityName
string
Yes
---
transactional
boolean
No
From Property
Use transactions not
Key
Type
Required
Default
Description
datasource
string
false
---
The default or specific datasource to use
// Check if by this point we have a dirty session, then flush it
if( ormService.isSessionDirty() ){
ORMFlush();
}baseService.nullValue()ormService.deleteWhere(entityName="User", isActive=true, age=10);
ormService.deleteWhere(entityName="Account", id="40");
ormService.deleteWhere(entityName="Book", isReleased=true, author="Luis Majano");Key
Type
Required
Default
Description
entityName
any
Yes
---
id
any
Yes
---
Key
Type
Required
Default
Description
cacheName
string
No
---
datasource
string
No
---
Get a brand new criteria builder object to do criteria queries with (See ORM:CriteriaBuilder)
This function returns coldbox.system.orm.hibernate.CriteriaBuilder
Returns the count by passing name value pairs as arguments to this function. One mandatory argument is to pass the 'entityName'. The rest of the arguments are used in the where class using AND notation and parameterized. Ex: countWhere(entityName="User",age="20");
This function returns numeric
This method will return to you the hibernate's metadata for a specific entity.
The Hibernate Java ClassMetadata Object (https://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/metadata/ClassMetadata.html)
This method allows you to cast the identifier value to the appropriate type in Java. The entity argument can be the entity name or an entity object. Please note that this is ONLY used for identifier casting not for any property!
This function returns the value casted to the right Java type
Delete using an entity name and an incoming id, you can also flush the session if needed. The ID can be a single ID or an array of ID's to batch delete using hibernate DLM style deletes. The function also returns the number of records deleted.
No cascading will be done since the delete is done without loading the entity into session but via DLM HQL
if( ormService.exists("Account",123) ){
// do something
}// evict queries that are in the default hibernate cache
ormService.evictQueries();
// evict queries for this service
ormService.evictQueries( ormService.getQueryCacheRegion() );
// evict queries for my artists
ormService.evictQueries( "MyArtits" );The datasource to use
transactional
boolean
No
From Property
Use transactions or not
Key
Type
Required
Default
Description
entityName
string
Yes
---
The entity to purge
flush
boolean
No
false
id
any
false
The id to use for eviction according to entity name or relation name
Key
Type
Required
Default
Description
entityName
string
Yes
---
The entity name to evict or use in the eviction process
relationName
string
false
The name of the relation in the entity to evict
queryCacheRegion
string
false
criterias.{entityName}
The queryCacheRegion name property for all queries in this criteria object
datasource
string
false
The datasource to use or default it to the application or entity in use
Key
Type
Required
Default
Description
entityName
string
true
---
The entity name to bind the criteria query to
useQueryCaching
boolean
false
false
Do automatic query caching for queries
transactional
boolean
No
From Property
Use Transactions or not
Key
type
Required
Default
Description
entity
any
Yes
---
flush
boolean
No
false
Key
Type
Required
Default
Description
entity
any
Yes
---
var name = ORMService.getEntityGivenName( entity );Key
Type
Required
Default
Description
datasource
string
false
---
The default or specific datasource use
ormService.clear();Key
Type
Required
Default
Description
entity
Any
Yes
---
The entity object
if( ormService.isDirty( entity ) ){
// The values have been modified
log.debug( "entity values modified", ormService.getDirtyPropertyNames( entity ) );
}flush
boolean
No
false
transactional
boolean
No
true
Use ColdFusion transactions or not
Key
Type
Required
Default
Description
entities
array
Yes
---
The array of entities to persist
forceInsert
boolean
No
false
Key
Type
Required
Default
Description
datasource
string
false
---
The default or specific datasource use
returnNew
boolean
false
true
If id is 0 or empty and this is true, then a new entity is returned.
Key
Type
Required
Default
Description
entityName
string
Yes
---
id
any
Yes
---
Key
Type
Required
Default
Description
entityName
string
Yes
---
criteria
struct
Yes
---
A structure of criteria to filter on
Key
Type
Required
Default
entityName
string
Yes
---
countWhere( entityName="User", age="20" );Key
Type
Required
Default
Description
entity
any
Yes
---
The entity name or entity object
Key
Type
Required
Default
Description
entity
string
Yes
The entity name or entity object
id
any
Yes
The value to cast
Key
Type
Required
Default
Description
entity
any
Yes
---
Key
Type
Required
Default
Description
example
any
Yes
---
The entity sample
unique
boolean
false
false
Return an array of sample data or none
flush
boolean
No
false
Do a flush after saving the entity, false by default since we use transactions
transactional
boolean
No
true
Wrap the save in a ColdFusion transaction
Key
Type
Required
Default
Description
entity
any
Yes
---
The entity to save
forceInsert
boolean
No
false
Insert as new record whether it already exists or not
Key
Type
Required
Default
Description
entity
any
Yes
---
// merge a single entity back
ormService.merge( userEntity );
// merge an array of entities
collection = [entity1,entity2,entity3];
ormService.merge( collection );This function returns any
Key
Type
Required
Default
Description
entity
string
Yes
---
The entity name or entity object
ormService.deleteAll("Tags");var users = ORMService.newCriteria( entityName="User" )
.gt( "age", ormService.idCast( 30 ) )
.isTrue( "isActive" )
.list( max=30, offset=10, sortOrder="lname" );var post = ormService.get(1);
ormService.delete( post );
// Delete a flush immediately
ormService.delete( post, true );var user = ormService.new("User");
populateModel(user);
var user2 = ormService.new("User");
populateModel(user);
ormService.saveAll( [user1,user2] );// Let's get the session statistics
stats = ormService.getSessionStatistics;
// Lets output it
<cfoutput>
collection count: #stats.collectionCount# <br/>
collection keys: #stats.collectionKeys# <br/>
entity count: #stats.entityCount# <br/>
entity keys: #stats.entityKeys#
</cfoutput>var account = ormService.get("Account",1);
var account = ormService.get("Account",4);
var newAccount = ormService.get("Account",0);// Find a category according to the named value pairs I pass into this method
var category = ormService.findWhere(entityName="Category", criteria={isActive=true, label="Training"});
var user = ormService.findWhere(entityName="User", criteria={isActive=true, username=rc.username,password=rc.password});var md = ORMService.getEntityMetadata( entity );baseService.idCast( "User", "123" );function checkSomething( any User ){
// check if User is already in session
if( NOT ormService.sessionContains( arguments.User ) ){
// Not in hibernate session, so merge it in.
ormService.merge( arguments.User );
}
}currentUser = ormService.findByExample( session.user, true );var user = ormService.new("User");
populateModel(user);
ormService.save(user);
// Save with immediate flush
var user = ormService.new(entityName="User", lastName="Majano");
ormService.save(entity=user, flush=true);var pkField = ormService.getKey( "User" );Key
Type
Required
Default
Description
query
string
No
---
The HQL Query to execute
params
any
No
{}
This function returns numeric
Key
Type
Required
Default
Description
entityName
string
Yes
---
The name of the entity to delte
id
any
Yes
---
The ORM Service so you can do concatenated calls
Key
Type
Required
Default
Description
target
boolean
Yes
A boolean evaluator
success
closure
Yes
Key
Type
Required
Default
Description
entity
string
Yes
The entity name or entity object
propertyName
string
Yes
This function returns any
Key
Type
Required
Default
Description
entityName
string
Yes
---
id
any
Yes
---
Return the count of instances in the DB for the given entity name. You can also pass an optional where statement that can filter the count. Ex: count('User','age > 40 AND name="joe"'). You can even use named or positional parameters with this method: Ex: count('User','age > ? AND name = ?',[40,"joe"])
This function returns numeric
Retrieve all the instances from the passed in entity name using the id argument if specified. The id can be a list of IDs or an array of IDs or none to retrieve all. If the id is not found or returns null the array position will have an empty string in it in the specified order
You can use the readOnly argument to give you the entities as read only entities.
You can use the properties argument so this method can return to you array of structs instead of array of objects. The property list must include the as alias if not you will get positional keys.
Example Positional: properties="catID,category Example Aliases: properties="catID as id, category as category, role as role"
You can use the
Get a new entity object by entity name. You can also pass in a structure called properties that will be used to populate the new entity with or you can use optional named parameters to call setters within the new entity to have shorthand population.
This function returns the newly created entity
// My First Post
ormService.findIt("from Post as p where p.author='Luis Majano'");
// With positional parameters
ormService.findIt("from Post as p where p.author=?", ["Luis Majano"]);
// with a named parameter (since 0.5)
ormService.findIt("from Post as p where p.author=:author and p.isActive=:active", { author="Luis Majano",active=true} );// just delete
count = ormService.deleteByID("User",1);
// delete and flush
count = ormService.deleteByID("User",4,true);
// Delete several records, or at least try
count = ormService.deleteByID("User",[1,2,3,4]);baseService
.when(
!isNull( rc.createdDate ),
( service ) => service.autoCast( "User", "createdDate", rc.createdDate )
)
.when(
rc.search.len(),
( service ) => service.like( "name", rc.search ),
( service ) => service.isTrue( "search" )
)baseService.autoCast( "User", "createdDate", arguments.myDate );var account = ormService.getOrFail("Account",1);
var account = ormService.getOrFail("Account",4);
var newAccount = ormService.getOrFail("Account",0);Positional or named params
timeout
numeric
No
0
ignoreCase
boolean
No
false
datasource
string
No
A single ID or array of IDs
flush
boolean
No
false
transactional
boolean
No
From Property
Use transactions not
The closure to execute if the target is true
failure
closure
No
The closure to execute if the target is false
The property name
value
any
Yes
The property value
timeout
numeric
No
0
ignoreCase
boolean
No
false
datasource
string
No
Key
Type
Required
Default
Description
query
string
No
---
The HQL Query to execute
params
any
No
{}
Positional or named params
params
any
No
strucnew()
Named or positional parameters
Key
Type
Required
Default
Description
entityName
string
Yes
---
where
string
No
// My First Post
ormService.findOrFail("from Post as p where p.author='Luis Majano'");
// With positional parameters
ormService.findOrFail("from Post as p where p.author=?", ["Luis Majano"]);
// with a named parameter (since 0.5)
ormService.findOrFail("from Post as p where p.author=:author and p.isActive=:active", { author="Luis Majano",active=true} );// Get the count of instances for all books
ormService.count("Book");
// Get the count for users with age above 40 and named Bob
ormService.count("User","age > 40 AND name='Bob'");
// Get the count for users with passed in positional parameters
ormService.count("User","age > ? AND name=?",[40,'Bob']);
// Get the count for users with passed in named parameters
ormService.count("Post","title like :title and year = :year",{title="coldbox",year="2007"});Key
Type
Required
Default
Description
target
any
Yes
---
The entity to populate
qry
query
Yes
---
asStreamNo casting is necessary on the Id value type as we do this automatically for you.
This function returns array of entities found
Key
Type
Required
Default
Description
entityName
string
true
---
id
any
false
---
Key
Type
Required
Default
Description
target
any
Yes
---
The entity to populate
xml
any
Yes
---
Key
Type
Required
Default
Description
query
string
No
---
The HQL Query to execute
params
any
No
[runtime expression]
Key
Type
Required
Default
Description
target
any
Yes
---
The entity to populate
JSONString
string
Yes
---
Key
Type
Required
Default
Description
entityName
any
true
---
properties
struct
false
{}
Key
Type
Required
Default
entityName
string
Yes
---
useQueryCaching
boolean
No
Same as BaseService
queryCacheRegion
Key
Type
Required
Default
description
query
string
Yes
---
params
any
No
---
Key
Type
Required
Default
Description
entityName
string
Yes
---
criteria
struct
Yes
---
var user = ormService.populateFromQuery( ormService.new( "User" ), ormService.list( "User", { id=4 } ) );// Get all user entities
users = ORMService.getAll(entityName="User", sortOrder="email desc");
// Get all the following users by id's
users = ORMService.getAll("User","1,2,3");
// Get all the following users by id's as array
users = ORMService.getAll("User",[1,2,3,4,5]);var user = ormService.populateFromXML( ormService.new("User"), xml, "User");// find all blog posts
ormService.findAll("Post");
// with a positional parameters
ormService.findAll("from Post as p where p.author=?",['Luis Majano']);
// 10 posts from Luis Majano staring from 5th post ordered by release date
ormService.findAll("from Post as p where p.author=? order by p.releaseDate",['Luis majano'],offset=5,max=10);
// Using paging params
var query = "from Post as p where p.author='Luis Majano' order by p.releaseDate"
// first 20 posts
ormService.findAll(query=query,max=20)
// 20 posts starting from my 15th entry
ormService.findAll(query=query,max=20,offset=15);
// examples with named parameters
ormService.findAll("from Post as p where p.author=:author", {author='Luis Majano'})
ormService.findAll("from Post as p where p.author=:author", {author='Luis Majano'}, max=20, offset=5);
// query by example
user = ormService.new(entityName="User",firstName="Luis");
ormService.findAll( example=user );var user = ormService.populateFromJSON( ormService.new("User"), jsonString );// return empty post entity
var post = ormService.new("Post");
var user = ormService.new(entityName="User",properties={firstName="Luis", lastName="Majano", age="32", awesome=true});
var user = ormService.new("User",{fname="Luis",lname="Majano",cool=false,awesome=true});userService = ormService.createService("User");
userService = ormService.createService("User",true);
userService = ormService.createService("User",true,"MyFunkyUserCache");
// Remember you can use virtual entity services by autowiring them in via our DSL
component{
property name="userService" inject="entityService:User";
property name="postService" inject="entityService:Post";
}// delete all blog posts
ormService.deleteByQuery("from Post");
// delete query with positional parameters
ormService.deleteByQuery("from Post as b where b.author=? and b.isActive = :active",['Luis Majano',false]);
// Use query options
var query = "from User as u where u.isActive=false order by u.creationDate desc";
// first 20 stale inactive users
ormService.deleteByQuery(query=query,max=20);
// 20 posts starting from my 15th entry
ormService.deleteByQuery(query=query,max=20,offset=15,flush=true);
// examples with named parameters
ormService.deleteByQuery("from Post as p where p.author=:author", {author='Luis Majano'})posts = ormService.findAllWhere(entityName="Post", criteria={author="Luis Majano"});
users = ormService.findAllWhere(entityName="User", criteria={isActive=true});
artists = ormService.findAllWhere(entityName="Artist", criteria={isActive=true, artist="Monet"});The query to populate with
rowNumber
numeric
false
1
The row to use to populate with.
scope
string
No
---
Use scope injection instead of setter injection, no need of setters, just tell us what scope to inject to
trustedSetter
Boolean
No
false
Do not check if the setter exists, just call it, great for usage with onMissingMethod() and virtual properties
include
string
No
---
A list of columns to ONLY include in the population
exclude
string
No
---
A list of columns to exclude from the population
nullEmptyInclude
string
No
A list of keys to NULL when empty, specifically for ORM population. You can also specify "*" for all fields
nullEmptyExclude
string
No
A list of keys to NOT NULL when empty, specifically for ORM population. You can also specify "*" for all fields
composeRelationships
boolean
No
true
When true, will automatically attempt to compose relationships from memento
sortOrder
string
false
---
The sort orering of the array
readOnly
boolean
false
false
properties
string
false
If passed, you can retrieve an array of properties of the entity instead of the entire entity. Make sure you add aliases to the properties: Ex: 'catId as id'
asStream
boolean
false
false
Returns the result as a Java Stream using cbStreams
The xml string or xml document object to populate with
root
string
false
The xml root node to start the population with, by default it uses the XMLRoot.
scope
string
No
Use scope injection instead of setter injection, no need of setters, just tell us what scope to inject to
trustedSetter
Boolean
No
false
Do not check if the setter exists, just call it, great for usage with onMissingMethod() and virtual properties
include
string
No
A list of keys to ONLY include in the population
exclude
string
No
A list of keys to exclude from the population
nullEmptyInclude
string
No
A list of keys to NULL when empty, specifically for ORM population. You can also specify "*" for all fields
nullEmptyExclude
string
No
A list of keys to NOT NULL when empty, specifically for ORM population. You can also specify "*" for all fields
composeRelationships
boolean
No
true
When true, will automatically attempt to compose relationships from memento
Named or positional params
offset
numeric
No
0
max
numeric
No
0
timeout
numeric
No
0
ignoreCase
boolean
No
false
datasource
string
No
asStream
boolean
No
false
The JSON packet to use for population
scope
string
No
Use scope injection instead of setter injection, no need of setters, just tell us what scope to inject to
trustedSetter
Boolean
No
false
Do not check if the setter exists, just call it, great for usage with onMissingMethod() and virtual properties
include
string
No
A list of keys to ONLY include in the population
exclude
string
No
A list of keys to exclude from the population
nullEmptyInclude
string
No
A list of keys to NULL when empty, specifically for ORM population. You can also specify "*" for all fields
nullEmptyExclude
string
No
A list of keys to NOT NULL when empty, specifically for ORM population. You can also specify "*" for all fields
composeRelationships
boolean
No
true
When true, will automatically attempt to compose relationships from memento
A structure of name-value pairs to populate the new entity with
composeRelationships
boolean
false
true
Automatically attempt to compose relationships from the incoming properties memento
nullEmptyInclude
string
false
---
A list of keys to NULL when empty
nullEmptyExclude
string
false
---
A list of keys to NOT NULL when empty
ignoreEmpty
boolean
false
false
Ignore empty property values on populations
include
string
false
---
A list of keys to include in the population from the incoming properties memento
exclude
string
false
---
A list of keys to exclude in the population from the incoming properties memento
string
No
Same as BaseService
eventHandling
boolean
No
true
useTransactions
boolean
No
true
defaultAsQuery
boolean
No
true
datasource
string
No
The default app datasource
max
numeric
No
0
offfset
numeric
No
0
flush
boolean
No
false
transactional
boolean
No
From Property
Use transactions or not
datasource
string
false
The datasource to use or use the default datasource
A structure of criteria to filter on
sortOrder
string
false
---
The sort ordering
ignoreCase
boolean
false
false
timeout
numeric
false
0
asStream
boolean
false
false
Key
Type
Required
Default
Description
target
any
Yes
---
The entity to populate
memento
struct
Yes
---
INFO With composeRelationships=true, you can populate one-to-many, many-to-one, many-to-many, and one-to-one relationships from property values in the memento. For 'many-to-one' and 'one-to-one' relationships, the value of the property in the memento should be a single value of the primary key of the target entity to be loaded. For 'one-to-many' and 'many-to-many' relationships, the value of the property in the memento should a comma-delimited list or array of the primary keys of the target entities to be loaded.
var user = ormService.populate( ormService.new("User"), data );
// populate with includes only
var user = ormService.populate( ormService.new("User"), data, "fname,lname,email" );
//populate with excludes
var user = ormService.populate(target=ormService.new("User"),memento=data,exclude="id,setup,total" );
// populate with null values when value is empty string
var user = ormService.populate(target=ormService.new("User"),memento=data,nullEmptyInclude="lastName,dateOfBirth" );
// populate many-to-one relationship
var data = {
firstName = "Luis",
role = 1 // "role" is the name of the many-to-one relational property, and one is the key value
};
var user = ormService.populate( target=ormService.new("User"), memento=data, composeRelationships=true );
// the role relationship will be composed, and the value will be set to the appropriate instance of the Role model
// populate one-to-many relationship
var data = {
firstName = "Luis",
favColors = "1,2,3" ( or [1,2,3] ) // favColors is the name of the one-to-many relational property, and 1, 2 and 3 are key values of favColor models
};
var user = ormService.populate( target=ormService.new("User"), memento=data, composeRelationships=true );
// the favColors property will be set to an array of favColor entities
// only compose some relationships
var data = {
firstName = "Luis",
role = 1,
favColors = [ 1, 3, 19 ]
};
var user = ormService.populate( target=ormService.new("User"), memento=data, composeRelationships=true, exclude="favColors" );
// in this example, "role" will be composed, but "favColors" will be excludedThe structure of name-value pairs to try to populate the entity with
scope
string
No
Use scope injection instead of setter injection, no need of setters, just tell us what scope to inject to
trustedSetter
Boolean
No
false
Do not check if the setter exists, just call it, great for usage with onMissingMethod() and virtual properties
include
string
No
A list of keys to ONLY include in the population
exclude
string
No
A list of keys to exclude from the population
nullEmptyInclude
string
No
A list of keys to NULL when empty, specifically for ORM population. You can also specify "*" for all fields
nullEmptyExclude
string
No
A list of keys to NOT NULL when empty, specifically for ORM population. You can also specify "*" for all fields
composeRelationships
boolean
No
true
When true, will automatically attempt to compose relationships from memento
offset
numeric
No
0
Pagination offset
max
numeric
No
0
Max records to return
timeout
numeric
No
0
Query timeout
asQuery
boolean
No
false
Return query or array of objects
unique
boolean
No
false
Return a unique result
datasource
string
No
---
Use a specific or default datasource
asStream
boolean
No
false
Returns the result as a Java Stream using
Key
Type
Required
Default
Description
query
string
Yes
---
The valid HQL to process
params
array or struct
No
Positional or named parameters
List all of the instances of the passed in entity class name with or without any filtering of properties, no HQL needed.
You can pass in several optional arguments like a struct of filtering criteria, a sortOrder string, offset, max, ignorecase, and timeout. Caching for the list is based on the useQueryCaching class property and the cachename property is based on the queryCacheRegion class property.
// simple query
ormService.executeQuery( "select distinct a.accountID from Account a" );
// using with list of parameters
ormService.executeQuery(
"select distinct e.employeeID from Employee e where e.department = ? and e.created > ?",
[ 'IS', '01/01/2010' ]
);
// same query but with paging
ormService.executeQuery(
"select distinct e.employeeID from Employee e where e.department = ? and e.created > ?",
[ 'IS', '01/01/2010' ],
1,
30
);
// same query but with named params and paging
ormService.executeQuery(
"select distinct e.employeeID from Employee e where e.department = :dep and e.created > :created",
{ dep='Accounting', created='01/01/2010' },
10,
20
);
// GET FUNKY!!This function returns array if asQuery = false
This function returns a query if asQuery = true
This function returns a stream if asStream = true
Key
Type
Required
Default
Description
entityName
string
Yes
---
The entity to list
criteria
struct
No
aUsers = ormService.list(
entityName="User",
max=20,
offset=10
);
users = ormService.list( entityName="Art", timeout=10 );
users = ormService.list( "User", {isActive=false}, "lastName,firstName" );
users = ormService.list( "Comment", {postID=rc.postID}, "createdDate desc" );
qUsers = ormService.list( entityName="User", asQuery = true );A struct of filtering criteria for the listing
sortOrder
string
No
The sorting order of the listing
offset
numeric
No
0
Pagination offset
max
numeric
No
0
Max records to return
timeout
numeric
No
0
Query timeout
ignoreCase
boolean
No
false
Case insensitive or case sensitive searches, we default to case sensitive filtering.
asQuery
boolean
No
false
Return query or array of objects
asStream
boolean
No
false
Returns the result as a Java Stream using cbStreams