C# 클래스 Azavea.Open.DAO.SQL.SqlDaLayer

A SQL-specific implementation of an IDaLayer. Provided functionality to run data access function that are specific to data sources that take sql commands.
상속: AbstractDaLayer
파일 보기 프로젝트 열기: azavea/net-dao 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
_connDesc AbstractSqlConnectionDescriptor
_fullyQualifyColumnNames System.Boolean
_sqlQueryCache ClearingCache

공개 메소드들

메소드 설명
AppendParameter ( SqlDaQuery queryToAddTo, object value, Type columnType ) : void

Since it is implementation-dependent whether to use the sql parameters collection or not, this method should be implemented in each implementation.

CreateQuery ( ClassMapping mapping, DaoCriteria crit ) : IDaQuery

Builds the query based on a serializable criteria.

CreateQuery ( string queryStr, IEnumerable queryParams, ClassMapping mapping ) : IDaQuery

Builds the query based on a string, such as a sql string. NOTE: Not all FastDaoLayers are required to support this, if it is not supported a NotSupportedException will be thrown. TODO: This will be removed when FastDAO.QueryFor and IterateOverObjects that take strings are removed.

Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
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
ExpressionsToQuery ( SqlDaQuery queryToAddTo, DaoCriteria crit, ClassMapping mapping ) : void

Takes a DaoCriteria, converts it to a " WHERE ..." chunk of SQL. The SQL will begin with a space if non-empty.

GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List
GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
GetLastAutoGeneratedId ( ITransaction transaction, ClassMapping mapping, string idCol ) : object
GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int
GroupBysToEndOfQuery ( SqlDaQuery query, ICollection groupExpressions, ClassMapping mapping ) : void

Adds the group by fields to the end of the query, including the keyword "GROUP BY" if necessary.

GroupBysToStartOfQuery ( SqlDaQuery query, ICollection groupExpressions, ClassMapping mapping ) : void

Adds the group by fields to the "column" list ("column" since they may not all be columns) in the beginning of the select (I.E. "SELECT COUNT(*), Field1, Field2, etc).

Insert ( ITransaction transaction, ClassMapping mapping, object>.IDictionary propValues ) : int
OrdersToQuery ( SqlDaQuery queryToAddTo, DaoCriteria crit, ClassMapping mapping ) : void

Takes a DaoCriteria, converts it to an " ORDER BY ..." chunk of SQL. The SQL will begin with a space if non-empty.

ReadScalarValue ( Hashtable parameters, IDataReader reader ) : void
SetFullyQualifyColumnNames ( bool fullyQualifyColumnNames ) : void

Sometimes it is not desirable to fully qualify column names, even for a database, e.g. when doing a query that is a join of foreign tables. This allows this value to be set in those instances.

SqlDaLayer ( AbstractSqlConnectionDescriptor connDesc, bool supportsNumRecords ) : System

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

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

보호된 메소드들

메소드 설명
BoolTypeToString ( BooleanOperator boolType ) : string

Returns a nicely spaced AND or OR depending on the boolean type.

ExpressionListToQuery ( SqlDaQuery queryToAddTo, BooleanOperator boolType, IEnumerable expressions, ClassMapping mapping, string colPrefix ) : void

Converts the list of expressions from this criteria into SQL, and appends to the given string builder.

ExpressionToQuery ( SqlDaQuery queryToAddTo, IExpression expr, ClassMapping mapping, string colPrefix, string booleanOperator ) : bool

Converts a single Expression to SQL (mapping the columns as appropriate) and appends to the given string builder. Remember to wrap the SQL in parends if necessary.

GetGroupByValue ( ClassMapping mapping, IDataReader reader, int number, AbstractGroupExpression expression ) : object

Reads a single "group by" field value from the data reader, coerces it to the correct type if necessary/possible, and returns it.

GetValueStrings ( string table, object>.IDictionary propValues ) : string>.IDictionary
OrderListToSql ( StringBuilder orderClauseToAddTo, DaoCriteria crit, ClassMapping mapping ) : void

Converts the list of SortOrders from this criteria into SQL, and appends to the given string builder.

PreProcessPropertyValues ( string table, object>.IDictionary propValues ) : void

Override this method if you need to do any work to convert values from the object's properties into normal SQL parameters. Default implementation does nothing. This is called prior to inserting or updating these values in the table.

ReadGroupByCount ( Hashtable parameters, IDataReader reader ) : void

Reads the results from the data reader produced by the group by query, creates the GroupCountResults, and returns them in the parameters collection.

메소드 상세

AppendParameter() 공개 메소드

Since it is implementation-dependent whether to use the sql parameters collection or not, this method should be implemented in each implementation.
public AppendParameter ( SqlDaQuery queryToAddTo, object value, Type columnType ) : void
queryToAddTo SqlDaQuery Query to add the parameter to.
value object Actual value that we need to append to our SQL.
columnType System.Type Type of data actually stored in the DB column. For example, /// Enums may be stored as strings. May be null if no type cast /// is necessary.
리턴 void

BoolTypeToString() 보호된 정적인 메소드

Returns a nicely spaced AND or OR depending on the boolean type.
protected static BoolTypeToString ( BooleanOperator boolType ) : string
boolType BooleanOperator
리턴 string

CreateQuery() 공개 메소드

Builds the query based on a serializable criteria.
public 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 for "where" comparisons.
리턴 IDaQuery

CreateQuery() 공개 메소드

Builds the query based on a string, such as a sql string. NOTE: Not all FastDaoLayers are required to support this, if it is not supported a NotSupportedException will be thrown. TODO: This will be removed when FastDAO.QueryFor and IterateOverObjects that take strings are removed.
public CreateQuery ( string queryStr, IEnumerable queryParams, ClassMapping mapping ) : IDaQuery
queryStr string The sql statement to execute that is expected to return a large /// number of rows.
queryParams IEnumerable The parameters for the sql statement. If there are none, this /// can be null.
mapping ClassMapping The mapping of the table for which to build the query string.
리턴 IDaQuery

Delete() 공개 메소드

public Delete ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction
mapping ClassMapping
crit Azavea.Open.DAO.Criteria.DaoCriteria
리턴 int

DisposeOfQuery() 공개 메소드

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

ExecuteQuery() 공개 메소드

public ExecuteQuery ( ITransaction transaction, ClassMapping mapping, IDaQuery query, DataReaderDelegate invokeMe, Hashtable parameters ) : void
transaction ITransaction
mapping ClassMapping
query IDaQuery
invokeMe DataReaderDelegate
parameters System.Collections.Hashtable
리턴 void

ExpressionListToQuery() 보호된 메소드

Converts the list of expressions from this criteria into SQL, and appends to the given string builder.
protected ExpressionListToQuery ( SqlDaQuery queryToAddTo, BooleanOperator boolType, IEnumerable expressions, ClassMapping mapping, string colPrefix ) : void
queryToAddTo SqlDaQuery Query we're adding the expression to.
boolType BooleanOperator Whether to AND or OR the expressions together.
expressions IEnumerable The expressions to add to the query.
mapping ClassMapping Class mapping for the class we're dealing with.
colPrefix string What to prefix column names with, I.E. "Table." for "Table.Column". /// May be null if no prefix is desired. May be something other than /// the table name if the tables are being aliased.
리턴 void

ExpressionToQuery() 보호된 메소드

Converts a single Expression to SQL (mapping the columns as appropriate) and appends to the given string builder. Remember to wrap the SQL in parends if necessary.
protected ExpressionToQuery ( SqlDaQuery queryToAddTo, IExpression expr, ClassMapping mapping, string colPrefix, string booleanOperator ) : bool
queryToAddTo SqlDaQuery Query we're adding the expression to.
expr IExpression The expression. NOTE: It should NOT be null. This method does not check.
mapping ClassMapping Class mapping for the class we're dealing with.
colPrefix string What to prefix column names with, I.E. "Table." for "Table.Column". /// May be null if no prefix is desired. May be something other than /// the table name if the tables are being aliased.
booleanOperator string The boolean operator (AND or OR) to insert before /// this expression. Blank ("") if we don't need one.
리턴 bool

ExpressionsToQuery() 공개 메소드

Takes a DaoCriteria, converts it to a " WHERE ..." chunk of SQL. The SQL will begin with a space if non-empty.
public ExpressionsToQuery ( SqlDaQuery queryToAddTo, DaoCriteria crit, ClassMapping mapping ) : void
queryToAddTo SqlDaQuery Query we're adding the expression to.
crit Azavea.Open.DAO.Criteria.DaoCriteria Serializable critera to get the expressions from.
mapping ClassMapping Class mapping for the class we're dealing with.
리턴 void

GetCount() 공개 메소드

public GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, ICollection groupExpressions ) : List
transaction ITransaction
mapping ClassMapping
crit Azavea.Open.DAO.Criteria.DaoCriteria
groupExpressions ICollection
리턴 List

GetCount() 공개 메소드

public GetCount ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit ) : int
transaction ITransaction
mapping ClassMapping
crit Azavea.Open.DAO.Criteria.DaoCriteria
리턴 int

GetGroupByValue() 보호된 메소드

Reads a single "group by" field value from the data reader, coerces it to the correct type if necessary/possible, and returns it.
protected GetGroupByValue ( ClassMapping mapping, IDataReader reader, int number, AbstractGroupExpression expression ) : object
mapping ClassMapping Mapping of class fields / names / etc.
reader IDataReader Data reader to get the value from.
number int Which group by field is this (0th, 1st, etc).
expression Azavea.Open.DAO.Criteria.Grouping.AbstractGroupExpression The group by expression we're reading the value for.
리턴 object

GetLastAutoGeneratedId() 공개 메소드

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

GetNextSequenceValue() 공개 메소드

public GetNextSequenceValue ( ITransaction transaction, string sequenceName ) : int
transaction ITransaction
sequenceName string
리턴 int

