ColdBox Platform Version 2.6.4

coldbox.system.orm.hibernate
Class BaseORMService

WEB-INF.cftags.component
        extended by coldbox.system.orm.hibernate.BaseORMService
Direct Known Subclasses:
VirtualEntityService , ORMService

public class BaseORMService
extends WEB-INF.cftags.component

******************************************************************************* Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.coldbox.org | www.luismajano.com | www.ortussolutions.com ******************************************************************************* Author : Luis Majano Description : This is a helper ORM service that will help you abstract some complexities when dealing with CF's ORM via Hibernate. You can use this service in its concrete form or you can inherit from it and extend it. TODO: - Add dynamic findBy methods - Add dynamic countBy methods - Add dynamic getBy methods - Dynamic entity methods for the following methods: - new{entityName}() - exists{entityName}() - get{entityName}() - getAll{entityName}() - count{entityName}() - Add find methods by criteria with projections - Add validations maybe via Hyrule, but more implicit and mixin methods - Add dml style batch updates ----------------------------------------------------------------------->


Constructor Summary
init([string queryCacheRegion='ORMService.defaultCache'], [boolean useQueryCaching='false'])
          Constructor
 
Method Summary
 string GETQUERYCACHEREGION()
          get: The queryCacheRegion name property for all query caching produced in this service
 boolean GETUSEQUERYCACHING()
          get: The bit that tells the service to enable query caching, disabled by default
 void SETQUERYCACHEREGION(string queryCacheRegion)
          set: The queryCacheRegion name property for all query caching produced in this service
 void SETUSEQUERYCACHING(boolean useQueryCaching)
          set: The bit that tells the service to enable query caching, disabled by default
 void clear()
          Clear the session removes all the entities that are loaded or created in the session
 numeric count(string entityName, [string where=''], [any params='[runtime expression]'])
          Return the count of records in the DB for the given entity name
 numeric countWhere(string entityName)
          Returns the count by passing name value pairs as arguments to this function
 any createService(string entityName, [boolean useQueryCaching='[runtime expression]'], [string queryCacheRegion='[runtime expression]'])
          Create a virtual abstract service for a specfic entity
 void delete(any entity, [boolean flush='false'])
          Delete an entity using hibernate transactions
 boolean deleteByID(string entityName, any id, [boolean flush='false'])
          Delete using an entity name and an incoming id, you can also flush the session if needed The method returns false if the passed in entityName and id is not found in the database
 void deleteByQuery(string query, [any params], [numeric max='0'], [numeric offset='0'], [boolean flush='false'])
          Delete by using an HQL query and iterating via the results, it is not performing a delete query but it actually is a select query that should retrieve objects to remove
 numeric deleteWhere(string entityName)
          Deletes entities by using name value pairs as arguments to this function
 void evict(string entityName, [string collectionName], [any id])
          Evict an entity from session, the id can be a string or structure for the primary key You can also pass in a collection name to evict from the collection
 void evictEntity(any entity)
          Evict entity objects from session
 void evictQueries([string cacheName])
          Evict all queries in the default cache or the cache region passed
 any executeQuery(string query, [any params='[runtime expression]'], [numeric offset='0'], [numeric max='0'], [numeric timeout='0'], [boolean asQuery='true'])
          Allows the execution of HQL queries using several nice arguments and returns either an array of entities or a query as specified by the asQuery argument
 boolean exists(any entityName, any id)
          Checks if the given entityName and id exists in the database
 any find([string query], [any params='[runtime expression]'], [any example])
          Finds and returns the first result for the given query or null if no entity was found
 array findAll([string query], [any params='[runtime expression]'], [numeric offset='0'], [numeric max='0'], [any example])
          Find all the entities for the specified query and params or example
 array findAllWhere(string entityName)
          Find one entity or null if not found according to the passed in name value pairs into the function ex: findWhere(entityName="Category", category="Training"), findWhere(entityName="Users", age=40);
 any findWhere(string entityName)
          Find one entity or null if not found according to the passed in name value pairs into the function ex: findWhere(entityName="Category", category="Training"), findWhere(entityName="Users", age=40);
 any get(string entityName, any id)
          Get an entity using a primary key, if the id is not found this method returns null
 array getAll(string entityName, [any id])
          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
 any getKey(string entityName)
          Returns the key (id field) of a given entity, either simple or composite keys
 array getPropertyNames(string entityName)
          Returns the Property Names of the entity
 struct getSessionStatistics()
          Information about the first-level (session) cache for the current session
 string getTableName(string entityName)
          Returns the table name of the of the entity
 boolean isSessionDirty()
          Checks if the session contains dirty objects that are awaiting persistence
 any list(string entityName, [struct criteria='[runtime expression]'], [string sortOrder=''], [numeric offset='0'], [numeric max='0'], [numeric timeout='0'], [boolean ignoreCase='false'], [boolean asQuery='true'])
          List all of the instances of the passed in entity class name
 void merge(any entity)
          Merge an entity or array of entities back into the session
 any new(string entityName)
          Get a new entity object by entity name and you can pass in any named parameter and the method will try to set it for you
 any onMissingMethod([String missingMethodName], [Struct missingMethodArguments])
          A nice onMissingMethod template to create awesome dynamic methods
 void refresh(any entity)
          Refresh the state of an entity or array of entities from the database
 void save(any entity, [boolean forceInsert='false'], [boolean flush='false'])
          Save an entity using hibernate transactions
 boolean sessionContains(any entity)
          Checks if the current session contains the passed in entity
 
Methods inherited from class WEB-INF.cftags.component
 

Constructor Detail

init

public init([string queryCacheRegion='ORMService.defaultCache'], [boolean useQueryCaching='false'])
Constructor

Parameters:
queryCacheRegion
useQueryCaching
Method Detail

GETQUERYCACHEREGION

public string GETQUERYCACHEREGION()
get: The queryCacheRegion name property for all query caching produced in this service


GETUSEQUERYCACHING

public boolean GETUSEQUERYCACHING()
get: The bit that tells the service to enable query caching, disabled by default


SETQUERYCACHEREGION

public void SETQUERYCACHEREGION(string queryCacheRegion)
set: The queryCacheRegion name property for all query caching produced in this service

Parameters:
queryCacheRegion

SETUSEQUERYCACHING

public void SETUSEQUERYCACHING(boolean useQueryCaching)
set: The bit that tells the service to enable query caching, disabled by default

Parameters:
useQueryCaching

clear

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


count

public numeric count(string entityName, [string where=''], [any params='[runtime expression]'])
Return the count of records 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 params with this method: Ex: count('User','age > ? AND name = ?',[40,"joe"])

Parameters:
entityName
where
params

countWhere

public numeric countWhere(string entityName)
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");

Parameters:
entityName

createService

public any createService(string entityName, [boolean useQueryCaching='[runtime expression]'], [string queryCacheRegion='[runtime expression]'])
Create a virtual abstract service for a specfic entity.

Parameters:
entityName
useQueryCaching
queryCacheRegion

delete

public void delete(any entity, [boolean flush='false'])
Delete an entity using hibernate transactions. The entity argument can be a single entity or an array of entities. You can optionally flush the session also after committing

Parameters:
entity
flush

deleteByID

public boolean deleteByID(string entityName, any id, [boolean flush='false'])
Delete using an entity name and an incoming id, you can also flush the session if needed The method returns false if the passed in entityName and id is not found in the database.

Parameters:
entityName
id
flush

deleteByQuery

public void deleteByQuery(string query, [any params], [numeric max='0'], [numeric offset='0'], [boolean flush='false'])
Delete by using an HQL query and iterating via the results, it is not performing a delete query but it actually is a select query that should retrieve objects to remove

