View Full Version : Spring and iBatis
uf766086
07-14-2006, 11:54 AM
Hi all!!!
I suppose answers would be similar to the previous post (Spring + nHibernate) but anyway: is there a schedule for Spring.Data.Orm.iBatis release ? or any sample beta???
Thx in advance
I have tried an implemention based on current sandbox:
SqlMapperDaoSupport:
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Dao.Support;
using IBatisNet.DataMapper;
namespace Spring.Data.IBatis.Support
{
public class SqlMapDaoSupport:DaoSupport
{
private SqlMapperTemplate _sqlMapperTemplate = new SqlMapperTemplate();
private bool _externalTemplate = false;
public SqlMapper SqlMapper
{
get
{
return _sqlMapperTemplate.SqlMapper;
}
set
{
_sqlMapperTemplate.SqlMapper = value;
}
}
public SqlMapperTemplate SqlMapperTemplate
{
get
{
return _sqlMapperTemplate;
}
set
{
_sqlMapperTemplate = value;
_externalTemplate = true;
}
}
protected override void CheckDaoConfig()
{
if (this._externalTemplate == false)
{
}
}
}
}
SqlMapperTemplate
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using IBatisNet.DataMapper;
using Spring.Data.IBatis;
using IBatisNet.Common;
using IBatisNet.Common.Utilities;
using IBatisNet.Common.Utilities.Objects;
using IBatisNet.Common.Utilities.Objects.Members;
using IBatisNet.DataMapper.Configuration;
using IBatisNet.DataMapper.Configuration.Cache;
using IBatisNet.DataMapper.Configuration.ParameterMappin g;
using IBatisNet.DataMapper.Configuration.ResultMapping;
using IBatisNet.DataMapper.DataExchange;
using IBatisNet.DataMapper.Exceptions;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.TypeHandlers;
using Spring.Core.IO;
using Spring.Objects.Factory.Config;
namespace Spring.Data.IBatis
{
public class SqlMapperTemplate
{
private SqlMapper _sqlMapper;
public delegate object DoInSqlMappper(SqlMapper sqlMapper);
public SqlMapperTemplate()
{
}
public SqlMapperTemplate(SqlMapper sqlMapper)
{
_sqlMapper = sqlMapper;
}
public SqlMapper SqlMapper
{
get
{
return _sqlMapper;
}
set
{
_sqlMapper = value;
}
}
/// <summary>
/// 回调doInSqlMapper,调用方法
/// DoInSqlMapper doInSqlMapper=delegate(SqlMapper sqlMapper)
/// {
/// 要执行的方法
/// };
/// Execute(doInSqlMapper);
/// </summary>
/// <param name="doInSqlMapper"></param>
/// <returns></returns>
public object Execute(DoInSqlMappper doInSqlMapper)
{
IDalSession session = this._sqlMapper.LocalSession;
if (session == null)
{
session = new SqlMapSession(_sqlMapper);
}
try
{
session.OpenConnection();
return doInSqlMapper(_sqlMapper);
}
catch (DataMapperException e)
{
throw e;
}
finally
{
session.CloseConnection();
}
}
public T QueryForObject<T>(string statementName, object parameterObject)
{
return _sqlMapper.QueryForObject<T>(statementName,parameterObject);
}
public IList<T> QueryForList<T>(string statementName, object parameterObject)
{
return _sqlMapper.QueryForList<T>(statementName,parameterObject);
}
public IList<T> QueryForList<T>(string statementName, object parameterObject, int skipResults, int maxResults)
{
return _sqlMapper.QueryForList<T>(statementName,parameterObject,skipResults,maxResu lts);
}
public DataTable QueryForDataTable(string statementName,object parameterObject)
{
return _sqlMapper.QueryForDataTable(statementName,paramet erObject);
}
public object Insert(string statementName, object parameterObject)
{
return _sqlMapper.Insert(statementName, parameterObject);
}
public int Update(string statementName, object parameterObject)
{
return _sqlMapper.Update(statementName, parameterObject);
}
public int Delete(string statementName, object parameterObject)
{
return _sqlMapper.Delete(statementName, parameterObject);
}
}
}
brianmir3
08-10-2006, 07:19 AM
Hi, all:
I need the Spring.Data.IBatis & Spring.Objects; I can't find it :( . Please send me(brian.z928@gmail.com) if you has, THX.
bchoi
08-30-2006, 11:42 PM
Hi Anyone can post example of how to use template and daosupport.
I could find only Java exmaple which has different implementation.
zblock
08-31-2006, 03:38 AM
Here's what I've pieced together from Mark's presentation - http://www.springframework.net/presentations/SpringOne-DataAccess-Pollack.ppt and the test projects in the nightly build...
You're object definition will look something like this:
<objects xmlns="http://www.springframework.net">
<object id="CustomerDao" type="SpringSample.CustomerDao, SpringSample">
<property name="DbProvider" ref="DbProvider" />
</object>
<object id="DbProvider"
type="Spring.Data.Support.Oracle.OracleClientProvider, Spring.Data">
<property name="ConnectionString"
value="Data Source=DBINSTANCE; User Id=UID; Password=PWD; Integrated Security=no;"/>
</object>
</objects>
</spring>
And the code:
public class CustomerDao : AdoDaoSupport, ICustomerDao
{
#region ICustomerDao Members
public void Create(Customer customerDao)
{
AdoTemplate.ExecuteNonQuery(CommandType.Text,
String.Format(@"INSERT INTO customer
( id... )
VALUES
(
{0}, ...
)",
"seq_customer.nextval", ...));
}
#endregion
}
Hope that helps
bchoi
09-06-2006, 12:04 AM
Thank you for the reply. I meant for SqlMapDaoSupport though.
In Java you can do this setting DataSource and SqlMapClient properties which is not available in .NET version of base DAO Support.
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.