——希望迎着阳光奔跑!

 

iBATIS

IbatisNet一下简称Ibatis包括DataAccess和DataMapper两部分。整个Solution包括三个主项目:

IBatisNet.Common
IBatisNet.DataAccess
IBatisNet.DataMapper

和一个辅助项目:IBatisNet.Common.Logging.Log4Net。

Common项目是DataAccess和DataMapper的公共基础,提供通用功能和公共服务。DataAccess是DAO框架,DataMapper是SqlMap映射框架。Common.Logging.Log4Net是对log4net日志服务的代理,利用log4net日志框架产生和输出日志。

二.各项目介绍
Commons

根目录:
DataSource类封装了数据源信息,包括数据源的标志名Name,数据源的提供者Provider和数据源所代表的连接字符串ConnectionString。DataSource类有下列属性:
[Serializable]
[XmlRoot("dataSource", Namespace="http://ibatis.apache.org/dataMapper")]
类中的Property(属性)也有[XmlAttribute]属性(Attribute),例如public string ConnectionString属性有[XmlAttribute("connectionString")]。
所以类可被反序列化为xml文件,也可以直接通过XmlNode解析为对象。DataSourceDeSerializer类就是从XmlNode中读取信息并生成DataSource类。
DataSource属性和配置文件中的dataSource节点对应。
Provider类封装了data provider(数据提供者)信息,例如程序集名称AssemblyName,是否是默认提供者IsDefault,ConnectionClass,DataAdapterClass等提供者程序的信息。并提供了IDbCommand GetCommand(),IDbDataAdapter GetDataAdapter()等方法,为上层应用隐藏了具体驱动(数据提供程序)的细节。与DataSource一样Provider也是可以序列化为xml文件,并通过ProviderDeSerializer.cs中的ProviderDeSerializer类从XmlNode中构造Provider实例。
IDalSession类是Ibatis中的基础接口。封装了数据访问相关的会话信息,比如数据源,连接和事物对象。用于管理数据源相关信息,比如:
IDbCommand CreateCommand(CommandType commandType);

///
/// Create an IDataParameter
///
/// An IDataParameter.
IDataParameter CreateDataParameter();

///
/// Create a DataAdapter
///
/// The statement or stored procedure
/// used to select records in the data source.
/// An IDbDataAdapter.
IDbDataAdapter CreateDataAdapter(IDbCommand command);

///
/// Create a DataAdapter
///
/// An IDbDataAdapter.
IDbDataAdapter CreateDataAdapter();
连接管理的相关方法,比如:
///
/// Open a connection.
///
void OpenConnection();

///
/// Open a connection, on the specified connection string.
///
/// The connection string
void OpenConnection(string connectionString);

///
/// close a connection
///
void CloseConnection();
事务管理相关的方法,比如:
///
/// Begins a transaction on the current connection
/// with the specified IsolationLevel value.
///
/// The transaction isolation level for this connection.
/// Open a connection.
void BeginTransaction(bool openConnection, IsolationLevel isolationLevel);

///
/// Commit a transaction and close the associated connection
///
void CommitTransaction();

///
/// Commits the database transaction.
///
/// Close the connection
void CommitTransaction(bool closeConnection);

///
/// Rollbak a transaction and close the associated connection
///
void RollBackTransaction();

///
/// Rolls back a transaction from a pending state.
///
/// Close the connection
void RollBackTransaction(bool closeConnection);
等。

Exception目录:
Exception目录中的类定义了框架的异常类型。
IBatisNetException是框架基础类,其他框架异常都继承自它。
ConfigurationException类用于处理配置过程中出现的异常。
ForeignKeyException类用于代表外键异常和错误。
ProbeException类代表较表层的异常,通过该异常可以探究深层原因,也用于通过流节序列化并组装成异常实例的过程(不是太清楚)。框架中在ReflectionInfo和ObjectProbe中有使用。

Logging目录:
Logging目录类似于apache jarkata中的commons log,对log进行了封装,可以同时支持多种log实现,并通过配置文件进行配置。不详细说明。


Pagination目录:
Pagination目录辅助查询分类。
PaginatedArrayList类实现了IPaginatedList接口。用于维护页码和页中的数据内容。维护分页状态实现分页算法。PaginatedArrayList和具体的数据访问无关,内部通过ArrayList容器分类。

Transaction目录:
Transaction目录中的类用于事务管理。
IsolationLevel枚举定义了事务的隔离级别。
TransactionOptions结构指明了事务行为:事务时间段和隔离级别。
TransactionScopeOptions枚举描述了事务范围(Transaction scope)和事务的关联关系。
TransactionScope用于管理分布式事务,不过只支持1.1而且对操作系统由要求,不支持win2000。

Utilities目录:
Utilities目录中是一些公用类。
ConfigWatcherHandler类用于监视配置文件以便在配置文件修改的时候进行相应的处理,比如重新加载并处理配置文件。该类中注意Timer类和FileSystemWatcher类的用法。
DBHelperParameterCache类用于对存储过程参数的缓存。
HashCodeProvider类的public static int GetIdentityHashCode(object obj)方法返回obj的HashCode。
Resources类用于简化资源文件的访问。可以通过流,文件和url获取资源文件,并解析为XmlDocument。
ScriptRunner类用于执行sql脚本语句。
StringTokenizer类类似于java中的StringTokenizer,可以分割字符串为字符串数组。

Utilities/Objects目录:
Utilities/Objects目录下的类主要用于反射。
ObjectProbe由于获取对象的反射信息和运行时值信息。
ReflectionInfo主要缓存了类的定义信息,可以使property和get/set方法的映射更加简单。

Utilities/Proxy目录:
Utilities/Proxy目录利用Castle DynamicProxy的代理类。
CachedProxyGenerator继承自Castle DynamicProxy的ProxyGenerator,通过CreateProxy方法利用ProxyBuilder.CreateInterfaceProxy(interfaces, targetType )创建动态代理。
IProxyGenerator一个标志接口。
ProxyGeneratorFactory工厂类,获取Castle DynamicProxy的一个ProxyGenerator实例。

Utilities/TypesResolver目录:
Utilities/TypesResolver目录中的类用于类型解析。也就是利用反射和程序集从字符串构造出相应的类型。
TypeResolver的Type Resolve (string typeName)方法从程序集中获取类型信息。
CachedTypeResolver继承自TypeResolver,增加了缓存功能。
TypeAliasResolver类定义了Ibatis内部的别名和实际类型的映射,例如list-〉new ArrayList(),以及将系统的内置值类型变换为相应的对象类型。

Xml目录:
Xml目录包含一个NodeUtils类,主要用于从XmlNode中解析属性,和从NameValueCollection中获取值,ParsePropertyTokens(string str, NameValueCollection properties) 方法用于将str中的占位符用相应的properties中的值替代。str中可以有多个占位符属性。

posted on 2006-06-12 16:08 Ark 阅读(961) 评论(1)  编辑  收藏

评论

# re: iBATIS 2006-11-22 16:20 loook123

比较详细 可是有点看不懂  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(2)

随笔档案

Java 志士

Tecnology collection

搜索

最新评论

阅读排行榜

评论排行榜