您的位置:首页 > 移动开发

Application应用框架思考(二) 之[数据访问层]

2009-04-14 23:19 197 查看
Application应用框架思考(二) 之[数据访问层]

public interface IDataAccessLayer
{
void BeginTransaction();
void Close();
void CommitTransaction();
string ConnectionString { get; set; }
void Dispose();
void Execute();
System.Data.IDataReader ExecuteDataReader(string commandText, System.Data.IDataParameter[] commandParameters);
System.Data.IDataReader ExecuteDataReader(string commandText, System.Data.CommandType commandType);
System.Data.IDataReader ExecuteDataReader(string commandText, System.Data.CommandType commandType, System.Data.IDataParameter[] commandParameters);
System.Data.IDataReader ExecuteDataReader(string commandText);
System.Data.DataSet ExecuteDataSet(string commandText, System.Data.CommandType commandType, System.Data.IDataParameter[] commandParameters);
System.Data.DataSet ExecuteDataSet(string commandText, System.Data.CommandType commandType);
System.Data.DataSet ExecuteDataSet(string commandText);
System.Data.DataSet ExecuteDataSet(string commandText, System.Data.IDataParameter[] commandParameters);
System.Data.DataTable ExecuteDataTable(string pSQL);
System.Data.DataSet ExecuteKDDataSet(string pSQL);
int ExecuteQuery(string commandText, System.Data.CommandType commandType, System.Data.IDataParameter[] commandParameters);
int ExecuteQuery(string commandText, System.Data.IDataParameter[] commandParameters);
int ExecuteQuery(string commandText);
int ExecuteQuery(string commandText, System.Data.CommandType commandType);
object ExecuteScalar(string commandText, System.Data.CommandType commandType, System.Data.IDataParameter[] commandParameters);
object ExecuteScalar(string commandText, System.Data.CommandType commandType);
object ExecuteScalar(string commandText);
object ExecuteScalar(string commandText, System.Data.IDataParameter[] commandParameters);
int ExecuteSp(string commandText, System.Data.CommandType commandType);
int ExecuteSp(string commandText, System.Data.CommandType commandType, System.Data.IDataParameter[] commandParameters);
int ExecuteSp(string commandText);
System.Data.IDbCommand GeDataProviderCommand();
DataProviderType GetCurrentDataProviderType();
System.Data.IDbConnection GetDataProviderConnection();
System.Data.IDbDataAdapter GetDataProviderDataAdapter();
System.Data.Common.DbCommand GetDbCommand();
System.Data.Common.DbCommandBuilder GetDbCommandBuilder();
System.Data.Common.DbConnection GetDbConnection();
System.Data.Common.DbDataAdapter GetDbDataAdapter();
string getFieldValue(string FieldName);
bool IsExistsField(string FieldName, string TableName);
bool IsExistsTable(string TableName, string UserName);
bool Open();
void ReOpen(string connectionString);
void RollbackTransaction();
string SQL { get; set; }
System.Data.ConnectionState State { get; }
}

/// <summary>
/// Defines the DataAccessLayer implemented data provider types.
/// </summary>
public enum DataProviderType
{
Access,
Odbc,
OleDb,
Oracle,
Sql
}

//抽象类
public abstract class DataAccessLayerBaseClass : IDataAccessLayer
{
//相关接口实现
}

public class OracleDataAccessLayer : DataAccessLayerBaseClass
{
//Oracle相关实现
}
public class SqlDataAccessLayer: DataAccessLayerBaseClass
{
//SQLServer相关实现
}
public class OleDbDataAccessLayer: DataAccessLayerBaseClass
{
//OleDb相关实现
}

public class OdbcDataAccessLayerDataAccessLayerBaseClass
{
//Odbc相关实现
}
public sealed class DataAccessLayerFactory
{
private DataAccessLayerFactory() { }

public static DataAccessLayerBaseClass GetDataAccessLayer()
{
//...
}
public static DataAccessLayerBaseClass GetDataAccessLayer(DataProviderType dataProviderType, string connectionString)
{
// construct specific data access provider class
switch (dataProviderType)
{
case DataProviderType.Access:
case DataProviderType.OleDb:
return new OleDbDataAccessLayer(connectionString);

case DataProviderType.Odbc:
return new OdbcDataAccessLayer(connectionString);

case DataProviderType.Oracle:
return new OracleDataAccessLayer(connectionString);

case DataProviderType.Sql:
return new SqlDataAccessLayer(connectionString);

default:
throw new ArgumentException("Invalid data access layer provider type.");
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: