标签:业界 table 批量 原理 mission logic param r文件 lazy
我们现在用的数据访问组件封装了IBatis.Net框架,提供了标准的数据访问接口和服务。正好总结一下老技术IBatis.Net
在进行实际的数据访问开发之前,我们先了解一下:IBatis.Net中几个重要的配置文件和一些关键的技术原理:
4个重要的配置文件:
关键的技术特性
开发一个数据访问的业务功能,主要有以下4个步骤:
示例几个关键的写法
1. 一对多关系,批量Insert
1 <insert id="SaveDomainModel" parameterClass="DomainModel"> 2 begin 3 INSERT INTO Meta_DomainModel(ID,Name,RootDomainObjectID, IsCache, CacheStrategy, IsLogicallyDeleted, DataLoaderConfig, Version,Creator,LastModifier)VALUES( 4 #ID#,#Name#,#RootDomainObjectID#,#IsCache:VarChar#,#CacheStrategy#,#IsLogicDelete:VarChar#,#DataLoaderConfig#,#Version#,#Creator#,#LastModifier#) 5 <iterate conjunction=" " open="" close="" property="DomainObjects"> 6 INSERT INTO Meta_DomainObject(ID,Name,DomainModelID,IsRootObject,ParentObjectID,ClazzReflectType,PropertyName,IsLazyLoad,DataObjectID,Creator,LastModifier) 7 VALUES(#DomainObjects[].ID#,#DomainObjects[].Name#,#DomainObjects[].DomainModelID#,#DomainObjects[].IsRootObject:VarChar#,#DomainObjects[].ParentObjectID#,#DomainObjects[].ClazzReflectType#, 8 #DomainObjects[].PropertyName#,#DomainObjects[].IsLazyLoad:VarChar#,#DomainObjects[].DataObjectID#,#DomainObjects[].Creator#,#DomainObjects[].LastModifier#) 9 </iterate> 10 end; 11 </insert>
2. 简单批量Insert插入
1 <insert id="SaveDomainObjectElements" parameterClass="ArrayList"> 2 begin 3 <iterate conjunction=" " open="" close="" > 4 INSERT INTO Meta_DomainObjectElement(ID,Name,Alias,DisplayName,DomainObjectID,DataType,Length,Precision,DefaultValue,IsAllowNull,ElementType,DataColumnID, 5 PropertyType,PropertyName,IsForQuery,Creator,LastModifier) 6 VALUES(#[].ID#,#[].Name#,#[].Alias#,#[].DisplayName#,#[].DomainObjectID#,#[].DataType#,#[].Length#,#[].Precision#,#[].DefaultValue#,#[].IsAllowNull:VarChar#,#[].ElementType#,#[].DataColumnID#, 7 #[].PropertyType#,#[].PropertyName#,#[].IsForQuery:VarChar#,#[].Creator#,#[].LastModifier#) 8 </iterate> 9 end; 10 </insert>
3. 查询一对多结果集
1 <resultMap id="DataObjectResultMap" class="DataObject" groupby="ID"> 2 <result property="ID" column="ID" /> 3 <result property="Name" column="Name" /> 4 <result property="Descriptions" column="Descriptions" /> 5 <result property="DataSourceName" column="DataSourceName" /> 6 <result property="LogicTableName" column="LogicTableName" /> 7 <result property="IsTableSharding" column="IsTableSharding" /> 8 <result property="IsDatabaseSharding" column="IsDatabaseSharding" /> 9 <result property="TableShardingStrategyID" column="TableShardingStrategy" /> 10 <result property="DatabaseShardingStrategyID" column="DatabaseShardingStrategy" /> 11 <result property="IsView" column="IsView" /> 12 <result property="IsLogicallyDeleted" column="IsLogicallyDeleted" /> 13 <result property="Version" column="Version" /> 14 <result property="Columns" resultMapping="MetadataMapper.DataColumnResultMap"></result> 15 <result property="Creator" column="Creator" /> 16 <result property="CreateTime" column="CreateTime" /> 17 <result property="LastModifier" column="LastModifier" /> 18 <result property="LastModifyTime" column="LastModifyTime" /> 19 </resultMap> 20 <resultMap id="DataColumnResultMap" class="DataColumn"> 21 <result property="ID" column="C_ID" /> 22 <result property="ColumnName" column="ColumnName" /> 23 <result property="DisplayName" column="DisplayName" /> 24 <result property="DataObjectID" column="DataObjectID" /> 25 <result property="DataTypeID" column="DataType" /> 26 <result property="Length" column="Length" /> 27 <result property="Precision" column="Precision" /> 28 <result property="DefaultValue" column="DefaultValue" /> 29 <result property="IsNullable" column="IsNullable" /> 30 <result property="IsPkColumn" column="IsPkColumn" /> 31 <result property="IsSystem" column="IsSystem" /> 32 <result property="IsShardingColumn" column="IsShardingColumn" /> 33 <result property="ColumnOrder" column="ColumnOrder" /> 34 <result property="Creator" column="C_Creator" /> 35 <result property="CreateTime" column="C_CreateTime" /> 36 <result property="LastModifier" column="C_LastModifier" /> 37 <result property="LastModifyTime" column="C_LastModifyTime" /> 38 </resultMap> 39
对应的Select 语句
1 <select id="GetDataObject" resultMap="DataObjectResultMap" parameterClass="string"> 2 SELECT Meta_DataObject.ID,Meta_DataObject.Name,Descriptions, DataSourceName, LogicTableName, IsTableSharding, IsDatabaseSharding, TableShardingStrategy,DatabaseShardingStrategy,IsView,IsLogicallyDeleted,Version,Meta_DataObjectColumn.Creator,Meta_DataObjectColumn.LastModifier,Meta_DataObjectColumn.CreateTime,Meta_DataObjectColumn.LastModifyTime, 3 Meta_DataObjectColumn.ID as C_ID,ColumnName,DisplayName,DataObjectID,DataType,Length,Precision,DefaultValue,IsNullable,IsPkColumn,IsShardingColumn,IsSystem,ColumnOrder, 4 Meta_DataObjectColumn.Creator as C_Creator,Meta_DataObjectColumn.LastModifier as C_LastModifier,Meta_DataObjectColumn.CreateTime as C_CreateTime,Meta_DataObjectColumn.LastModifyTime as C_LastModifyTime 5 FROM Meta_DataObject 6 LEFT JOIN Meta_DataObjectColumn on Meta_DataObjectColumn.DataObjectID = Meta_DataObject.ID 7 WHERE Meta_DataObject.ID=#id# 8 </select>
4. 批量删除多张表
1 <delete id="DeleteShardingStrategy" parameterClass="string"> 2 begin 3 DELETE FROM Meta_ShardingColumn WHERE ShardingStrategyID=#id# 4 DELETE FROM Meta_ShardingStrategy WHERE ID=#id# 5 end; 6 </delete>
5. 删除指定数据
1 <delete id="DeleteShardingColumns" parameterClass="string"> 2 DELETE FROM Meta_ShardingColumn WHERE DataObjectID=#id# 3 </delete>
6. 查询数据行数
1 <select id="IsTaskExist" resultClass="int" parameterClass="string"> 2 SELECT COUNT(1) FROM TableTask WHERE name=#Name# 3 </select>
以上就是一些简单的IBatis.Net总结。
周国庆
2017/10/14
标签:业界 table 批量 原理 mission logic param r文件 lazy
原文地址:http://www.cnblogs.com/tianqing/p/7668850.html