Class BaseDatabaseAdapter<TConnection, TParameter>
Database adapter base class
Inherited Members
Namespace: XData.Database.Adapter
Assembly: XData.docfx.dll
Syntax
[DatabaseAdapter("NONE")]
public abstract class BaseDatabaseAdapter<TConnection, TParameter> : IDatabaseAdapter, IDisposable where TConnection : DbConnection, new()
where TParameter : IDbDataParameter, new()
Type Parameters
Name | Description |
---|---|
TConnection | |
TParameter |
Properties
| Improve this Doc View SourceConfig
Adapter configuration
Declaration
protected IConfiguration Config { get; }
Property Value
Type | Description |
---|---|
IConfiguration |
ConnectType
Adapter name
Declaration
public string ConnectType { get; }
Property Value
Type | Description |
---|---|
String |
Context
Database context name
Declaration
protected string Context { get; }
Property Value
Type | Description |
---|---|
String |
DialectAdapter
SQL dialect adapter instance
Declaration
protected ISqlBuilder DialectAdapter { get; }
Property Value
Type | Description |
---|---|
ISqlBuilder |
Initialized
Declaration
protected bool Initialized { get; }
Property Value
Type | Description |
---|---|
Boolean |
NotSupported
Check adapter supports user defined types (UDT)
Declaration
public virtual DialectOptions NotSupported { get; }
Property Value
Type | Description |
---|---|
DialectOptions |
Methods
| Improve this Doc View SourceAddSavePoint(Guid, IDbTransaction, String)
Add named save point
Declaration
protected abstract void AddSavePoint(Guid layer, IDbTransaction transaction, string savePoint)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
IDbTransaction | transaction | Transaction |
String | savePoint | Save point name |
BeginTransaction(Guid, Boolean, IsolationLevel)
Begin transaction
Declaration
public string BeginTransaction(Guid layer, bool read = false, IsolationLevel isolation = IsolationLevel.ReadCommitted)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Boolean | read | Read only transaction flag |
IsolationLevel | isolation | Transaction isolation level |
Returns
Type | Description |
---|---|
String | Transaction key |
Exceptions
Type | Condition |
---|---|
XDataSqlException | SQL exceptions while beginning transaction. |
Call(Guid, StoredProcedure, CancellationToken)
Calls stored procedure
Declaration
public CallResult Call(Guid layer, StoredProcedure procedure, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
StoredProcedure | procedure | Stored procedure |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
CallResult | CallResult |
Exceptions
Type | Condition |
---|---|
XDataSqlException |
Close(Guid)
Close database connection
Declaration
public void Close(Guid layer)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer |
Exceptions
Type | Condition |
---|---|
XDataSqlException | SQL exceptions while closing connection |
Commit(Guid, String)
Commit transaction
Declaration
public bool Commit(Guid layer, string transactionId)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
String | transactionId | Transaction key |
Returns
Type | Description |
---|---|
Boolean | Success flag |
CreateCommand(TConnection)
Create specific SQL command
Declaration
protected virtual IDbCommand CreateCommand(TConnection connection)
Parameters
Type | Name | Description |
---|---|---|
TConnection | connection | SQL connection |
Returns
Type | Description |
---|---|
IDbCommand | SQL command |
Remarks
Override this when some special command parameters are required
CreateParameter(Guid, QueryParam)
Create common parameter
Declaration
protected virtual TParameter CreateParameter(Guid layer, QueryParam parameter)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
QueryParam | parameter | Query parameter |
Returns
Type | Description |
---|---|
TParameter | Parameter |
Dispose()
IDisposable realization
Declaration
public void Dispose()
ExecuteNonQuery(Guid, Enum, Object[])
Executes SQL expression with no result set
Declaration
public QueryResult ExecuteNonQuery(Guid layer, Enum queryIndex, params object[] paramValues)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Enum | queryIndex | Predefined query enumeration key |
Object[] | paramValues | Query parameter values |
Returns
Type | Description |
---|---|
QueryResult | Query result |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query parameters |
ExecuteNonQuery(Guid, Query)
Executes SQL expression with no result set
Declaration
public QueryResult ExecuteNonQuery(Guid layer, Query query)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Query | query | Query |
Returns
Type | Description |
---|---|
QueryResult | Query result |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query |
XDataConcurrencyException | concurrency exception |
ExecuteScalar(Guid, Enum, Object[])
Executes scalar returning query
Declaration
public object ExecuteScalar(Guid layer, Enum queryIndex, params object[] paramValues)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Enum | queryIndex | Predefined query enumeration key |
Object[] | paramValues | Query parameter values |
Returns
Type | Description |
---|---|
Object | Scalar value |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query parameters |
ExecuteScalar(Guid, Query)
Executes scalar returning query
Declaration
public object ExecuteScalar(Guid layer, Query query)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Query | query | Query |
Returns
Type | Description |
---|---|
Object | Reader |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query |
XDataConcurrencyException | concurrency exception |
FillTable(Guid, Enum, CommandBehavior, Object[])
Executes query and fill data table
Declaration
public DataTable FillTable(Guid layer, Enum queryIndex, CommandBehavior behavior, params object[] paramValues)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Enum | queryIndex | Predefined query enumeration key |
CommandBehavior | behavior | Command behavior |
Object[] | paramValues | Query parameter values |
Returns
Type | Description |
---|---|
DataTable | Filled data table |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query parameters |
FillTable(Guid, Enum, Object[])
Executes query and fill data table
Declaration
public DataTable FillTable(Guid layer, Enum queryIndex, params object[] paramValues)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Enum | queryIndex | Predefined query enumeration key |
Object[] | paramValues | Query parameter values |
Returns
Type | Description |
---|---|
DataTable | Filled data table |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query parameters |
FillTable(Guid, Query, CancellationToken, CommandBehavior)
Executes query and fill data table
Declaration
public DataTable FillTable(Guid layer, Query query, CancellationToken token, CommandBehavior behavior = CommandBehavior.Default)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Query | query | Query |
CancellationToken | token | Cancellation token |
CommandBehavior | behavior | Command behavior |
Returns
Type | Description |
---|---|
DataTable | Filled data table |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query |
FixFieldDataType(DataRow)
Convert field data type
Declaration
protected virtual Type FixFieldDataType(DataRow columnInfo)
Parameters
Type | Name | Description |
---|---|---|
DataRow | columnInfo | Field description from schema table |
Returns
Type | Description |
---|---|
Type | Correct data type |
GetConnection(Guid)
Database connection
Declaration
protected DbConnection GetConnection(Guid layer)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer |
Returns
Type | Description |
---|---|
DbConnection |
GetNativeType(DbType)
Declaration
protected string GetNativeType(DbType type)
Parameters
Type | Name | Description |
---|---|---|
DbType | type |
Returns
Type | Description |
---|---|
String |
Exceptions
Type | Condition |
---|---|
XDataAdapterException |
GetParameterValue(QueryParam)
Returns parameter value
Declaration
public object GetParameterValue(QueryParam parameter)
Parameters
Type | Name | Description |
---|---|---|
QueryParam | parameter | Query parameter |
Returns
Type | Description |
---|---|
Object | Parameter value |
GetParameterValue<T>(QueryParam)
Declaration
public T GetParameterValue<T>(QueryParam parameter)
Parameters
Type | Name | Description |
---|---|---|
QueryParam | parameter |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
XDataAdapterException |
GetProcedureCall(ref IDbCommand, StoredProcedure, String, Boolean)
Declaration
protected virtual void GetProcedureCall(ref IDbCommand command, StoredProcedure procedure, string getResultName = null, bool closeCursor = false)
Parameters
Type | Name | Description |
---|---|---|
IDbCommand | command | |
StoredProcedure | procedure | |
String | getResultName | |
Boolean | closeCursor |
GetSqlType(String, ref Int32, ref Int32, Int32)
Declaration
protected DbType GetSqlType(string typeName, ref int size, ref int scale, int precision)
Parameters
Type | Name | Description |
---|---|---|
String | typeName | |
Int32 | size | |
Int32 | scale | |
Int32 | precision |
Returns
Type | Description |
---|---|
DbType |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | Type not supported |
GetTableFieldInfo(Guid, String)
Declaration
public abstract ReadOnlyCollection<FieldInfo> GetTableFieldInfo(Guid layer, string table)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | |
String | table |
Returns
Type | Description |
---|---|
ReadOnlyCollection<FieldInfo> |
GetTablesInfo(Guid)
Declaration
public abstract ReadOnlyCollection<TableInfo> GetTablesInfo(Guid layer)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer |
Returns
Type | Description |
---|---|
ReadOnlyCollection<TableInfo> |
GetUtdParameter(QueryParam)
Create and initialize user data type (UDT) parameter
Hint: Override this method to use UDT stored procedure parameters
Declaration
protected virtual IDataParameter GetUtdParameter(QueryParam parameter)
Parameters
Type | Name | Description |
---|---|---|
QueryParam | parameter | Stored procedure parameter |
Returns
Type | Description |
---|---|
IDataParameter | IDataParameter |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | User Defined Type (UTD) |
Init()
Adapter initialization
Declaration
protected abstract void Init()
Init(ISqlBuilder, String, String, IConfiguration)
Adapter initialization logic
Declaration
public void Init(ISqlBuilder dialectAdapter, string context, string connectionString, IConfiguration config)
Parameters
Type | Name | Description |
---|---|---|
ISqlBuilder | dialectAdapter | SQL dialect adapter |
String | context | Context name |
String | connectionString | Database connection string |
IConfiguration | config | Adapter configuration |
InitConnection(DbConnection)
Declaration
protected virtual void InitConnection(DbConnection connection)
Parameters
Type | Name | Description |
---|---|---|
DbConnection | connection |
InTransaction(Guid)
Connection have not committed transaction flag
Declaration
public bool InTransaction(Guid layer)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer |
Returns
Type | Description |
---|---|
Boolean |
IsConcurrencyError(Exception)
Check exception is a concurrency exception
Declaration
protected virtual bool IsConcurrencyError(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception | Exception |
Returns
Type | Description |
---|---|
Boolean | Exception is a concurrency exception |
IsOpen(Guid)
Connection is open flag
Declaration
public bool IsOpen(Guid layer)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer |
Returns
Type | Description |
---|---|
Boolean |
ReadNativeValue<T>(String, Object)
Read native SQL value
Declaration
protected virtual T ReadNativeValue<T>(string nativeSqlType, object value)
Parameters
Type | Name | Description |
---|---|---|
String | nativeSqlType | Native SQL type name |
Object | value | Value |
Returns
Type | Description |
---|---|
T | Mapped value |
Type Parameters
Name | Description |
---|---|
T | Mapped type |
Exceptions
Type | Condition |
---|---|
XDataAdapterException |
ReadUtd<T>(Object)
Read data from wrapped user defined type (UTD)
Declaration
protected virtual T ReadUtd<T>(object utdObject)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Object | utdObject | Wrapped value |
Returns
Type | Description |
---|---|
T | Unwrapped value |
Type Parameters
Name | Description |
---|---|
T | Type mapped to user defined type (UTD) |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | User Defined Type (UTD) |
ReadUtdCollection<T>(Object)
Read data from wrapped user defined type (UTD)
Declaration
protected virtual ICollection<T> ReadUtdCollection<T>(object utdCollection)
Parameters
Type | Name | Description |
---|---|---|
Object | utdCollection | Wrapped collection |
Returns
Type | Description |
---|---|
ICollection<T> | Unwrapped collection |
Type Parameters
Name | Description |
---|---|
T | Collection element type mapped to user defined type (UTD) |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | User Defined Type (UTD) |
RegisterResultSet(String)
Register result set parameter of stored procedure
Declaration
protected virtual IDbDataParameter RegisterResultSet(string resultSetName)
Parameters
Type | Name | Description |
---|---|---|
String | resultSetName | Result set name |
Returns
Type | Description |
---|---|
IDbDataParameter | Result set parameter |
Remarks
WARNING! Override this method to register result sets as out parameters
Exceptions
Type | Condition |
---|---|
XDataAdapterException | RegisterResultSet |
See Also
| Improve this Doc View SourceRollback(Guid, String)
Rollback transaction
Declaration
public bool Rollback(Guid layer, string transactionId)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
String | transactionId | Transaction key |
Returns
Type | Description |
---|---|
Boolean | Success flag |
RollbackToSavePoint(Guid, IDbTransaction, String)
Rollback to named save point
Declaration
protected abstract void RollbackToSavePoint(Guid layer, IDbTransaction transaction, string savePoint)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
IDbTransaction | transaction | Transaction |
String | savePoint | Save point name |
SafeConvert<T>(Object)
Safe conversion for Db specific types
Declaration
public virtual T SafeConvert<T>(object data)
Parameters
Type | Name | Description |
---|---|---|
Object | data | Source data |
Returns
Type | Description |
---|---|
T | Source data converted to type |
Type Parameters
Name | Description |
---|---|
T | Result type |
Remarks
Override this to convert some specific Db related types
See Also
| Improve this Doc View SourceSelectParameterValue<T>(QueryParam)
Declaration
public IEnumerable<T> SelectParameterValue<T>(QueryParam parameter)
Parameters
Type | Name | Description |
---|---|---|
QueryParam | parameter |
Returns
Type | Description |
---|---|
IEnumerable<T> |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
XDataAdapterException |
Test(Guid, Query)
Test query syntax WARNING! Throws a error if test failed!
Declaration
public void Test(Guid layer, Query query)
Parameters
Type | Name | Description |
---|---|---|
Guid | layer | Layer |
Query | query | Query |
Exceptions
Type | Condition |
---|---|
XDataSqlException | wrong SQL query |
WrapUtd<T>(T, String)
Wrap data to user defined type (UTD)
Declaration
protected virtual object WrapUtd<T>(T value, string utdTypeName)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | value | Value to wrap |
String | utdTypeName | User defined type name |
Returns
Type | Description |
---|---|
Object | Wrapped value |
Type Parameters
Name | Description |
---|---|
T | Type mapped to user defined type (UTD) |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | User Defined Type (UTD) |
WrapUtdCollection<T>(T[], Boolean, String, String)
Wrap data to collection (table or array) user defined type (UTD)
Declaration
protected virtual object WrapUtdCollection<T>(T[] value, bool isArray, string utdTypeName, string utdElementName = null)
Parameters
Type | Name | Description |
---|---|---|
T[] | value | Collection to wrap |
Boolean | isArray | Use VARARRAY |
String | utdTypeName | User defined type name for collection |
String | utdElementName | User defined type name for element (set to null for scalar type collection) |
Returns
Type | Description |
---|---|
Object | Wrapped collection |
Type Parameters
Name | Description |
---|---|
T | Collection element type mapped to user defined type (UTD) |
Exceptions
Type | Condition |
---|---|
XDataAdapterException | User Defined Type (UTD) |