GetValueStrings() 보호된 메소드

protected GetValueStrings ( string table, object>.IDictionary propValues ) : string>.IDictionary
table string
propValues object>.IDictionary
리턴 string>.IDictionary

GroupBysToEndOfQuery() 공개 메소드

Adds the group by fields to the end of the query, including the keyword "GROUP BY" if necessary.
public GroupBysToEndOfQuery ( SqlDaQuery query, ICollection groupExpressions, ClassMapping mapping ) : void
query SqlDaQuery Query to append to.
groupExpressions ICollection Group by expressions.
mapping ClassMapping Class mapping for the class we're dealing with.
리턴 void

GroupBysToStartOfQuery() 공개 메소드

Adds the group by fields to the "column" list ("column" since they may not all be columns) in the beginning of the select (I.E. "SELECT COUNT(*), Field1, Field2, etc).
public GroupBysToStartOfQuery ( SqlDaQuery query, ICollection groupExpressions, ClassMapping mapping ) : void
query SqlDaQuery Query to append to.
groupExpressions ICollection Group by expressions.
mapping ClassMapping Class mapping for the class we're dealing with.
리턴 void

Insert() 공개 메소드

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

OrderListToSql() 보호된 메소드

Converts the list of SortOrders from this criteria into SQL, and appends to the given string builder.
protected OrderListToSql ( StringBuilder orderClauseToAddTo, DaoCriteria crit, ClassMapping mapping ) : void
orderClauseToAddTo StringBuilder
crit Azavea.Open.DAO.Criteria.DaoCriteria
mapping ClassMapping
리턴 void

OrdersToQuery() 공개 메소드

Takes a DaoCriteria, converts it to an " ORDER BY ..." chunk of SQL. The SQL will begin with a space if non-empty.
public OrdersToQuery ( SqlDaQuery queryToAddTo, DaoCriteria crit, ClassMapping mapping ) : void
queryToAddTo SqlDaQuery
crit Azavea.Open.DAO.Criteria.DaoCriteria
mapping ClassMapping
리턴 void

PreProcessPropertyValues() 보호된 메소드

Override this method if you need to do any work to convert values from the object's properties into normal SQL parameters. Default implementation does nothing. This is called prior to inserting or updating these values in the table.
protected PreProcessPropertyValues ( string table, object>.IDictionary propValues ) : void
table string The table these values will be inserted or updated into.
propValues object>.IDictionary A dictionary of "column"/value pairs for the object to insert or update.
리턴 void

ReadGroupByCount() 보호된 메소드

Reads the results from the data reader produced by the group by query, creates the GroupCountResults, and returns them in the parameters collection.
protected ReadGroupByCount ( Hashtable parameters, IDataReader reader ) : void
parameters System.Collections.Hashtable Input and output parameters for the method.
reader IDataReader Data reader to read from.
리턴 void

ReadScalarValue() 공개 메소드

public ReadScalarValue ( Hashtable parameters, IDataReader reader ) : void
parameters System.Collections.Hashtable
reader IDataReader
리턴 void

SetFullyQualifyColumnNames() 공개 메소드

Sometimes it is not desirable to fully qualify column names, even for a database, e.g. when doing a query that is a join of foreign tables. This allows this value to be set in those instances.
public SetFullyQualifyColumnNames ( bool fullyQualifyColumnNames ) : void
fullyQualifyColumnNames bool Whether or not to fully qualify column names.
리턴 void

SqlDaLayer() 공개 메소드

Instantiates the data access layer with the connection descriptor for the DB.
public SqlDaLayer ( AbstractSqlConnectionDescriptor connDesc, bool supportsNumRecords ) : System
connDesc AbstractSqlConnectionDescriptor 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.
리턴 System

Truncate() 공개 메소드

public Truncate ( ClassMapping classMap ) : void
classMap ClassMapping
리턴 void

Update() 공개 메소드

public Update ( ITransaction transaction, ClassMapping mapping, DaoCriteria crit, object>.IDictionary propValues ) : int
transaction ITransaction
mapping ClassMapping
crit Azavea.Open.DAO.Criteria.DaoCriteria
propValues object>.IDictionary
리턴 int

프로퍼티 상세

_connDesc 보호되어 있는 프로퍼티

From this class on down, we can always treat it as a SqlConnectionDescriptor.
protected AbstractSqlConnectionDescriptor,Azavea.Open.DAO.SQL _connDesc
리턴 AbstractSqlConnectionDescriptor

_fullyQualifyColumnNames 보호되어 있는 프로퍼티

Tells us whether or not to fully qualify column names ("Table.Column") in the SQL. This is generally harmless for actual databases, but may not always be desirable.
protected Boolean,System _fullyQualifyColumnNames
리턴 System.Boolean

_sqlQueryCache 보호되어 있는 정적으로 프로퍼티

Since there are different types of query for different dao layers, each keeps their own cache.
protected static ClearingCache _sqlQueryCache
리턴 ClearingCache