All pages
Powered by GitBook
1 of 62

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...

Criteria Queries

These methods allows you to tap into the Criteria Queries API so you can do fluent and functional queries with your ORM objects.

Service Methods

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:

getRestrictions

Get our hibernate org.hibernate.criterion.Restrictions proxy object that will help you produce criterias.

Returns

  • This function returns an instance of cborm.models.criterion.Restrictions

Examples

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();
API Docs

Creation - Population

These methods allow you to create entities and populate them from external data like structures, json, xml, queries and much more.

Counters

These methods allow you to do counting on entities with or without filtering.

Finders

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.

Saving Entities

Querying

These methods are used for doing a-la-carte querying of entities with extra pizzaz!

ORM Session

Getters

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.

Deleting Entities

These methods allow you to delete one or more entities in cascade style or bulk styles.

Utility Methods

getPropertyNames

Returns the persisted Property Names of the entity in array format

Returns

  • This function returns array

Arguments

Examples

evict

Evict entity object(s) from the hibernate session or first-level cache.

  • An entity object

  • An array of entity objects

exists

Checks if the given entityName and id exists in the database, this method does not load the entity into session. A very useful approach to check for data existence.

Returns

  • This function returns boolean

getTableName

Returns the table name of the passed in entity

Returns

  • This function returns string

evictQueries

Evict all queries in the default cache or the cache region that is passed in.

Returns

  • This function returns void

getKeyValue

Get the unique identifier value for the passed in entity, or null if the instance is not in session

Returns

  • This function returns any

isDirty

Verifies if the passed in entity has dirty values or not since loaded from the database.

Returns

  • This function returns true if the entity values have been changed since loaded into the hibernate session, else false

refresh

Refresh the state of an entity or array of entities from the database

Returns

  • This function returns back the BaseORMService (this)

deleteWhere

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);

Returns

  • This function returns numeric

isSessionDirty

Checks if the session contains dirty objects that are awaiting persistence

Returns

  • This function returns boolean

nullValue

Produce a null value that can be used anywhere you like!

Returns

  • A null value

Entity Convenience Methods

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");
Returns
  • This function returns void

Arguments

Key

Type

Required

Description

entities

any

Yes

The argument can be one persistence entity or an array of entities to evict

Examples

ormService.evict( thisEntity );
Arguments

Key

Type

Required

Default

Description

entity

string

Yes

---

Examples

var persistedTable = ormService.getTableName( "Category" );
Arguments

Key

Type

Required

Default

Description

entity

string

Yes

---

The entity to inspect for it's id

Examples

var pkValue = ormService.getKeyValue( "User" );
Arguments

Key

Type

Required

Default

Description

entity

Any

Yes

---

The entity object

Examples

if( ormService.isDirty( entity ) ){
    // The values have been modified
    log.debug( "entity values modified", ormService.getDirtyPropertyNames( entity ) );
}
Arguments

Key

Type

Required

Default

Description

entity

any

Yes

---

Examples

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

Examples

Arguments

Key

Type

Required

Default

Description

datasource

string

false

---

The default or specific datasource to use

Examples

// Check if by this point we have a dirty session, then flush it
if( ormService.isSessionDirty() ){
  ORMFlush();
}
Examples
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");

Arguments

Key

Type

Required

Default

Description

entityName

any

Yes

---

id

any

Yes

---

Examples

Arguments

Key

Type

Required

Default

Description

cacheName

string

No

---

datasource

string

No

---

Examples

deleteAll

Deletes all the entity records found in the database in a transaction safe matter and returns the number of records removed

This method will respect cascading deletes if any

Returns

  • This function returns numeric

Arguments

Examples

evictCollection

Evict all the collection or association data for a given entity name and collection name from the secondary cache ONLY, not the hibernate session.

Evict an entity name with or without an ID from the secondary cache ONLY, not the hibernate session

Returns

  • This function returns void

Arguments

Examples

newCriteria

Get a brand new criteria builder object to do criteria queries with (See ORM:CriteriaBuilder)

