Author: gilles Date: 2004-11-14 10:58:56 -0600 (Sun, 14 Nov 2004) New Revision: 355
Added: Source1/External-Bin/Net/1.1/NHibernate.dll Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSession.cs Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSessionHandler.cs Modified: Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSessionHandler.cs Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSessionHandler.cs Source1/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj Source1/IBatisNet.DataMapper/SqlMapSession.cs Source1/IBatisNet.sln Log: - Began NHibernate support in DataAccess Added: Source1/External-Bin/Net/1.1/NHibernate.dll =================================================================== (Binary files differ) Property changes on: Source1/External-Bin/Net/1.1/NHibernate.dll ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSession.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSession.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSession.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -0,0 +1,284 @@ + +#region Apache Notice +/***************************************************************************** + * $Header: $ + * $Revision: $ + * $Date: $ + * + * iBATIS.NET Data Mapper + * Copyright (C) 2004 - Gilles Bayon + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ********************************************************************************/ +#endregion + +#region Imports +using System; +using System.Data; + +using IBatisNet.Common; + +using IBatisNet.DataAccess; +using IBatisNet.DataAccess.Exceptions; +using IBatisNet.DataAccess.Interfaces; + +using NHibernate; +using NHibernate.Cfg; + +using log4net; + +#endregion + +#region Remarks + +//<context> +//<transactionManager type="SQLMAP"> +//<property name="SqlMapConfig" value="com/domain/dao/sqlmap/SqlMapConfig.xml"/> +//</transactionManager> +//<dao interface="com.domain.dao.PersonDao" implementation="com.domain.dao.sqlmap.SqlMapPersonDao"/> +//<dao interface="com.domain.dao.BusinessDao" implementation="com.domain.dao.sqlmap.SqlMapBusinessDao"/> +//<dao interface="com.domain.dao.AccountDao" implementation="com.domain.dao.sqlmap.SqlMapAccountDao"/> +//</context> +// +//<!--=============================================== +//Example Hibernate DAO Configuration +//===============================================--> +// +//<context> +//<transactionManager type="HIBERNATE"> +//<property name="hibernate.dialect" value="net.sf.hibernate.dialect.PostgreSQLDialect"/> +//<property name="hibernate.connection.driver_class" value="${driver}"/> +//<property name="hibernate.connection.url" value="${url}"/> +//<property name="hibernate.connection.username" value="${username}"/> +//<property name="hibernate.connection.password" value="${password}"/> +//<property name="class.1" value="com.domain.Person"/> +//<property name="class.2" value="com.domain.Business"/> +//<property name="class.3" value="com.domain.Account"/> +//</transactionManager> +//<dao interface="com.domain.dao.CategoryDao" implementation="com.domain.dao.hbn.HbnCategoryDao"/> +//<dao interface="com.domain.dao.ProductDao" implementation="com.domain.dao.hbn.HbnProductDao"/> +//<dao interface="com.domain.dao.ItemDao" implementation="com.domain.dao.hbn.HbnItemDao"/> +//</context> +// +//<!--=============================================== +//Example JDBC DAO Configuration +//===============================================--> +// +//<context> +//<transactionManager type="JDBC"> +//<property name="DataSource" value="SIMPLE"/> +//<property name="JDBC.Driver" value="${driver}"/> +//<property name="JDBC.ConnectionURL" value="${url}"/> +//<property name="JDBC.Username" value="${username}"/> +//<property name="JDBC.Password" value="${password}"/> +//<property name="JDBC.DefaultAutoCommit" value="true" /> +//<property name="Pool.MaximumActiveConnections" value="10"/> +//<property name="Pool.MaximumIdleConnections" value="5"/> +//<property name="Pool.MaximumCheckoutTime" value="120000"/> +//<property name="Pool.TimeToWait" value="500"/> +//<property name="Pool.PingQuery" value="select 1 from ACCOUNT"/> +//<property name="Pool.PingEnabled" value="false"/> +//<property name="Pool.PingConnectionsOlderThan" value="1"/> +//<property name="Pool.PingConnectionsNotUsedFor" value="1"/> +//<property name="Pool.QuietMode" value="true"/> +//</transactionManager> +//<dao interface="com.domain.dao.OrderDao" implementation="com.domain.dao.jdbc.JdbcOrderDao"/> +//<dao interface="com.domain.dao.LineItemDao" implementation="com.domain.dao.jdbc.JdbcLineItemDao"/> +//<dao interface="com.domain.dao.CustomerDao" implementation="com.domain.dao.jdbc.JdbcCustomerDao"/> +//</context> + +#endregion + + +namespace IBatisNet.DataAccess.DaoSessionHandlers +{ + /// <summary> + /// Summary description for NHibernateDaoSession. + /// </summary> + public class NHibernateDaoSession : DaoSession + { + #region Fields + private ISessionFactory _factory = null; + private DaoManager _daoManager = null; + private ISession _session = null; + private ITransaction _transaction = null; + private bool _consistent = false; + + #endregion + + #region Properties + public ISessionFactory Factory + { + get { return _factory; } + } + + public override DataSource DataSource + { + get + { + throw new DataAccessException("DataSource is not supported with Hibernate."); + } + } + + public override IDbConnection Connection + { + get { return _session.Connection; } + } + + public override IDbTransaction Transaction + { + get { return (_session.Transaction as IDbTransaction); } + } + + #endregion + + #region Constructor (s) / Destructor + public NHibernateDaoSession(DaoManager daoManager, ISessionFactory factory) + { + this.InitDaoSession( daoManager ); + _factory = factory; + } + #endregion + + #region Methods + + public override void InitDaoSession(DaoManager daoManager) + { + _daoManager = daoManager; + } + + /// <summary> + /// Opens a database connection. + /// </summary> + public override void OpenConnection() + { + _session = _factory.OpenSession(); + } + + /// <summary> + /// Closes the connection + /// </summary> + public override void CloseConnection() + { + _session.Flush();// or flush ? + } + + /// <summary> + /// Begins a transaction. + /// </summary> + public override void BeginTransaction() + { + try + { + _session = _factory.OpenSession(); + _transaction = _session.BeginTransaction(); + } + catch (HibernateException e) + { + throw new DataAccessException("Error starting Hibernate transaction. Cause: " + e, e); + } + } + + /// <summary> + /// Begins a transaction at the data source with the specified IsolationLevel value. + /// </summary> + /// <param name="isolationLevel">The transaction isolation level for this connection.</param> + public override void BeginTransaction(IsolationLevel isolationLevel) + { + throw new DataAccessException("IsolationLevel is not supported with Hibernate transaction."); + } + + /// <summary> + /// Commits the database transaction. + /// </summary> + /// <remarks> + /// Will close the connection. + /// </remarks> + public override void CommitTransaction() + { + try + { + _transaction.Commit(); + _session.Close(); + } + catch (HibernateException e) + { + throw new DataAccessException("Error committing Hibernate transaction. Cause: " + e); + } + } + + /// <summary> + /// Rolls back a transaction from a pending state. + /// </summary> + /// <remarks> + /// Will close the connection. + /// </remarks> + public override void RollBackTransaction() + { + try + { + _transaction.Rollback(); + _session.Close(); + } + catch (HibernateException e) + { + throw new DataAccessException("Error ending Hibernate transaction. Cause: " + e); + } + } + + /// <summary> + /// Changes the vote for distributed transaction to commit (true) or to abort (false). + /// </summary> + public override bool Consistent + { + set + { + _consistent = value; + } + } + + public override IDbCommand CreateCommand(CommandType commandType) + { + throw new DataAccessException("CreateCommand is not supported with Hibernate."); + } + + public override IDataParameter CreateDataParameter() + { + throw new DataAccessException("CreateDataParameter is not supported with Hibernate."); + } + + public override IDbDataAdapter CreateDataAdapter() + { + throw new DataAccessException("CreateDataAdapter is not supported with Hibernate."); + } + + public override IDbDataAdapter CreateDataAdapter(IDbCommand command) + { + throw new DataAccessException("CreateDataAdapter is not supported with Hibernate."); + } + #endregion + + #region IDisposable Members + /// <summary> + /// Releasing, or resetting resources. + /// </summary> + public override void Dispose() + { + _session.Dispose(); + } + #endregion + + } +} Added: Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSessionHandler.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSessionHandler.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/NHibernateDaoSessionHandler.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -0,0 +1,91 @@ + +#region Apache Notice +/***************************************************************************** + * $Header: $ + * $Revision: $ + * $Date: $ + * + * iBATIS.NET Data Mapper + * Copyright (C) 2004 - Gilles Bayon + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ********************************************************************************/ +#endregion + +#region Imports +using System; +using System.Collections; + +using IBatisNet.Common; +using IBatisNet.Common.Exceptions; +using IBatisNet.Common.Utilities; + +using IBatisNet.DataAccess; +using IBatisNet.DataAccess.Exceptions; +using IBatisNet.DataAccess.Interfaces; + +using NHibernate.Cfg; +using NHibernate; +#endregion + +namespace IBatisNet.DataAccess.DaoSessionHandlers +{ + /// <summary> + /// Summary description for NHibernateDaoSessionHandler. + /// </summary> + public class NHibernateDaoSessionHandler : IDaoSessionHandler + { + private ISessionFactory _factory = null; + + public ISessionFactory Factory + { + get { return _factory; } + } + + public NHibernateDaoSessionHandler() + { + + } + + public void Configure(Hashtable properties) + { + try + { + NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); + + foreach(DictionaryEntry entry in properties) + { + if ((entry.Key as string).StartsWith("class.")) + { + config.AddClass(Resources.TypeForName(entry.Value as string)); + } + } + + config.Properties = properties; + _factory = config.BuildSessionFactory(); + } + catch(Exception e) + { + throw new ConfigurationException(string.Format("DaoManager could not configure NHibernateDaoSessionHandler. Cause: {0}", e.Message)); + } + } + + public DaoSession GetDaoSession(DaoManager daoManager) + { + return (new NHibernateDaoSession(daoManager, _factory)); + } + + } +} Modified: Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSession.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -81,7 +81,7 @@ } /// <summary> - /// Changes the vote to commit (true) or to abort (false). + /// Changes the vote for distributed transaction to commit (true) or to abort (false). /// </summary> public override bool Consistent { Modified: Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSessionHandler.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSessionHandler.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/SimpleDaoSessionHandler.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -38,7 +38,7 @@ namespace IBatisNet.DataAccess.DaoSessionHandlers { /// <summary> - /// Description résumée de DaoSessionPool. + /// Summary description for SimpleDaoSessionHandler. /// </summary> public class SimpleDaoSessionHandler : IDaoSessionHandler { Modified: Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSession.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -184,7 +184,5 @@ } #endregion - - } } Modified: Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSessionHandler.cs =================================================================== --- Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSessionHandler.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/DaoSessionHandlers/SqlMapDaoSessionHandler.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -43,7 +43,7 @@ namespace IBatisNet.DataAccess.DaoSessionHandlers { /// <summary> - /// Description résumée de SqlMapDaoSessionHandler. + /// Summary description for SqlMapDaoSessionHandler. /// </summary> public class SqlMapDaoSessionHandler : IDaoSessionHandler { Modified: Source1/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj =================================================================== --- Source1/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataAccess/IBatisNet.DataAccess.csproj 2004-11-14 16:58:56 UTC (rev 355) @@ -99,6 +99,11 @@ AssemblyName = "System.Web" HintPath = "D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Web.dll" /> + <Reference + Name = "NHibernate" + AssemblyName = "NHibernate" + HintPath = "..\External-Bin\Net\1.1\NHibernate.dll" + /> </References> </Build> <Files> @@ -155,6 +160,16 @@ BuildAction = "Compile" /> <File + RelPath = "DaoSessionHandlers\NHibernateDaoSession.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "DaoSessionHandlers\NHibernateDaoSessionHandler.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "DaoSessionHandlers\SimpleDaoSession.cs" SubType = "Code" BuildAction = "Compile" Modified: Source1/IBatisNet.DataMapper/SqlMapSession.cs =================================================================== --- Source1/IBatisNet.DataMapper/SqlMapSession.cs 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.DataMapper/SqlMapSession.cs 2004-11-14 16:58:56 UTC (rev 355) @@ -194,7 +194,7 @@ } /// <summary> - /// Changes the vote to commit (true) or to abort (false). + /// Changes the vote for distributed transaction to commit (true) or to abort (false). /// </summary> public bool Consistent { Modified: Source1/IBatisNet.sln =================================================================== --- Source1/IBatisNet.sln 2004-11-14 12:04:44 UTC (rev 354) +++ Source1/IBatisNet.sln 2004-11-14 16:58:56 UTC (rev 355) @@ -55,6 +55,7 @@ External-Bin\Net\1.1\ICSharpCode.SharpZipLib.dll = External-Bin\Net\1.1\ICSharpCode.SharpZipLib.dll External-Bin\Net\1.1\log4net.dll = External-Bin\Net\1.1\log4net.dll External-Bin\Net\1.1\log4net.xml = External-Bin\Net\1.1\log4net.xml + External-Bin\Net\1.1\NHibernate.dll = External-Bin\Net\1.1\NHibernate.dll External-Bin\Net\1.1\nunit.framework.dll = External-Bin\Net\1.1\nunit.framework.dll IBatisNet.Schemas\SqlMap.xsd = IBatisNet.Schemas\SqlMap.xsd IBatisNet.Schemas\SqlMapConfig.xsd = IBatisNet.Schemas\SqlMapConfig.xsd
