C# Class Castle.ActiveRecord.ActiveRecordBase

Inheritance: ActiveRecordHooksBase
Mostrar archivo Open project: nats/castle-1.0.3-mono Class Usage Examples

Protected Properties

Property Type Description
holder ISessionFactoryHolder

Public Methods

Method Description
Asc ( ) : NHibernate.Criterion.Order[]

Ascending Order

Returns an array of Ascending Order instances specifing which properties to use to order a result.

Create ( ) : void

Creates (Saves) a new instance to the database.

If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.

CreateAndFlush ( ) : void

Creates (Saves) a new instance to the database.

Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.

Delete ( ) : void

Deletes the instance from the database.

If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.

DeleteAndFlush ( ) : void

Deletes the instance from the database.

Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.

Desc ( ) : NHibernate.Criterion.Order[]

Descending Order

Returns an array of Descending Order instances specifing which properties to use to order a result.

ExecuteQuery ( IActiveRecordQuery query ) : object

Executes the query.

Refresh ( ) : void

Refresh the instance from the database.

Save ( ) : void

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

If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.

SaveAndFlush ( ) : void

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

Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.

SaveCopy ( ) : object

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

If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.

SaveCopyAndFlush ( ) : object

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

Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.

ToString ( ) : String

Return the type of the object with its PK value. Useful for logging/debugging

Update ( ) : void

Persists the modification on the instance state to the database.

If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.

UpdateAndFlush ( ) : void

Persists the modification on the instance state to the database.

Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.

Protected Methods

Method Description
Count ( Type targetType ) : int

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

Count ( Type targetType, DetachedCriteria detachedCriteria ) : int

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

Count ( Type targetType, ICriterion criteria ) : int

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

Count ( Type targetType, string filter ) : int

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

Create ( object instance ) : void

Creates (Saves) a new instance to the database.

CreateAndFlush ( object instance ) : void

Creates (Saves) a new instance to the database and flushes the session.

Delete ( object instance ) : void

Deletes the instance from the database.

DeleteAll ( Type targetType, IEnumerable pkValues ) : int

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

DeleteAll ( Type type ) : void

Deletes all rows for the specified ActiveRecord type

This method is usually useful for test cases.

DeleteAll ( Type type, String where ) : void

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

This method is usually useful for test cases.

DeleteAndFlush ( object instance ) : void

Deletes the instance from the database and flushes the session.

EnumerateQuery ( IActiveRecordQuery query ) : IEnumerable

Enumerates the query Note: only use if you expect most of the values to exist on the second level cache.

Execute ( NHibernateDelegate call ) : object

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

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

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

Exists ( Type targetType ) : bool

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

Exists ( Type targetType, DetachedCriteria detachedCriteria ) : bool

Check if any instance matching the criteria exists in the database.

Exists ( Type targetType, object id ) : bool

Check if the id exists in the database.

Exists ( Type targetType, string filter ) : bool

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

FindAll ( Type targetType ) : Array

Returns all instances found for the specified type.

FindAll ( Type targetType, DetachedCriteria detachedCriteria ) : Array

Returns all instances found for the specified type according to the criteria

FindAll ( Type targetType, NHibernate.Criterion.Order orders ) : Array

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

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.

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

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

FindByPrimaryKey ( Type targetType, object id ) : object

Finds an object instance by an unique ID

FindByPrimaryKey ( Type targetType, object id, bool throwOnNotFound ) : object

Finds an object instance by an unique ID

FindFirst ( Type targetType ) : object

Searches and returns the first row.

FindFirst ( Type targetType, DetachedCriteria detachedCriteria ) : object

Searches and returns the first row.

FindFirst ( Type targetType, NHibernate.Criterion.Order orders ) : object

Searches and returns the first row.

FindOne ( Type targetType ) : object

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

FindOne ( Type targetType, DetachedCriteria criteria ) : object

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

Refresh ( object instance ) : void

Refresh the instance from the database.

Replicate ( object instance, NHibernate.ReplicationMode replicationMode ) : void

From NHibernate documentation: Persist all reachable transient objects, reusing the current identifier values. Note that this will not trigger the Interceptor of the Session.

Save ( object instance ) : void

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 Create() or Update() instead.

SaveAndFlush ( object instance ) : void

Saves the instance to the database and flushes the session. 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 Create() or Update() instead.

SaveCopy ( object instance ) : object

Saves a copy of 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 Create() or Update() instead.

SaveCopyAndFlush ( object instance ) : object

Saves a copy of the instance to the database and flushes the session. 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 Create() or Update() instead.

SlicedFindAll ( Type targetType, int firstResult, int maxResults ) : Array