Returns

  • This function returns coldbox.system.orm.hibernate.CriteriaBuilder

Arguments

Examples

delete

Delete an entity using safe transactions. The entity argument can be a single entity or an array of entities. You can optionally flush the session also after committing.

This method will respect cascading deletes if any

Returns

  • This function returns void

Arguments

Examples

getEntityGivenName

Returns the entity name from a given entity object via session lookup or if new object via metadata lookup

Returns

  • This function returns string

Arguments

Examples

clear

Clear the session removes all the entities that are loaded or created in the session. This clears the first level cache and removes the objects that are not yet saved to the database.

Returns

  • This function returns the base service reference (this)

Arguments

Examples

getDirtyPropertyNames

Get an array of property names that that have been changed from the original loaded session state.

Returns

  • An array of property names

Arguments

Examples

saveAll

Saves an array of passed entities in specified order and transaction safe

Returns

  • This function returns void

Arguments

Examples

getSessionStatistics

Information about the first-level (session) cache for the current session

Returns

  • This function returns struct

Arguments

Examples

get

Get an entity using a primary key, if the id is not found this method returns null. You can also pass an id = 0 and the service will return to you a new entity.

No casting is necessary on the Id value type as we do this automatically for you.

Returns

  • This function returns any

Arguments

Examples

findWhere

Find one entity (or null if not found) according to a criteria structure ex: findWhere(entityName="Category", {category="Training"}), findWhere(entityName="Users",{age=40,retired=false});

Returns

  • This function returns any

Arguments

Examples

countWhere

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");

Returns

  • This function returns numeric

Arguments

Examples

getEntityMetadata

This method will return to you the hibernate's metadata for a specific entity.

