Home

Castle Stronghold

Table of contents

ActiveRecordBase API Document

Base class for all ActiveRecord classes. Implements all the functionality to simplify the code on the subclasses.

Constructors

ActiveRecordBase()

Constructs an ActiveRecordBase subclass.

Methods

Refresh()

Refresh the instance from the database.

Delete()

Deletes the instance from the database.

Update()

Persists the modification on the instance state to the database.

Create()

Creates (Saves) a new instance to the database.

Save()

Saves the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.

OnLoad(Object id)

Lifecycle method invoked during Load of the entity

ParameterDescription
id Missing documentation

OnDelete()

Lifecycle method invoked during Delete of the entity

OnUpdate()

Lifecycle method invoked during Update of the entity

OnSave()

Lifecycle method invoked during Save of the entity

FindDirty(Object id, IDictionary previousState, IDictionary currentState, IType[] types) : Int32[]

Called from Flush(). The return value determines whether the entity is updated

ParameterDescription
id Missing documentation
previousState Missing documentation
currentState Missing documentation
types Missing documentation

IsUnsaved() : Object

Called when a transient entity is passed to SaveOrUpdate.

PostFlush()

Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.

PreFlush()

Called before a flush

BeforeDelete(IDictionary adapter)

Hook to perform additional tasks before removing the object instance representation from the database.

ParameterDescription
adapter Missing documentation

BeforeLoad(IDictionary adapter) : Boolean

Hook to transform the read data from the database before populating the object instance

ParameterDescription
adapter Missing documentation

BeforeSave(IDictionary state) : Boolean

Hook to change the object state before saving it.

ParameterDescription
state Missing documentation

ToString() : String

Missing summary

Create(Object instance)

Creates (Saves) a new instance to the database.

ParameterDescription
instance The ActiveRecord instance to be created on the database

Delete(Object instance)

Deletes the instance from the database.

ParameterDescription
instance The ActiveRecord instance to be deleted

Refresh(Object instance)

Refresh the instance from the database.

ParameterDescription
instance The ActiveRecord instance to be reloaded

DeleteAll(Type type)

Deletes all rows for the specified ActiveRecord type

Quick Note

This method is usually useful for test cases.

ParameterDescription
type ActiveRecord type on which the rows on the database should be deleted

DeleteAll(Type type, String where)

Deletes all rows for the specified ActiveRecord type that matches the supplied HQL condition

Quick Note

This method is usually useful for test cases.

ParameterDescription
type ActiveRecord type on which the rows on the database should be deleted
where HQL condition to select the rows to be deleted

DeleteAll(Type targetType, IEnumerable pkValues) : Int32

Deletes all targetType objects, based on the primary keys supplied on pkValues.

ParameterDescription
targetType The target ActiveRecord type
pkValues A list of primary keys

Update(Object instance)

Persists the modification on the instance state to the database.

ParameterDescription
instance The ActiveRecord instance to be updated on the database

Save(Object instance)

Saves the instance to the database. If the primary key is unitialized it creates the instance on the database. Otherwise it updates it.

If the primary key is assigned, then you must invoke Castle.ActiveRecord.ActiveRecordBase.Create or Castle.ActiveRecord.ActiveRecordBase.Update instead.

ParameterDescription
instance The ActiveRecord instance to be saved

Execute(Type targetType, NHibernateDelegate call, Object instance) : Object

Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.

ParameterDescription
targetType The target ActiveRecordType
call The delegate instance
instance The ActiveRecord instance

EnumerateQuery(IActiveRecordQuery query) : IEnumerable

Missing summary

ParameterDescription
query Missing documentation

ExecuteQuery(IActiveRecordQuery query) : Object

Missing summary

ParameterDescription
query Missing documentation

CountAll(Type targetType) : Int32

Returns the number of records of the specified type in the database

Example


[ActiveRecord]
public class User : ActiveRecordBase
{
  ...
  
  public static int CountAllUsers()
  {
    return CountAll(typeof(User));
  }
}

ParameterDescription
targetType Type of the target.

CountAll(Type targetType, String filter, Object[] args) : Int32

Returns the number of records of the specified type in the database

Example


[ActiveRecord]
public class User : ActiveRecordBase
{
  ...
  
  public static int CountAllUsersLocked()
  {
    return CountAll(typeof(User), "IsLocked = ?", true);
  }
}

ParameterDescription
targetType Type of the target.
filter A sql where string i.e. Person=? and DOB > ?
args Positional parameters for the filter string

Exists(Type targetType) : Boolean

Check if there is any records in the db for the target type

ParameterDescription
targetType Type of the target.

Exists(Type targetType, String filter, Object[] args) : Boolean

Check if there is any records in the db for the target type

ParameterDescription
targetType Type of the target.
filter A sql where string i.e. Person=? and DOB > ?
args Positional parameters for the filter string

Exists(Type targetType, Object id) : Boolean

Check if the id exists in the database.

ParameterDescription
targetType Type of the target.
id The id to check on

FindAll(Type targetType) : Array

Returns all instances found for the specified type.

ParameterDescription
targetType

FindAll(Type targetType, Order[] orders, ICriterion[] criterias) : Array

Returns all instances found for the specified type using sort orders and criterias.

ParameterDescription
targetType
orders
criterias

FindAll(Type targetType, ICriterion[] criterias) : Array

Returns all instances found for the specified type using criterias.

ParameterDescription
targetType
criterias

FindAllByProperty(Type targetType, String property, Object value) : Array

Finds records based on a property value - automatically converts null values to IS NULL style queries.

ParameterDescription
targetType The target type
property A property name (not a column name)
value The value to be equals to

FindAllByProperty(Type targetType, String orderByColumn, String property, Object value) : Array

Finds records based on a property value - automatically converts null values to IS NULL style queries.

ParameterDescription
targetType The target type
orderByColumn The column name to be ordered ASC
property A property name (not a column name)
value The value to be equals to

FindByPrimaryKey(Type targetType, Object id) : Object

Finds an object instance by an unique ID

ParameterDescription
targetType The AR subclass type
id ID value

FindByPrimaryKey(Type targetType, Object id, Boolean throwOnNotFound) : Object

Finds an object instance by an unique ID

ParameterDescription
targetType The AR subclass type
id ID value
throwOnNotFoundtrue if you want to catch an exception if the object is not found

FindFirst(Type targetType, Order[] orders, ICriterion[] criterias) : Object

Searches and returns the first row.

ParameterDescription
targetType The target type
orders The sort order - used to determine which record is the first one
criterias The criteria expression

FindFirst(Type targetType, ICriterion[] criterias) : Object

Searches and returns the first row.

ParameterDescription
targetType The target type
criterias The criteria expression

FindOne(Type targetType, ICriterion[] criterias) : Object

Searches and returns a row. If more than one is found, throws Castle.ActiveRecord.Framework.ActiveRecordException

ParameterDescription
targetType The target type
criterias The criteria expression

SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, Order[] orders, ICriterion[] criterias) : Array

Returns a portion of the query results (sliced)

ParameterDescription
targetType Missing documentation
firstResult Missing documentation
maxResults Missing documentation
orders Missing documentation
criterias Missing documentation

SlicedFindAll(Type targetType, Int32 firstResult, Int32 maxResults, ICriterion[] criterias) : Array

Returns a portion of the query results (sliced)

ParameterDescription
targetType Missing documentation
firstResult Missing documentation
maxResults Missing documentation
criterias Missing documentation

Execute(NHibernateDelegate call) : Object

Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.

ParameterDescription
call The delegate instance

Google
Search WWW Search castleproject.org