Returns a portion of the query results (sliced)

SlicedFindAll ( Type targetType, int firstResult, int maxResults, DetachedCriteria criteria ) : Array

Returns a portion of the query results (sliced)

SlicedFindAll ( Type targetType, int firstResult, int maxResults, NHibernate.Criterion.Order orders ) : Array

Returns a portion of the query results (sliced)

SlicedFindAll ( Type targetType, int firstResult, int maxResults, NHibernate.Criterion.Order orders, DetachedCriteria criteria ) : Array

Returns a portion of the query results (sliced)

Update ( object instance ) : void

Persists the modification on the instance state to the database.

UpdateAndFlush ( object instance ) : void

Persists the modification on the instance state to the database and flushes the session.

Private Methods

Method Description
AddOrdersToCriteria ( ICriteria criteria, IEnumerable orders ) : void
EnsureInitialized ( Type type ) : void
GetModel ( Type arType ) : ActiveRecordModel

Internally used

InternalCreate ( object instance, bool flush ) : void

Creates (Saves) a new instance to the database.

InternalDelete ( object instance, bool flush ) : void

Deletes the instance from the database.

InternalSave ( object instance, bool flush ) : void

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 Create() or Update() instead.

InternalSaveCopy ( object instance, bool flush ) : object

Saves a copy of 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 Create() or Update() instead.

InternalUpdate ( object instance, bool flush ) : void

Persists the modification on the instance state to the database.

PropertyNamesToOrderArray ( bool asc ) : NHibernate.Criterion.Order[]
Register ( Type arType, ActiveRecordModel model ) : void

Internally used

Method Details

Asc() public static method

Ascending Order
Returns an array of Ascending Order instances specifing which properties to use to order a result.
public static Asc ( ) : NHibernate.Criterion.Order[]
return NHibernate.Criterion.Order[]

Count() protected static method

Returns the number of records of the specified type in the database
protected static Count ( Type targetType ) : int
targetType System.Type The target type.
return int

Count() protected static method

Returns the number of records of the specified type in the database
protected static Count ( Type targetType, DetachedCriteria detachedCriteria ) : int
targetType System.Type The target type.
detachedCriteria DetachedCriteria The criteria expression
return int

Count() protected static method

Returns the number of records of the specified type in the database
protected static Count ( Type targetType, ICriterion criteria ) : int
targetType System.Type The target type.
criteria ICriterion The criteria expression
return int

Count() protected static method

Returns the number of records of the specified type in the database
protected static Count ( Type targetType, string filter ) : int
targetType System.Type The target type.
filter string A sql where string i.e. Person=? and DOB > ?
return int

Create() public method

Creates (Saves) a new instance to the database.
If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.
public Create ( ) : void
return void

Create() protected static method

Creates (Saves) a new instance to the database.
protected static Create ( object instance ) : void
instance object The ActiveRecord instance to be created on the database
return void

CreateAndFlush() public method

Creates (Saves) a new instance to the database.
Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.
public CreateAndFlush ( ) : void
return void

CreateAndFlush() protected static method

Creates (Saves) a new instance to the database and flushes the session.
protected static CreateAndFlush ( object instance ) : void
instance object The ActiveRecord instance to be created on the database
return void

Delete() public method

Deletes the instance from the database.
If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.
public Delete ( ) : void
return void

Delete() protected static method

Deletes the instance from the database.
protected static Delete ( object instance ) : void
instance object The ActiveRecord instance to be deleted
return void

DeleteAll() protected static method

Deletes all targetType objects, based on the primary keys supplied on pkValues.
protected static DeleteAll ( Type targetType, IEnumerable pkValues ) : int
targetType System.Type The target ActiveRecord type
pkValues IEnumerable A list of primary keys
return int

DeleteAll() protected static method

Deletes all rows for the specified ActiveRecord type
This method is usually useful for test cases.
protected static DeleteAll ( Type type ) : void
type System.Type ActiveRecord type on which the rows on the database should be deleted
return void

DeleteAll() protected static method

Deletes all rows for the specified ActiveRecord type that matches the supplied HQL condition
This method is usually useful for test cases.
protected static DeleteAll ( Type type, String where ) : void
type System.Type ActiveRecord type on which the rows on the database should be deleted
where String HQL condition to select the rows to be deleted
return void

DeleteAndFlush() public method

Deletes the instance from the database.
Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.
public DeleteAndFlush ( ) : void
return void

DeleteAndFlush() protected static method

Deletes the instance from the database and flushes the session.
protected static DeleteAndFlush ( object instance ) : void
instance object The ActiveRecord instance to be deleted
return void

Desc() public static method