Returns

  • The Hibernate Java ClassMetadata Object (https://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/metadata/ClassMetadata.html)

Arguments

Examples

idCast

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!

Returns

  • This function returns the value casted to the right Java type

Arguments

Examples

sessionContains

Checks if the current hibernate session contains the passed in entity.

Returns

  • This function returns boolean

Arguments

Examples

findByExample

Find all/single entities by example

Returns

  • This function returns array

Arguments

Examples

save

Save an entity using hibernate transactions or not. You can optionally flush the session also.

Returns

  • This function returns void

Arguments

Examples

findit

Finds and returns the first result for the given query or null if no entity was found. You can either use the query and params combination or send in an example entity to find.

Returns

  • This function returns any

deleteByID

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

when

This method gives you the ability to fluently create chains of executions by evaluating the incoming target as a boolean. If true it will execute the success closure, else the failure closure if passed.

Returns

autoCast

This method allows you to cast any value to the appropriate type in Java for the property passed in. The entity argument can be the entity name or an entity object.

Returns

  • This function returns the value casted to the right Java type

merge

Merge an entity or array of entities back into the session

Returns

  • Same entity if one passed, array if an array of entities passed.

getOrFail

Get an entity using a primary key, if the id is not found this method throws an EntityNotFound Exception

No casting is necessary on the Id value type as we do this automatically for you.

getKey

Returns the key (id field) of a given entity, either simple or composite keys.

  • If the key is a simple pk then it will return a string, if it is a composite key then it returns an array.

  • If the key cannot be identified then a blank string is returned.

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

Arguments

Key

Type

Required

Default

Description

entity

any

Yes

---

Examples

// merge a single entity back
ormService.merge( userEntity );
// merge an array of entities
collection = [entity1,entity2,entity3];
ormService.merge( collection );
Returns
  • This function returns any

Arguments

Key

Type

Required

Default

Description

entity

string

Yes

---

The entity name or entity object

Examples

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" );
Arguments

Key

Type

Required

Default

Description

query

string

No

---

The HQL Query to execute

params

any

No

{}

Examples

Returns
  • This function returns numeric

Arguments

Key

Type

Required

Default

Description

entityName

string

Yes

---

The name of the entity to delte

id

any

Yes

---

Examples

The ORM Service so you can do concatenated calls

Arguments

Key

Type

Required

Default

Description

target

boolean

Yes

A boolean evaluator

success

closure

Yes

Examples

Arguments

Key

Type

Required

Default

Description

entity

string

Yes

The entity name or entity object

propertyName

string

Yes

Examples

Returns
  • This function returns any

Arguments

Key

Type

Required

Default

Description

entityName

string

Yes

---

id

any

Yes

---

Examples

findOrFail

Finds and returns the first result for the given query or throws an exception if not found, this method delegates to the findIt() method

Returns

  • This function returns any

  • This function could throw an EntityNotFound exception

Arguments

Examples

count

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"])

Returns

  • This function returns numeric

Arguments

Examples

populateFromQuery

Populate an entity with a query object. Make sure the names of the columns match the keys in the object.

Returns

  • This function returns the populated object

getAll

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

populateFromXML

Populate an entity with an XML packet. Make sure the names of the elements match the keys in the structure.

Returns

  • This function returns the populated object

findAll

Find all the entities for the specified query, named or positional arguments or by an example entity

Returns

  • This function returns array

populateFromJSON

Populate an entity with a JSON structure packet. Make sure the names of the properties match the keys in the structure.

Returns

  • This function returns the populated object

new

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.

Returns

  • This function returns the newly created entity

createService

Create a virtual service for a specific entity. Basically a new service layer that inherits from the BaseORMService object but no need to pass in entity names, they are bound to the entity name passed here.

Returns

  • This function returns VirtualEntityService

deleteByQuery

Delete by using an HQL query and iterating via the results. It is not performing a delete query but is a select query that should retrieve objects to remove

Returns

  • This function returns void

findAllWhere

Find all entities according to criteria structure. Ex: findAllWhere(entityName="Category", {category="Training"}), findAllWhere(entityName="Users", {age=40,retired=true});

Returns

  • This function returns array

// 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"});
Arguments

Key

Type

Required

Default

Description

target

any

Yes

---

The entity to populate

qry

query

Yes

---

Examples

asStream
boolean argument to get either an array of objects or a Java stream via cbStreams.

No casting is necessary on the Id value type as we do this automatically for you.

Returns

  • This function returns array of entities found

Arguments

Key

Type

Required

Default

Description

entityName

string

true

---

id

any

false

---

Examples

Arguments

Key

Type

Required

Default

Description

target

any

Yes

---

The entity to populate

xml

any

Yes

---

Examples

Arguments

Key

Type

Required

Default

Description

query

string

No

---

The HQL Query to execute

params

any

No

[runtime expression]

Examples

Arguments

Key

Type

Required

Default

Description

target

any

Yes

---

The entity to populate

JSONString

string

Yes

---

Examples

Arguments

Key

Type

Required

Default

Description

entityName

any

true

---

properties

struct

false

{}

Examples

Arguments

Key

Type

Required

Default

entityName

string

Yes

---

useQueryCaching

boolean

No

Same as BaseService

queryCacheRegion

Examples

Arguments

Key

Type

Required

Default

description

query

string

Yes

---

params

any

No

---

Examples

Arguments

Key

Type

Required

Default

Description

entityName

string

Yes

---

criteria

struct

Yes

---

Examples

Ortus Solutions Artifacts Serverapidocs.ortussolutions.com

populate

Populate an entity with a structure of name-value pairs. Make sure the names of the properties match the keys in the structure.

Returns

  • This function returns the populated object

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

Logo
Arguments

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.

Examples

executeQuery

Allows the execution of Custom HQL queries with binding, pagination, and many options. Underlying mechanism is ORMExecuteQuery. The params filtering can be using named or positional.

Returns

This function returns multiple formats:

  • array of objects

  • array of structs

  • query

  • cbStream

Arguments

Examples

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 excluded

The 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

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!!
cbStreams
Returns
  • This function returns array if asQuery = false

  • This function returns a query if asQuery = true

  • This function returns a stream if asStream = true

Arguments

Key

Type

Required

Default

Description

entityName

string

Yes

---

The entity to list

criteria

struct

No

Examples

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