Parameters:
query
params
max
offset
flush

deleteWhere

public numeric deleteWhere(string entityName)
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);

Parameters:
entityName

evict

public void evict(string entityName, [string collectionName], [any id])
Evict an entity from session, the id can be a string or structure for the primary key You can also pass in a collection name to evict from the collection

Parameters:
entityName
collectionName
id

evictEntity

public void evictEntity(any entity)
Evict entity objects from session. The argument can be one persistence entity or an array of entities

Parameters:
entity

evictQueries

public void evictQueries([string cacheName])
Evict all queries in the default cache or the cache region passed

Parameters:
cacheName

executeQuery

public any executeQuery(string query, [any params='[runtime expression]'], [numeric offset='0'], [numeric max='0'], [numeric timeout='0'], [boolean asQuery='true'])
Allows the execution of HQL queries using several nice arguments and returns either an array of entities or a query as specified by the asQuery argument. The params filtering can be using named or positional.

Parameters:
query
params
offset
max
timeout
asQuery

exists

public boolean exists(any entityName, any id)
Checks if the given entityName and id exists in the database

Parameters:
entityName
id

find

public any find([string query], [any params='[runtime expression]'], [any example])
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.

Parameters:
query
params
example

findAll

public array findAll([string query], [any params='[runtime expression]'], [numeric offset='0'], [numeric max='0'], [any example])
Find all the entities for the specified query and params or example

Parameters:
query
params
offset
max
example

findAllWhere

public array findAllWhere(string entityName)
Find one entity or null if not found according to the passed in name value pairs into the function ex: findWhere(entityName="Category", category="Training"), findWhere(entityName="Users", age=40);

Parameters:
entityName

findWhere

public any findWhere(string entityName)
Find one entity or null if not found according to the passed in name value pairs into the function ex: findWhere(entityName="Category", category="Training"), findWhere(entityName="Users", age=40);

Parameters:
entityName

get

public any get(string entityName, any id)
Get an entity using a primary key, if the id is not found this method returns null

Parameters:
entityName
id

getAll

public array getAll(string entityName, [any id])
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

Parameters:
entityName
id

getKey

public any getKey(string entityName)
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

Parameters:
entityName

getPropertyNames

public array getPropertyNames(string entityName)
Returns the Property Names of the entity

Parameters:
entityName

getSessionStatistics

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


getTableName

public string getTableName(string entityName)
Returns the table name of the of the entity

Parameters:
entityName

isSessionDirty

public boolean isSessionDirty()
Checks if the session contains dirty objects that are awaiting persistence


list

public any list(string entityName, [struct criteria='[runtime expression]'], [string sortOrder=''], [numeric offset='0'], [numeric max='0'], [numeric timeout='0'], [boolean ignoreCase='false'], [boolean asQuery='true'])
List all of the instances of the passed in entity class name. 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.

Parameters:
entityName
criteria
sortOrder
offset
max
timeout
ignoreCase
asQuery

merge

public void merge(any entity)
Merge an entity or array of entities back into the session

Parameters:
entity

new

public any new(string entityName)
Get a new entity object by entity name and you can pass in any named parameter and the method will try to set it for you.

Parameters:
entityName

onMissingMethod

public any onMissingMethod([String missingMethodName], [Struct missingMethodArguments])
A nice onMissingMethod template to create awesome dynamic methods.

Parameters:
missingMethodName
missingMethodArguments

refresh

public void refresh(any entity)
Refresh the state of an entity or array of entities from the database

Parameters:
entity

save

public void save(any entity, [boolean forceInsert='false'], [boolean flush='false'])
Save an entity using hibernate transactions. You can optionally flush the session also

Parameters:
entity
forceInsert
flush

sessionContains

public boolean sessionContains(any entity)
Checks if the current session contains the passed in entity

Parameters:
entity

ColdBox Platform Version 2.6.4