Descending Order
Returns an array of Descending Order instances specifing which properties to use to order a result.
public static Desc ( ) : NHibernate.Criterion.Order[]
return NHibernate.Criterion.Order[]

EnumerateQuery() protected static method

Enumerates the query Note: only use if you expect most of the values to exist on the second level cache.
protected static EnumerateQuery ( IActiveRecordQuery query ) : IEnumerable
query IActiveRecordQuery The query.
return IEnumerable

Execute() protected method

Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.
protected Execute ( NHibernateDelegate call ) : object
call NHibernateDelegate The delegate instance
return object

Execute() protected static method

Invokes the specified delegate passing a valid NHibernate session. Used for custom NHibernate queries.
protected static Execute ( Type targetType, NHibernateDelegate call, object instance ) : object
targetType System.Type The target ActiveRecordType
call NHibernateDelegate The delegate instance
instance object The ActiveRecord instance
return object

ExecuteQuery() public static method

Executes the query.
public static ExecuteQuery ( IActiveRecordQuery query ) : object
query IActiveRecordQuery The query.
return object

Exists() protected static method

Check if there is any records in the db for the target type
protected static Exists ( Type targetType ) : bool
targetType System.Type The target type.
return bool

Exists() protected static method

Check if any instance matching the criteria exists in the database.
protected static Exists ( Type targetType, DetachedCriteria detachedCriteria ) : bool
targetType System.Type The target type.
detachedCriteria DetachedCriteria The criteria expression
return bool

Exists() protected static method

Check if the id exists in the database.
protected static Exists ( Type targetType, object id ) : bool
targetType System.Type The target type.
id object The id to check on
return bool

Exists() protected static method

Check if there is any records in the db for the target type
protected static Exists ( Type targetType, string filter ) : bool
targetType System.Type The target type.
filter string A sql where string i.e. Person=? and DOB > ?
return bool

FindAll() protected static method

Returns all instances found for the specified type.
protected static FindAll ( Type targetType ) : Array
targetType System.Type The target type.
return System.Array

FindAll() protected static method

Returns all instances found for the specified type according to the criteria
protected static FindAll ( Type targetType, DetachedCriteria detachedCriteria ) : Array
targetType System.Type The target type.
detachedCriteria DetachedCriteria The criteria.
return System.Array

FindAll() protected static method

Returns all instances found for the specified type using sort orders and criteria.
protected static FindAll ( Type targetType, NHibernate.Criterion.Order orders ) : Array
targetType System.Type The The target type.
orders NHibernate.Criterion.Order An of objects.
return System.Array

FindAllByProperty() protected static method

Finds records based on a property value - automatically converts null values to IS NULL style queries.
protected static FindAllByProperty ( Type targetType, String orderByColumn, String property, object value ) : Array
targetType System.Type The target type
orderByColumn String The column name to be ordered ASC
property String A property name (not a column name)
value object The value to be equals to
return System.Array

FindAllByProperty() protected static method

Finds records based on a property value - automatically converts null values to IS NULL style queries.
protected static FindAllByProperty ( Type targetType, String property, object value ) : Array
targetType System.Type The target type
property String A property name (not a column name)
value object The value to be equals to
return System.Array

FindByPrimaryKey() protected static method

Finds an object instance by an unique ID
protected static FindByPrimaryKey ( Type targetType, object id ) : object
targetType System.Type The AR subclass type
id object ID value
return object

FindByPrimaryKey() protected static method

Finds an object instance by an unique ID
if throwOnNotFound is set to /// true and the row is not found
protected static FindByPrimaryKey ( Type targetType, object id, bool throwOnNotFound ) : object
targetType System.Type The AR subclass type
id object ID value
throwOnNotFound bool true if you want to catch an exception /// if the object is not found
return object

FindFirst() protected static method

Searches and returns the first row.
protected static FindFirst ( Type targetType ) : object
targetType System.Type The target type
return object

FindFirst() protected static method

Searches and returns the first row.
protected static FindFirst ( Type targetType, DetachedCriteria detachedCriteria ) : object
targetType System.Type The target type.
detachedCriteria DetachedCriteria The criteria.
return object

FindFirst() protected static method

Searches and returns the first row.
protected static FindFirst ( Type targetType, NHibernate.Criterion.Order orders ) : object
targetType System.Type The target type
orders NHibernate.Criterion.Order The sort order - used to determine which record is the first one
return object

FindOne() protected static method

Searches and returns a row. If more than one is found, throws ActiveRecordException
protected static FindOne ( Type targetType ) : object
targetType System.Type The target type
return object

FindOne() protected static method

Searches and returns a row. If more than one is found, throws ActiveRecordException
protected static FindOne ( Type targetType, DetachedCriteria criteria ) : object
targetType System.Type The target type
criteria DetachedCriteria The criteria
return object

Refresh() public method

Refresh the instance from the database.
public Refresh ( ) : void
return void

Refresh() protected static method

Refresh the instance from the database.
protected static Refresh ( object instance ) : void
instance object The ActiveRecord instance to be reloaded
return void

Replicate() protected static method

From NHibernate documentation: Persist all reachable transient objects, reusing the current identifier values. Note that this will not trigger the Interceptor of the Session.
protected static Replicate ( object instance, NHibernate.ReplicationMode replicationMode ) : void
instance object The instance.
replicationMode NHibernate.ReplicationMode The replication mode.
return void

Save() public method

Saves the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.
If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.
public Save ( ) : void
return void

Save() protected static method

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 Create() or Update() instead.

protected static Save ( object instance ) : void
instance object The ActiveRecord instance to be saved
return void

SaveAndFlush() public method

Saves the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.
Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.
public SaveAndFlush ( ) : void
return void

SaveAndFlush() protected static method

Saves the instance to the database and flushes the session. 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 Create() or Update() instead.

protected static SaveAndFlush ( object instance ) : void
instance object The ActiveRecord instance to be saved
return void

SaveCopy() public method

Saves a copy of the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.
If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.
public SaveCopy ( ) : object
return object

SaveCopy() protected static method

Saves a copy of 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 Create() or Update() instead.

protected static SaveCopy ( object instance ) : object
instance object The transient instance to be saved
return object

SaveCopyAndFlush() public method

Saves a copy of the instance information to the database. May Create or Update the instance depending on whether it has a valid ID.
Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.
public SaveCopyAndFlush ( ) : object
return object

SaveCopyAndFlush() protected static method

Saves a copy of the instance to the database and flushes the session. 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 Create() or Update() instead.

protected static SaveCopyAndFlush ( object instance ) : object
instance object The transient instance to be saved
return object

SlicedFindAll() protected static method

Returns a portion of the query results (sliced)
protected static SlicedFindAll ( Type targetType, int firstResult, int maxResults ) : Array
targetType System.Type The target type.
firstResult int The number of the first row to retrieve.
maxResults int The maximum number of results retrieved.
return System.Array

SlicedFindAll() protected static method

Returns a portion of the query results (sliced)
protected static SlicedFindAll ( Type targetType, int firstResult, int maxResults, DetachedCriteria criteria ) : Array
targetType System.Type The target type.
firstResult int The number of the first row to retrieve.
maxResults int The maximum number of results retrieved.
criteria DetachedCriteria The criteria expression
return System.Array

SlicedFindAll() protected static method

Returns a portion of the query results (sliced)
protected static SlicedFindAll ( Type targetType, int firstResult, int maxResults, NHibernate.Criterion.Order orders ) : Array
targetType System.Type The target type.
firstResult int The number of the first row to retrieve.
maxResults int The maximum number of results retrieved.
orders NHibernate.Criterion.Order An of objects.
return System.Array

SlicedFindAll() protected static method

Returns a portion of the query results (sliced)
protected static SlicedFindAll ( Type targetType, int firstResult, int maxResults, NHibernate.Criterion.Order orders, DetachedCriteria criteria ) : Array
targetType System.Type The target type.
firstResult int The number of the first row to retrieve.
maxResults int The maximum number of results retrieved.
orders NHibernate.Criterion.Order An of objects.
criteria DetachedCriteria The criteria expression
return System.Array

ToString() public method

Return the type of the object with its PK value. Useful for logging/debugging
public ToString ( ) : String
return String

Update() public method

Persists the modification on the instance state to the database.
If within a SessionScope the operation is going to be on hold until NHibernate (or you) decides to flush the session.
public Update ( ) : void
return void

Update() protected static method

Persists the modification on the instance state to the database.
protected static Update ( object instance ) : void
instance object The ActiveRecord instance to be updated on the database
return void

UpdateAndFlush() public method

Persists the modification on the instance state to the database.
Even within a SessionScope the operation is going to be flushed immediately. This might have side effects such as flushing (persisting) others operations that were on hold.
public UpdateAndFlush ( ) : void
return void

UpdateAndFlush() protected static method

Persists the modification on the instance state to the database and flushes the session.
protected static UpdateAndFlush ( object instance ) : void
instance object The ActiveRecord instance to be updated on the database
return void

Property Details

holder protected_oe static_oe property

The global holder for the session factories.
protected static ISessionFactoryHolder holder
return ISessionFactoryHolder