Click here to Skip to main content
15,897,273 members
Articles / Mobile Apps

Building applications with Mono

Rate me:
Please Sign up or sign in to vote.
4.56/5 (20 votes)
6 Nov 20032 min read 94.4K   325   32  
Developing .NET cross platform applications using mono and IBM DB2
using System;
using System.Data;
using System.Runtime.InteropServices;

namespace System.Data.DB2Client
{
	public class DB2Transaction : IDbTransaction
	{
		IsolationLevel IL = IsolationLevel.Unspecified;
		DB2Connection db2Conn;
		public DB2Transaction(DB2Connection con, IsolationLevel isoL)
		{
			long db2IsoL = DB2Constants.SQL_TXN_READ_COMMITTED;
			db2Conn = con;
			short sqlRet;

			switch (isoL) 
			{
				case System.Data.IsolationLevel.Chaos:			//No DB2equivalent, default to SQL_TXN_READ_COMMITTED
					break;
				case System.Data.IsolationLevel.ReadCommitted:		//SQL_TXN_READ_COMMITTED
					db2IsoL = DB2Constants.SQL_TXN_READ_COMMITTED;
					break;
				case System.Data.IsolationLevel.ReadUncommitted:		//SQL_TXN_READ_UNCOMMITTED
					db2IsoL = DB2Constants.SQL_TXN_READ_UNCOMMITTED;
					break;
				case System.Data.IsolationLevel.RepeatableRead:		//SQL_TXN_REPEATABLE_READ
					db2IsoL = DB2Constants.SQL_TXN_REPEATABLE_READ;
					break;
				case System.Data.IsolationLevel.Serializable:			//SQL_TXN_SERIALIZABLE_READ
					db2IsoL = DB2Constants.SQL_TXN_SERIALIZABLE_READ;
					break;
			}

			IL = isoL;
			IntPtr iso = new IntPtr(db2IsoL);
			IntPtr attr = new IntPtr(DB2Constants.SQL_AUTOCOMMIT_OFF);
			sqlRet = DB2CLIWrapper.SQLSetConnectAttr(db2Conn.DBHandle, DB2Constants.SQL_AUTOCOMMIT, attr, 0);
			DB2ClientUtils.DB2CheckReturn(sqlRet, DB2Constants.SQL_HANDLE_DBC, db2Conn.DBHandle, "Error setting AUTOCOMMIT OFF in transaction CTOR.");
//	
			
		}

		/// <summary>
		/// DB2Connection associated with this transaction
		/// </summary>
		public IDbConnection Connection
		{
			get
			{
				return db2Conn;
			}
		}
		/// <summary>
		/// IsolationLevel property
		/// </summary>
		/// 
		public IsolationLevel IsolationLevel
		{
			get 
			{
				return IL;
			}
		}

		public void Commit() {
			DB2CLIWrapper.SQLEndTran(DB2Constants.SQL_HANDLE_DBC, db2Conn.DBHandle, DB2Constants.SQL_COMMIT);
			this.db2Conn.WeakRefTransaction = null;
			this.db2Conn = null;
		}

		public void Rollback() 
		{
			DB2CLIWrapper.SQLEndTran(DB2Constants.SQL_HANDLE_DBC, db2Conn.DBHandle, DB2Constants.SQL_ROLLBACK);
			this.db2Conn.WeakRefTransaction = null;
			this.db2Conn = null;
		}

		/// <summary>
		/// Dispose method.
		/// </summary>
		private bool Done = false;
		public void Dispose()
		{
			if (Done) 
				return;
			Rollback();
			IL = IsolationLevel.Unspecified;
			db2Conn = null;
			Done = true;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions