C# Class Azavea.Open.DAO.AbstractDaLayer

Defines an interface that FastDAO can use to run data access functions that are specific to a particular data source (e.g. sql-based database). This class, and all classes that extend it, should be thread-safe.
Inheritance: IDaLayer
Datei anzeigen Open project: azavea/net-dao

Protected Properties

Property Type Description
_coerceableTypes TypeCoercionDelegate>.Dictionary
_connDesc IConnectionDescriptor
_log log4net.ILog

Public Methods

Method Description
AddCoercibleType ( Type t, TypeCoercionDelegate coercionDelegate ) : void

A method to add a coercion delegate for a type, without exposing the dictionary.

CoerceType ( Type desiredType, object input ) : object

Attempts to convert the value into the given type. While broadly similar to Convert.ChangeType, that method doesn't support enums and this one does. Calling that from within this method makes it take nearly twice as long, so this method does its own type checking.

CreateQuery ( ClassMapping mapping, DaoCriteria crit ) : IDaQuery

Builds the query based on a serializable criteria. The Query object is particular to the implementation, but may contain things like the parameters parsed out, or whatever makes sense to this FastDaoLayer. You can think of this method as a method to convert from the generic DaoCriteria into the specific details necessary for querying.

Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int

Deletes a data object record using the mapping and criteria for what's deleted.

DisposeOfQuery ( IDaQuery query ) : void

Should be called when you're done with the query. Allows us to cache the objects for reuse.

ExecuteQuery ( ITransaction transaction, ClassMapping mapping, IDaQuery query, DataReaderDelegate invokeMe, Hashtable parameters ) : void

Executes a query and invokes a method with a DataReader of results.

GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List

Gets a count of records for the given criteria, aggregated by the given grouping expressions. This matches "GROUP BY" behavior in SQL.

GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int

Gets a count of records for the given criteria.

GetLastAutoGeneratedId ( ITransaction transaction, ClassMapping mapping, string idCol ) : object

Finds the last generated id number for a column.

GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int

Gets the next id number from a sequence in the data source.

Insert ( ITransaction transaction, ClassMapping mapping, object>.IDictionary propValues ) : int

Inserts a data object record using the "table" and a list of column/value pairs.

InsertBatch ( ITransaction transaction, ClassMapping mapping, object>.List propValueDictionaries ) : void

Inserts a list of data object records of the same type. The default implementation merely calls Insert for each one, however some datasources may have more efficient ways of inserting multiple records that the appropriate DaLayer will take advantage of.

SupportsNumRecords ( ) : bool

If true, methods that return numbers of records affected will be returning accurate numbers. If false, they will return UNKNOWN_NUM_ROWS.

Truncate ( ClassMapping mapping ) : void

Deletes all contents of the table. Faster for large tables than DeleteAll, but requires greater permissions. For layers that do not support this, the behavior should be the same as calling Delete(null, mapping).

Update ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, object>.IDictionary propValues ) : int

Updates a data object record using the "table" and a list of column/value pairs.

UpdateBatch ( ITransaction transaction, ClassMapping mapping, List criteriaList, object>.List propValueDictionaries ) : void

Updates a list of data object records of the same type. The default implementation merely calls Update for each one, however some datasources may have more efficient ways of inserting multiple records that the appropriate DaLayer will take advantage of.

Protected Methods

Method Description
AbstractDaLayer ( IConnectionDescriptor connDesc, bool supportsNumRecords ) : System

Instantiates the data access layer with the connection descriptor for the DB.

GetDataType ( string col, ClassMapping mapping ) : Type

Given the class mapping and the column name, determines the appropriate c# data type.

Method Details

AbstractDaLayer() protected method

Instantiates the data access layer with the connection descriptor for the DB.
protected AbstractDaLayer ( IConnectionDescriptor connDesc, bool supportsNumRecords ) : System
connDesc IConnectionDescriptor The connection descriptor that is being used by this FastDaoLayer.
supportsNumRecords bool If true, methods that return numbers of records affected will be /// returning accurate numbers. If false, they will probably return /// FastDAO.UNKNOWN_NUM_ROWS.
return System

AddCoercibleType() public method

A method to add a coercion delegate for a type, without exposing the dictionary.
public AddCoercibleType ( Type t, TypeCoercionDelegate coercionDelegate ) : void
t System.Type The type to coerce.
coercionDelegate TypeCoercionDelegate How to coerce it.
return void

CoerceType() public method

Attempts to convert the value into the given type. While broadly similar to Convert.ChangeType, that method doesn't support enums and this one does. Calling that from within this method makes it take nearly twice as long, so this method does its own type checking.
public CoerceType ( Type desiredType, object input ) : object
desiredType System.Type Type we need the value to be.
input object Input value, may or may not already be the right type.
return object

CreateQuery() public abstract method

Builds the query based on a serializable criteria. The Query object is particular to the implementation, but may contain things like the parameters parsed out, or whatever makes sense to this FastDaoLayer. You can think of this method as a method to convert from the generic DaoCriteria into the specific details necessary for querying.
public abstract CreateQuery ( ClassMapping mapping, DaoCriteria crit ) : IDaQuery
mapping ClassMapping The mapping of the table for which to build the query string.
crit Azavea.Open.DAO.Criteria.DaoCriteria The criteria to use to find the desired objects.
return IDaQuery

Delete() public abstract method

Deletes a data object record using the mapping and criteria for what's deleted.
public abstract Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table from which to delete.
crit Azavea.Open.DAO.Criteria.DaoCriteria Criteria for deletion. NOTE: Only the expressions are observed, /// other things (like "order" or start / limit) are ignored. /// WARNING: A null or empty (no expression) criteria will /// delete ALL records!
return int

DisposeOfQuery() public abstract method

Should be called when you're done with the query. Allows us to cache the objects for reuse.
public abstract DisposeOfQuery ( IDaQuery query ) : void
query IDaQuery Query you're done using.
return void

ExecuteQuery() public abstract method

Executes a query and invokes a method with a DataReader of results.
public abstract ExecuteQuery ( ITransaction transaction, ClassMapping mapping, IDaQuery query, DataReaderDelegate invokeMe, Hashtable parameters ) : void
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping Class mapping for the table we're querying against. Optional, /// but not all columns may be properly typed if it is null.
query IDaQuery The query to execute, should have come from CreateQuery.
invokeMe DataReaderDelegate The method to invoke with the IDataReader results.
parameters System.Collections.Hashtable A hashtable containing any values that need to be persisted through invoked method. /// The list of objects from the query will be placed here.
return void

GetCount() public abstract method

Gets a count of records for the given criteria, aggregated by the given grouping expressions. This matches "GROUP BY" behavior in SQL.
public abstract GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table for which to build the query string.
crit Azavea.Open.DAO.Criteria.DaoCriteria The criteria to use for "where" comparisons.
groupExpressions ICollection The fields/expressions to aggregate on when counting.
return List

GetCount() public abstract method

Gets a count of records for the given criteria.
public abstract GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table for which to build the query string.
crit Azavea.Open.DAO.Criteria.DaoCriteria The criteria to use for "where" comparisons.
return int

GetDataType() protected method

Given the class mapping and the column name, determines the appropriate c# data type.
protected GetDataType ( string col, ClassMapping mapping ) : Type
col string Column to look up.
mapping ClassMapping Mapping for the class we're creating a table for.
return System.Type

GetLastAutoGeneratedId() public abstract method

Finds the last generated id number for a column.
public abstract GetLastAutoGeneratedId ( ITransaction transaction, ClassMapping mapping, string idCol ) : object
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The class mapping for the table being queried.
idCol string The ID column for which to find the last-generated ID.
return object

GetNextSequenceValue() public abstract method

Gets the next id number from a sequence in the data source.
public abstract GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int
transaction ITransaction The transaction to do this as part of.
sequenceName string The name of the sequence.
return int

Insert() public abstract method

Inserts a data object record using the "table" and a list of column/value pairs.
public abstract Insert ( ITransaction transaction, ClassMapping mapping, object>.IDictionary propValues ) : int
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
propValues object>.IDictionary A dictionary of "column"/value pairs for the object to insert.
return int

InsertBatch() public method

Inserts a list of data object records of the same type. The default implementation merely calls Insert for each one, however some datasources may have more efficient ways of inserting multiple records that the appropriate DaLayer will take advantage of.
public InsertBatch ( ITransaction transaction, ClassMapping mapping, object>.List propValueDictionaries ) : void
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
propValueDictionaries object>.List A list of dictionaries of column/value pairs. /// Each item in the list should represent the dictionary of column/value pairs for /// each respective object being inserted.
return void

SupportsNumRecords() public method

If true, methods that return numbers of records affected will be returning accurate numbers. If false, they will return UNKNOWN_NUM_ROWS.
public SupportsNumRecords ( ) : bool
return bool

Truncate() public abstract method

Deletes all contents of the table. Faster for large tables than DeleteAll, but requires greater permissions. For layers that do not support this, the behavior should be the same as calling Delete(null, mapping).
public abstract Truncate ( ClassMapping mapping ) : void
mapping ClassMapping
return void

Update() public abstract method

Updates a data object record using the "table" and a list of column/value pairs.
public abstract Update ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, object>.IDictionary propValues ) : int
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
crit Azavea.Open.DAO.Criteria.DaoCriteria All records matching this criteria will be updated per the dictionary of /// values.
propValues object>.IDictionary A dictionary of column/value pairs for all non-ID columns to be updated.
return int

UpdateBatch() public method

Updates a list of data object records of the same type. The default implementation merely calls Update for each one, however some datasources may have more efficient ways of inserting multiple records that the appropriate DaLayer will take advantage of.
public UpdateBatch ( ITransaction transaction, ClassMapping mapping, List criteriaList, object>.List propValueDictionaries ) : void
transaction ITransaction The transaction to do this as part of.
mapping ClassMapping The mapping of the table or other data container we're dealing with.
criteriaList List A list of DaoCriteria. /// Each item in the list should represent the criteria for /// rows that will be updated per the accompanying dictionary.
propValueDictionaries object>.List A list of dictionaries of column/value pairs. /// Each item in the list should represent the dictionary of non-ID column/value pairs for /// each respective object being updated.
return void

Property Details

_coerceableTypes protected_oe property

A mapping of additional types that can be handled by this DAO to methods for handling them. It is initially null, but can be created and aded to by a subclass to easily allow for handling arbitrary data types. Use must be synchronized!
protected Dictionary _coerceableTypes
return TypeCoercionDelegate>.Dictionary

_connDesc protected_oe property

The connection descriptor that is being used by this FastDaoLayer.
protected IConnectionDescriptor _connDesc
return IConnectionDescriptor

_log protected_oe static_oe property

log4net logger that any child class may use for logging any appropriate messages.
protected static ILog,log4net _log
return log4net.ILog