You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(56) |
Nov
(13) |
Dec
(36) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(7) |
Feb
(55) |
Mar
(33) |
Apr
(71) |
May
(12) |
Jun
|
Jul
(5) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Richard B. <rb...@us...> - 2005-02-07 13:22:17
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_Informix In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12639/Providers/AF_Informix Modified Files: AF_Informix.vbproj CInformixConnection.vb CInformixDatabase.vb Log Message: Completed first attempt at informix provider (untested). Upgraded MySQL provider to official 1.0.4 release Index: CInformixDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_Informix/CInformixDatabase.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CInformixDatabase.vb 7 Feb 2005 07:37:36 -0000 1.1 +++ CInformixDatabase.vb 7 Feb 2005 13:22:06 -0000 1.2 @@ -1,20 +1,20 @@ Option Strict Off Option Explicit On -Imports System.Data.SqlClient +Imports IBM.Data.Informix Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework -''' Class : CMsSqlDatabase +''' Class : CInformixDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> -''' Implementation of CRelationalDatabase for Microsoft SQL Server. +''' Implementation of CRelationalDatabase for IBM Informix Servers. ''' </summary> ''' <remarks>This class contains the specific functionality required for the -''' framework to interact with Microsoft SQL databases.</remarks> +''' framework to interact with Informix databases.</remarks> ''' <history> -''' [rbanks] 11/12/2003 Created +''' [rbanks] 08-Feb-2005 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CInformixDatabase @@ -24,13 +24,15 @@ Private m_user As String Private m_password As String Private m_serverName As String + Private m_host As String + Private m_service As String '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> - ''' <returns>A CMSSqlConnection containing the newly established connection.</returns> - ''' <remarks>The CMSSqlConnection class implements the _CConnection interface which + ''' <returns>A CInformixConnection containing the newly established connection.</returns> + ''' <remarks>The CInformixConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para> ''' <para>The connection is established using normal SQL server authentication (ie @@ -41,7 +43,7 @@ '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New CInformixConnection - conn.Connection = New SqlConnection + conn.Connection = New IfxConnection conn.ManageTransactions = True Try If m_user Is Nothing OrElse m_user.Length = 0 Then @@ -50,29 +52,23 @@ Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) - End If - If m_user = "SSPI" Then - conn.Connection.ConnectionString = _ - "Data Source=" & m_serverName & ";" & _ - "Initial Catalog=" & m_name & ";" & _ - "Integrated Security=SSPI;" & _ - "Persist Security Info=False;" - Else - conn.Connection.ConnectionString = _ - "Data Source=" & m_serverName & ";" & _ - "Initial Catalog=" & m_name & ";" & _ - "Integrated Security=false;" & _ - "Persist Security Info=False;" & _ - "User Id=" & m_user & ";" & _ - "Password=" & m_password - End If - conn.Connection.Open() - Catch ex As SqlClient.SqlException - Throw New DatabaseConnectionException(ex.Message, ex) - Catch ex As Exception - Throw New DatabaseConnectionException(ex.Message, ex) - End Try - getNewConnection = conn + End If + If m_service = String.Empty Then m_service = "8080" + conn.Connection.ConnectionString = _ + "Server=" & m_serverName & ";" & _ + "Database=" & m_name & ";" & _ + "Host=" & m_host & ";" & _ + "Protocol=onsoctcp;" & _ + "Service=" & m_service & ";" & _ + "uid=" & m_user & ";" & _ + "Password=" & m_password + conn.Connection.Open() + Catch ex As IfxException + Throw New DatabaseConnectionException(ex.Message, ex) + Catch ex As Exception + Throw New DatabaseConnectionException(ex.Message, ex) + End Try + getNewConnection = conn End Function '''----------------------------------------------------------------------------- @@ -98,7 +94,9 @@ Public Overrides Sub init(ByVal properties As System.Collections.Specialized.HybridDictionary) m_name = properties.Item("name") m_serverName = properties.Item("serverName") - m_user = properties.Item("user") + m_host = properties.Item("host") + m_service = properties.Item("service") + m_user = properties.Item("user") m_password = properties.Item("password") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False @@ -158,18 +156,11 @@ If dd = Date.MinValue Then tempRetorno = "NULL" Else - If dd.Date.Ticks = 0 Then - 'MSSQL doesn't support dates with years less than 1753, so time only - 'values that format to "0001-01-01 11:23:00" for example produce errors. - 'If it's just a time we will only return time portion. - tempRetorno = "'" & dd.ToString("HH:mm:ss") & "'" - Else - tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" - End If - End If + tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" + End If - System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture - System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture + System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture + System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "1", "0") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal @@ -195,11 +186,11 @@ '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet - Dim da As New SqlDataAdapter - Dim cb As SqlCommandBuilder + Dim da As New IfxDataAdapter + Dim cb As IfxCommandBuilder Dim aValue As Integer Dim row As System.Data.DataRow - Dim p As SqlParameter + Dim p As IfxParameter Dim initvals() As Object = {1} Dim x As OIDException Dim conn As CInformixConnection @@ -207,8 +198,8 @@ conn.AutoCommit = False conn.startTransaction() Try - da.SelectCommand = New SqlCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) - cb = New SqlCommandBuilder(da) + da.SelectCommand = New IfxCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) + cb = New IfxCommandBuilder(da) da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 @@ -221,19 +212,19 @@ da.Update(rs, "oid") da.Dispose() conn.commit() - Catch err As SqlException - conn.rollback() - x = New OIDException(err.Message, err) - Catch err As Exception - conn.rollback() - x = New OIDException(err.Message, err) - Finally - Me.freeConnection(conn) - If Not x Is Nothing Then - Throw x - End If - End Try - Return aValue + Catch err As IfxException + conn.rollback() + x = New OIDException(err.Message, err) + Catch err As Exception + conn.rollback() + x = New OIDException(err.Message, err) + Finally + Me.freeConnection(conn) + If Not x Is Nothing Then + Throw x + End If + End Try + Return aValue End Function '''----------------------------------------------------------------------------- @@ -252,8 +243,8 @@ '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet - Dim da As New SqlDataAdapter - Dim cb As SqlCommandBuilder + Dim da As New IfxDataAdapter + Dim cb As IfxCommandBuilder Dim aValue As Integer Dim connection As CInformixConnection @@ -261,8 +252,8 @@ connection.AutoCommit = False Try - da.SelectCommand = New SqlCommand("select @@IDENTITY", connection.Connection, connection.Transaction) - cb = New SqlCommandBuilder(da) + da.SelectCommand = New IfxCommand("select @@IDENTITY", connection.Connection, connection.Transaction) + cb = New IfxCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value") @@ -275,10 +266,10 @@ Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() - Catch err As SqlException - Throw New IdentityValueException(err.Message, err) - End Try - Return aValue + Catch err As IfxException + Throw New IdentityValueException(err.Message, err) + End Try + Return aValue End Function '''----------------------------------------------------------------------------- @@ -287,7 +278,7 @@ ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> - ''' <remarks>Since the parameter is for an MSSQL connection only a the returned + ''' <remarks>Since the parameter is for an Informix connection only a the returned ''' string is in the format of @pxxx where xxx is the value of the input integer (i).</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created Index: CInformixConnection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_Informix/CInformixConnection.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CInformixConnection.vb 7 Feb 2005 07:37:36 -0000 1.1 +++ CInformixConnection.vb 7 Feb 2005 13:22:06 -0000 1.2 @@ -1,16 +1,16 @@ -Imports System.Data.SqlClient +Imports IBM.Data.Informix Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework -''' Class : CMSSqlConnection +''' Class : CInformixConnection ''' '''----------------------------------------------------------------------------- ''' <summary> -''' Connection class for MSSql data sources +''' Connection class for Informix data sources ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used -''' to manage connections to MSSQL datasources.</para> +''' to manage connections to Informix datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> @@ -19,6 +19,7 @@ ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> +''' <para>Built against client SDK version 2.81.TC3 ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> @@ -30,15 +31,15 @@ Implements IDisposable '************************************************** - 'Class: CMSSqlConnection + 'Class: CInformixConnection 'Author: Richard Banks '************************************************** - Private m_connection As InformixConnection + Private m_connection As IfxConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean - Private m_transaction As sqlTransaction + Private m_transaction As IfxTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase @@ -47,7 +48,7 @@ '''----------------------------------------------------------------------------- ''' <summary> - ''' The actual SQL Server connection for the object. + ''' The actual Informix Server connection for the object. ''' </summary> ''' <value></value> ''' <remarks></remarks> @@ -55,426 +56,408 @@ ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- - Public Property Connection() As SqlConnection - Get - Connection = m_connection - End Get - Set(ByVal Value As SqlConnection) - m_connection = Value - End Set - End Property + Public Property Connection() As IfxConnection + Get + Connection = m_connection + End Get + Set(ByVal Value As IfxConnection) + m_connection = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit - Get - AutoCommit = m_autoCommit - End Get - Set(ByVal Value As Boolean) - m_autoCommit = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit + Get + AutoCommit = m_autoCommit + End Get + Set(ByVal Value As Boolean) + m_autoCommit = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Started() As Boolean Implements _CConnection.Started - Get - Started = m_started - End Get - Set(ByVal Value As Boolean) - m_started = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Started() As Boolean Implements _CConnection.Started + Get + Started = m_started + End Get + Set(ByVal Value As Boolean) + m_started = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions - Get - ManageTransactions = m_manageTransactions - End Get - Set(ByVal Value As Boolean) - m_manageTransactions = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions + Get + ManageTransactions = m_manageTransactions + End Get + Set(ByVal Value As Boolean) + m_manageTransactions = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. - ''' </summary> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub commit() Implements _CConnection.commit - If DEBUG_MODE Then - If m_transactioncalls = 1 Then - System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") - Else - System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") - End If - End If - If Me.ManageTransactions Then - If m_transactioncalls = 1 Then - m_transaction.Commit() - getPersistenceBrokerInstance().commitCache(Me.Database) - Me.Started = False - m_transaction = Nothing - End If - m_transactioncalls -= 1 - End If - End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. + ''' </summary> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub commit() Implements _CConnection.commit + If DEBUG_MODE Then + If m_transactioncalls = 1 Then + System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") + Else + System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") + End If + End If + If Me.ManageTransactions Then + If m_transactioncalls = 1 Then + m_transaction.Commit() + getPersistenceBrokerInstance().commitCache(Me.Database) + Me.Started = False + m_transaction = Nothing + End If + m_transactioncalls -= 1 + End If + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' The current transaction for the connection. - ''' </summary> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public ReadOnly Property Transaction() As SqlTransaction - Get - Transaction = m_transaction - End Get - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' The current transaction for the connection. + ''' </summary> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public ReadOnly Property Transaction() As IfxTransaction + Get + Transaction = m_transaction + End Get + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. - ''' </summary> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Overloads Sub startTransaction() Implements _CConnection.startTransaction - If DEBUG_MODE Then - If m_transactioncalls = 0 Then - System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") - Else - System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") - End If - End If - If Me.ManageTransactions Then - If Not Me.Started Then - m_transaction = m_connection.BeginTransaction - getPersistenceBrokerInstance().startCacheTransaction(Me.Database) - End If - m_transactioncalls += 1 - Me.Started = True - End If - End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. + ''' </summary> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Overloads Sub startTransaction() Implements _CConnection.startTransaction + If DEBUG_MODE Then + If m_transactioncalls = 0 Then + System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") + Else + System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") + End If + End If + If Me.ManageTransactions Then + If Not Me.Started Then + m_transaction = m_connection.BeginTransaction + getPersistenceBrokerInstance().startCacheTransaction(Me.Database) + End If + m_transactioncalls += 1 + Me.Started = True + End If + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. - ''' </summary> - ''' <param name="statement"></param> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' [rbanks] 23/01/2004 Changed to use SQL parameters - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement - Dim m_command As New SqlCommand - Dim m_recordcount As Integer - Dim cp As CSQLParameter - Dim param As SqlParameter - Dim dd As Date + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. + ''' </summary> + ''' <param name="statement"></param> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' [rbanks] 23/01/2004 Changed to use SQL parameters + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement + Dim m_command As New IfxCommand + Dim m_recordcount As Integer + Dim cp As CSQLParameter + Dim param As IfxParameter + Dim dd As Date - Try - m_command.Connection = m_connection - m_command.CommandText = statement.SqlString - For Each cp In statement.Parameters - If Not cp.Ignore Then - param = New SqlParameter - param.ParameterName = cp.Name - param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) - If TypeOf (cp.Value) Is DateTime Then - dd = cp.Value - If dd.Ticks = 0 Then - dd = DateAdd(DateInterval.Year, 1899, dd) - Else - dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) - End If - cp.Value = dd - End If - param.Value = cp.Value - m_command.Parameters.Add(param) - End If - Next - m_command.Transaction = m_transaction - Debug.WriteLine(m_command.CommandText) - m_recordcount = m_command.ExecuteNonQuery() - If m_recordcount = 0 Then - Throw New NothingUpdatedException("No records were affected by the update") - End If - Catch err As SqlException - Throw err - Catch err As Exception - Throw err - End Try - End Sub + Try + m_command.Connection = m_connection + m_command.CommandText = statement.SqlString + For Each cp In statement.Parameters + If Not cp.Ignore Then + param = New IfxParameter + param.ParameterName = cp.Name + param.IfxType = CType(cp.Column.ProviderType, IfxType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If + Next + m_command.Transaction = m_transaction + Debug.WriteLine(m_command.CommandText) + m_recordcount = m_command.ExecuteNonQuery() + If m_recordcount = 0 Then + Throw New NothingUpdatedException("No records were affected by the update") + End If + Catch err As IfxException + Throw err + Catch err As Exception + Throw err + End Try + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. - ''' </summary> - ''' <param name="statement"></param> - ''' <returns></returns> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement - SyncLock GetType(CInformixConnection) - Dim x As RetrieveException - Dim rs As New CResultset - Dim param As SqlParameter - Dim dd As Date - Dim m_command As New SqlCommand + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. + ''' </summary> + ''' <param name="statement"></param> + ''' <returns></returns> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement + SyncLock GetType(CInformixConnection) + Dim x As RetrieveException + Dim rs As New CResultset + Dim param As IfxParameter + Dim dd As Date + Dim m_command As New IfxCommand - If DEBUG_MODE Then - System.Diagnostics.Debug.WriteLine(statement.SqlString) - End If + If DEBUG_MODE Then + System.Diagnostics.Debug.WriteLine(statement.SqlString) + End If - m_command.Connection = m_connection - m_command.CommandText = statement.SqlString - For Each cp As CSQLParameter In statement.Parameters - If Not cp.Ignore Then - param = New SqlParameter - param.ParameterName = cp.Name - param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) - If TypeOf (cp.Value) Is DateTime Then - dd = cp.Value - If dd.Ticks = 0 Then - dd = DateAdd(DateInterval.Year, 1899, dd) - Else - dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) - End If - cp.Value = dd - End If - param.Value = cp.Value - m_command.Parameters.Add(param) - End If - Next + m_command.Connection = m_connection + m_command.CommandText = statement.SqlString + For Each cp As CSQLParameter In statement.Parameters + If Not cp.Ignore Then + param = New IfxParameter + param.ParameterName = cp.Name + param.IfxType = CType(cp.Column.ProviderType, IfxType) + param.Value = cp.Value + m_command.Parameters.Add(param) + End If + Next - Try - Dim m_adapter As New SqlDataAdapter(m_command) - If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction - m_adapter.Fill(rs.ResultSet, "ole") - m_adapter.Dispose() - Catch err As SqlException - x = New RetrieveException("SQL Error: " & err.Message, err) - Catch err As Exception - x = New RetrieveException(err.Message, err) - End Try - If Not x Is Nothing Then - Throw x - End If - processSelectStatement = rs - End SyncLock - End Function + Try + Dim m_adapter As New IfxDataAdapter(m_command) + If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction + m_adapter.Fill(rs.ResultSet, "ole") + m_adapter.Dispose() + Catch err As IfxException + x = New RetrieveException("SQL Error: " & err.Message, err) + Catch err As Exception + x = New RetrieveException(err.Message, err) + End Try + If Not x Is Nothing Then + Throw x + End If + processSelectStatement = rs + End SyncLock + End Function - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. - ''' </summary> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub rollback() Implements _CConnection.rollback - Dim pb As CPersistenceBroker - If DEBUG_MODE Then - If m_transactioncalls = 1 Then - System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") - Else - System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") - End If - End If - If Me.ManageTransactions Then - If m_transactioncalls = 1 Then - Try - m_transaction.Rollback() - Catch ex As Exception - End Try - getPersistenceBrokerInstance().rollbackCache(Me.Database) - Me.Started = False - m_transaction = Nothing - End If - m_transactioncalls -= 1 - End If - End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. + ''' </summary> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub rollback() Implements _CConnection.rollback + Dim pb As CPersistenceBroker + If DEBUG_MODE Then + If m_transactioncalls = 1 Then + System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") + Else + System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") + End If + End If + If Me.ManageTransactions Then + If m_transactioncalls = 1 Then + Try + m_transaction.Rollback() + Catch ex As Exception + End Try + getPersistenceBrokerInstance().rollbackCache(Me.Database) + Me.Started = False + m_transaction = Nothing + End If + m_transactioncalls -= 1 + End If + End Sub - Public Sub New() - MyBase.New() - 'By default we manage tranactions - 'For DB's that do not manage transactions we should - 'set this attribute to false - m_manageTransactions = True - m_references = 0 - End Sub + Public Sub New() + MyBase.New() + 'By default we manage tranactions + 'For DB's that do not manage transactions we should + 'set this attribute to false + m_manageTransactions = True + m_references = 0 + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. - ''' </summary> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Sub CloseConnection() Implements _CConnection.CloseConnection - m_references -= 1 - If m_references = 0 Then - m_connection.Close() - End If - End Sub + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. + ''' </summary> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Sub CloseConnection() Implements _CConnection.CloseConnection + m_references -= 1 + If m_references = 0 Then + m_connection.Close() + End If + End Sub - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed - Get - Return m_connection.State = ConnectionState.Closed - End Get - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed + Get + Return m_connection.State = ConnectionState.Closed + End Get + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount - Get - Return m_references - End Get - Set(ByVal Value As Integer) - m_references = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount + Get + Return m_references + End Get + Set(ByVal Value As Integer) + m_references = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. - ''' </summary> - ''' <param name="tName"></param> - ''' <returns></returns> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 1/12/2003 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema - Dim statement As String - Dim cmd As SqlCommand - Dim dr As SqlDataReader - Dim dt As DataTable + '''----------------------------------------------------------------------------- + ''' <summary> + ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. + ''' </summary> + ''' <param name="tName"></param> + ''' <returns></returns> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 1/12/2003 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema + Dim statement As String + Dim cmd As IfxCommand + Dim dr As IfxDataReader + Dim dt As DataTable - statement = "select * from " & tName - Try - cmd = New SqlCommand(statement, Me.Connection) - dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) - dt = dr.GetSchemaTable - Catch ex As Exception - dt = Nothing - Throw ex - End Try - Return dt - End Function + statement = "select * from " & tName + Try + cmd = New IfxCommand(statement, Me.Connection) + dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) + dt = dr.GetSchemaTable + Catch ex As Exception + dt = Nothing + Throw ex + End Try + Return dt + End Function - Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction - If DEBUG_MODE Then - If m_transactioncalls = 0 Then - System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") - Else - System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") - End If - End If - If Me.ManageTransactions Then - If Not Me.Started Then - m_transaction = m_connection.BeginTransaction(isolationLevel) - getPersistenceBrokerInstance().startCacheTransaction(Me.Database) - End If - m_transactioncalls += 1 - Me.Started = True - End If - End Sub + Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction + If DEBUG_MODE Then + If m_transactioncalls = 0 Then + System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") + Else + System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") + End If + End If + If Me.ManageTransactions Then + If Not Me.Started Then + m_transaction = m_connection.BeginTransaction(isolationLevel) + getPersistenceBrokerInstance().startCacheTransaction(Me.Database) + End If + m_transactioncalls += 1 + Me.Started = True + End If + End Sub - Public Property Database() As _CRelationalDatabase Implements _CConnection.Database - Get - Return m_db - End Get - Set(ByVal Value As _CRelationalDatabase) - m_db = Value - End Set - End Property + Public Property Database() As _CRelationalDatabase Implements _CConnection.Database + Get + Return m_db + End Get + Set(ByVal Value As _CRelationalDatabase) + m_db = Value + End Set + End Property - Public Overloads Sub Dispose() Implements System.IDisposable.Dispose - Dispose(True) - GC.SuppressFinalize(Me) - End Sub + Public Overloads Sub Dispose() Implements System.IDisposable.Dispose + Dispose(True) + GC.SuppressFinalize(Me) + End Sub - Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) - If Not m_disposed Then - If disposing Then - If Me.Started AndAlso Not m_transaction Is Nothing Then - m_transaction.Rollback() - m_transaction = Nothing - End If - If Not m_connection Is Nothing Then - m_connection.Close() - m_connection.Dispose() - m_connection = Nothing - End If - m_db = Nothing - m_disposed = True - End If - End If - End Sub + Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) + If Not m_disposed Then + If disposing Then + If Me.Started AndAlso Not m_transaction Is Nothing Then + m_transaction.Rollback() + m_transaction = Nothing + End If + If Not m_connection Is Nothing Then + m_connection.Close() + m_connection.Dispose() + m_connection = Nothing + End If + m_db = Nothing + m_disposed = True + End If + End If + End Sub - Protected Overrides Sub Finalize() - ' Simply call Dispose(False). - Dispose(False) - End Sub + Protected Overrides Sub Finalize() + ' Simply call Dispose(False). + Dispose(False) + End Sub End Class Index: AF_Informix.vbproj =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_Informix/AF_Informix.vbproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AF_Informix.vbproj 7 Feb 2005 07:37:36 -0000 1.1 +++ AF_Informix.vbproj 7 Feb 2005 13:22:06 -0000 1.2 @@ -1,107 +1,112 @@ -<VisualStudioProject> - <VisualBasic - ProjectType = "Local" - ProductVersion = "7.10.3077" - SchemaVersion = "2.0" - ProjectGuid = "{09659A30-0220-42BF-9478-267278E89692}" - > - <Build> - <Settings - ApplicationIcon = "" - AssemblyKeyContainerName = "" - AssemblyName = "AF_Informix" - AssemblyOriginatorKeyFile = "" - AssemblyOriginatorKeyMode = "None" - DefaultClientScript = "JScript" - DefaultHTMLPageLayout = "Grid" - DefaultTargetSchema = "IE50" - DelaySign = "false" - OutputType = "Library" - OptionCompare = "Binary" - OptionExplicit = "On" - OptionStrict = "Off" - RootNamespace = "AF_Informix" - StartupObject = "" - > - <Config - Name = "Debug" - BaseAddress = "285212672" - ConfigurationOverrideFile = "" - DefineConstants = "" - DefineDebug = "true" - DefineTrace = "true" - DebugSymbols = "true" - IncrementalBuild = "true" - Optimize = "false" - OutputPath = "bin\" - RegisterForComInterop = "false" - RemoveIntegerChecks = "false" - TreatWarningsAsErrors = "false" - WarningLevel = "1" - /> - <Config - Name = "Release" - BaseAddress = "285212672" - ConfigurationOverrideFile = "" - DefineConstants = "" - DefineDebug = "false" - DefineTrace = "true" - DebugSymbols = "false" - IncrementalBuild = "false" - Optimize = "true" - OutputPath = "bin\" - RegisterForComInterop = "false" - RemoveIntegerChecks = "false" - TreatWarningsAsErrors = "false" - WarningLevel = "1" - /> - </Settings> - <References> - <Reference - Name = "System" - AssemblyName = "System" - /> - <Reference - Name = "System.Data" - AssemblyName = "System.Data" - /> - <Reference - Name = "System.XML" - AssemblyName = "System.Xml" - /> - <Reference - Name = "AToMSFramework" - Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" - Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" - /> - </References> - <Imports> - <Import Namespace = "Microsoft.VisualBasic" /> - <Import Namespace = "System" /> - <Import Namespace = "System.Collections" /> - <Import Namespace = "System.Data" /> - <Import Namespace = "System.Diagnostics" /> - </Imports> - </Build> - <Files> - <Include> - <File - RelPath = "AssemblyInfo.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "CInformixConnection.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "CInformixDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - </Include> - </Files> - </VisualBasic> -</VisualStudioProject> - +<VisualStudioProject> + <VisualBasic + ProjectType = "Local" + ProductVersion = "7.10.3077" + SchemaVersion = "2.0" + ProjectGuid = "{09659A30-0220-42BF-9478-267278E89692}" + > + <Build> + <Settings + ApplicationIcon = "" + AssemblyKeyContainerName = "" + AssemblyName = "AF_Informix" + AssemblyOriginatorKeyFile = "" + AssemblyOriginatorKeyMode = "None" + DefaultClientScript = "JScript" + DefaultHTMLPageLayout = "Grid" + DefaultTargetSchema = "IE50" + DelaySign = "false" + OutputType = "Library" + OptionCompare = "Binary" + OptionExplicit = "On" + OptionStrict = "Off" + RootNamespace = "AF_Informix" + StartupObject = "" + > + <Config + Name = "Debug" + BaseAddress = "285212672" + ConfigurationOverrideFile = "" + DefineConstants = "" + DefineDebug = "true" + DefineTrace = "true" + DebugSymbols = "true" + IncrementalBuild = "true" + Optimize = "false" + OutputPath = "bin\" + RegisterForComInterop = "false" + RemoveIntegerChecks = "false" + TreatWarningsAsErrors = "false" + WarningLevel = "1" + /> + <Config + Name = "Release" + BaseAddress = "285212672" + ConfigurationOverrideFile = "" + DefineConstants = "" + DefineDebug = "false" + DefineTrace = "true" + DebugSymbols = "false" + IncrementalBuild = "false" + Optimize = "true" + OutputPath = "bin\" + RegisterForComInterop = "false" + RemoveIntegerChecks = "false" + TreatWarningsAsErrors = "false" + WarningLevel = "1" + /> + </Settings> + <References> + <Reference + Name = "System" + AssemblyName = "System" + /> + <Reference + Name = "System.Data" + AssemblyName = "System.Data" + /> + <Reference + Name = "System.XML" + AssemblyName = "System.Xml" + /> + <Reference + Name = "AToMSFramework" + Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" + Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" + /> + <Reference + Name = "IBM.Data.Informix" + AssemblyName = "IBM.Data.Informix" + HintPath = "..\..\..\..\..\Program Files\Informix\Client-SDK\bin\IBM.Data.Informix.dll" + /> + </References> + <Imports> + <Import Namespace = "Microsoft.VisualBasic" /> + <Import Namespace = "System" /> + <Import Namespace = "System.Collections" /> + <Import Namespace = "System.Data" /> + <Import Namespace = "System.Diagnostics" /> + </Imports> + </Build> + <Files> + <Include> + <File + RelPath = "AssemblyInfo.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CInformixConnection.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CInformixDatabase.vb" + SubType = "Code" + BuildAction = "Compile" + /> + </Include> + </Files> + </VisualBasic> +</VisualStudioProject> + |
From: Richard B. <rb...@us...> - 2005-02-07 13:22:16
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MySQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12639/Providers/AF_MySQL Modified Files: AF_MySQL.vbproj CMySQLConnection.vb CMySqlDatabase.vb Log Message: Completed first attempt at informix provider (untested). Upgraded MySQL provider to official 1.0.4 release Index: CMySqlDatabase.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_MySQL/CMySqlDatabase.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CMySqlDatabase.vb 7 Feb 2005 07:37:53 -0000 1.1 +++ CMySqlDatabase.vb 7 Feb 2005 13:22:07 -0000 1.2 @@ -2,7 +2,7 @@ Option Explicit On 'Imports System.Data.OleDb -Imports ByteFX.Data.MySqlClient +Imports MySql.Data.MySqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- Index: CMySQLConnection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_MySQL/CMySQLConnection.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CMySQLConnection.vb 7 Feb 2005 07:37:53 -0000 1.1 +++ CMySQLConnection.vb 7 Feb 2005 13:22:07 -0000 1.2 @@ -1,4 +1,4 @@ -Imports ByteFX.Data.MySqlClient +Imports MySql.Data.MySqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- Index: AF_MySQL.vbproj =================================================================== RCS file: /cvsroot/jcframework/dotnet/Providers/AF_MySQL/AF_MySQL.vbproj,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AF_MySQL.vbproj 7 Feb 2005 07:37:37 -0000 1.1 +++ AF_MySQL.vbproj 7 Feb 2005 13:22:06 -0000 1.2 @@ -1,112 +1,112 @@ -<VisualStudioProject> - <VisualBasic - ProjectType = "Local" - ProductVersion = "7.10.3077" - SchemaVersion = "2.0" - ProjectGuid = "{0421A413-1FDE-452E-AB47-82E2CD959461}" - > - <Build> - <Settings - ApplicationIcon = "" - AssemblyKeyContainerName = "" - AssemblyName = "AF_MySQL" - AssemblyOriginatorKeyFile = "" - AssemblyOriginatorKeyMode = "None" - DefaultClientScript = "JScript" - DefaultHTMLPageLayout = "Grid" - DefaultTargetSchema = "IE50" - DelaySign = "false" - OutputType = "Library" - OptionCompare = "Binary" - OptionExplicit = "On" - OptionStrict = "Off" - RootNamespace = "AF_MySQL" - StartupObject = "" - > - <Config - Name = "Debug" - BaseAddress = "285212672" - ConfigurationOverrideFile = "" - DefineConstants = "" - DefineDebug = "true" - DefineTrace = "true" - DebugSymbols = "true" - IncrementalBuild = "true" - Optimize = "false" - OutputPath = "bin\" - RegisterForComInterop = "false" - RemoveIntegerChecks = "false" - TreatWarningsAsErrors = "false" - WarningLevel = "1" - /> - <Config - Name = "Release" - BaseAddress = "285212672" - ConfigurationOverrideFile = "" - DefineConstants = "" - DefineDebug = "false" - DefineTrace = "true" - DebugSymbols = "false" - IncrementalBuild = "false" - Optimize = "true" - OutputPath = "bin\" - RegisterForComInterop = "false" - RemoveIntegerChecks = "false" - TreatWarningsAsErrors = "false" - WarningLevel = "1" - /> - </Settings> - <References> - <Reference - Name = "System" - AssemblyName = "System" - /> - <Reference - Name = "System.Data" - AssemblyName = "System.Data" - /> - <Reference - Name = "System.XML" - AssemblyName = "System.Xml" - /> - <Reference - Name = "ByteFX.MySqlClient" - AssemblyName = "ByteFX.MySqlClient" - HintPath = "..\..\ByteFX.MySqlClient.dll" - /> - <Reference - Name = "AToMSFramework" - Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" - Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" - /> - </References> - <Imports> - <Import Namespace = "Microsoft.VisualBasic" /> - <Import Namespace = "System" /> - <Import Namespace = "System.Collections" /> - <Import Namespace = "System.Data" /> - <Import Namespace = "System.Diagnostics" /> - </Imports> - </Build> - <Files> - <Include> - <File - RelPath = "AssemblyInfo.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "CMySQLConnection.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "CMySqlDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - </Include> - </Files> - </VisualBasic> -</VisualStudioProject> - +<VisualStudioProject> + <VisualBasic + ProjectType = "Local" + ProductVersion = "7.10.3077" + SchemaVersion = "2.0" + ProjectGuid = "{0421A413-1FDE-452E-AB47-82E2CD959461}" + > + <Build> + <Settings + ApplicationIcon = "" + AssemblyKeyContainerName = "" + AssemblyName = "AF_MySQL" + AssemblyOriginatorKeyFile = "" + AssemblyOriginatorKeyMode = "None" + DefaultClientScript = "JScript" + DefaultHTMLPageLayout = "Grid" + DefaultTargetSchema = "IE50" + DelaySign = "false" + OutputType = "Library" + OptionCompare = "Binary" + OptionExplicit = "On" + OptionStrict = "Off" + RootNamespace = "AF_MySQL" + StartupObject = "" + > + <Config + Name = "Debug" + BaseAddress = "285212672" + ConfigurationOverrideFile = "" + DefineConstants = "" + DefineDebug = "true" + DefineTrace = "true" + DebugSymbols = "true" + IncrementalBuild = "true" + Optimize = "false" + OutputPath = "bin\" + RegisterForComInterop = "false" + RemoveIntegerChecks = "false" + TreatWarningsAsErrors = "false" + WarningLevel = "1" + /> + <Config + Name = "Release" + BaseAddress = "285212672" + ConfigurationOverrideFile = "" + DefineConstants = "" + DefineDebug = "false" + DefineTrace = "true" + DebugSymbols = "false" + IncrementalBuild = "false" + Optimize = "true" + OutputPath = "bin\" + RegisterForComInterop = "false" + RemoveIntegerChecks = "false" + TreatWarningsAsErrors = "false" + WarningLevel = "1" + /> + </Settings> + <References> + <Reference + Name = "System" + AssemblyName = "System" + /> + <Reference + Name = "System.Data" + AssemblyName = "System.Data" + /> + <Reference + Name = "System.XML" + AssemblyName = "System.Xml" + /> + <Reference + Name = "AToMSFramework" + Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" + Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" + /> + <Reference + Name = "MySql.Data" + AssemblyName = "MySql.Data" + HintPath = "..\..\..\..\..\Program Files\MySQL\MySQL Connector Net 1.0.4\bin\.NET 1.1\MySql.Data.dll" + /> + </References> + <Imports> + <Import Namespace = "Microsoft.VisualBasic" /> + <Import Namespace = "System" /> + <Import Namespace = "System.Collections" /> + <Import Namespace = "System.Data" /> + <Import Namespace = "System.Diagnostics" /> + </Imports> + </Build> + <Files> + <Include> + <File + RelPath = "AssemblyInfo.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CMySQLConnection.vb" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "CMySqlDatabase.vb" + SubType = "Code" + BuildAction = "Compile" + /> + </Include> + </Files> + </VisualBasic> +</VisualStudioProject> + |
From: Richard B. <rb...@us...> - 2005-02-07 07:38:17
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604 Modified Files: AToMSFramework.vbproj CConnection.vb CPersistenceBroker.vb CSqlStatement.vb CXMLConfigLoader.vb XMLMapping.xsd XMLMapping.xsx modAliasNull.vb Added Files: AToMSFramework.sln Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider Index: modAliasNull.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/modAliasNull.vb,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- modAliasNull.vb 9 Nov 2004 11:46:04 -0000 1.6 +++ modAliasNull.vb 7 Feb 2005 07:37:35 -0000 1.7 @@ -15,7 +15,7 @@ ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- -Module modAliasNull +Public Module modAliasNull '----------------------------------------------------------- 'VBPJ Junio 2000 Index: AToMSFramework.vbproj =================================================================== RCS file: /cvsroot/jcframework/dotnet/AToMSFramework.vbproj,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- AToMSFramework.vbproj 23 Dec 2004 01:14:44 -0000 1.21 +++ AToMSFramework.vbproj 7 Feb 2005 07:37:33 -0000 1.22 @@ -77,16 +77,6 @@ Name = "Microsoft.VisualBasic.Compatibility.Data" AssemblyName = "Microsoft.VisualBasic.Compatibility.Data" /> - <Reference - Name = "ByteFX.MySqlClient" - AssemblyName = "ByteFX.MySqlClient" - HintPath = "..\ByteFX.MySqlClient.76.NI\ByteFX.MySqlClient.dll" - /> - <Reference - Name = "System.Data.OracleClient" - AssemblyName = "System.Data.OracleClient" - HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.OracleClient.dll" - /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> @@ -219,16 +209,6 @@ BuildAction = "Compile" /> <File - RelPath = "CMsAccessDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "CMsSqlDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "CMultiRetrieveCriteria.vb" SubType = "Code" BuildAction = "Compile" @@ -239,11 +219,6 @@ BuildAction = "Compile" /> <File - RelPath = "CMySqlDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "CNotBetweenCriteria.vb" SubType = "Code" BuildAction = "Compile" @@ -259,11 +234,6 @@ BuildAction = "Compile" /> <File - RelPath = "CODBCDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "COID.vb" SubType = "Code" BuildAction = "Compile" @@ -274,11 +244,6 @@ BuildAction = "Compile" /> <File - RelPath = "COracleDatabase.vb" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "COrderEntry.vb" SubType = "Code" BuildAction = "Compile" Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- CPersistenceBroker.vb 6 Feb 2005 02:44:00 -0000 1.90 +++ CPersistenceBroker.vb 7 Feb 2005 07:37:34 -0000 1.91 @@ -182,12 +182,6 @@ conn.AutoCommit = False Try retrieveObject = retrievePrivateObject(obj, conn, useFind, useCache) - Catch ex As SqlClient.SqlException - x = New RetrieveException(ex.Message, ex) - Catch ex As ByteFX.Data.MySqlClient.MySqlException - x = New RetrieveException(ex.Message, ex) - Catch ex As OleDb.OleDbException - x = New RetrieveException(ex.Message, ex) Catch ex As Exception x = New RetrieveException(ex.Message, ex) Finally @@ -201,7 +195,7 @@ If Not x Is Nothing Then Throw x End If - End Try + End Try End SyncLock End Function @@ -2590,19 +2584,19 @@ Return getObjectsToSave(obj, True, checkAssociationsRecursivly) End Function - Friend Sub GetLoginDetails(ByVal sender As _CRelationalDatabase, ByRef User As String, ByRef Password As String) + Public Sub GetLoginDetails(ByVal sender As _CRelationalDatabase, ByRef User As String, ByRef Password As String) RaiseEvent LoginDetailsNeeded(sender, User, Password) End Sub - Friend Sub startCacheTransaction(ByVal reldb As _CRelationalDatabase) + Public Sub startCacheTransaction(ByVal reldb As _CRelationalDatabase) m_cache.StartTransaction(reldb) End Sub - Friend Sub commitCache(ByVal reldb As _CRelationalDatabase) + Public Sub commitCache(ByVal reldb As _CRelationalDatabase) m_cache.CommitChanges(reldb) End Sub - Friend Sub rollbackCache(ByVal reldb As _CRelationalDatabase) + Public Sub rollbackCache(ByVal reldb As _CRelationalDatabase) m_cache.AbortChanges(reldb) End Sub Index: XMLMapping.xsd =================================================================== RCS file: /cvsroot/jcframework/dotnet/XMLMapping.xsd,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XMLMapping.xsd 15 Dec 2004 23:46:12 -0000 1.1 +++ XMLMapping.xsd 7 Feb 2005 07:37:35 -0000 1.2 @@ -16,7 +16,7 @@ </xs:element> </xs:sequence> <xs:attribute name="name" form="unqualified" type="xs:string" use="required" /> - <xs:attribute name="class" form="unqualified" type="DBClassType" use="required" /> + <xs:attribute name="provider" form="unqualified" type="DBClassType" use="required" /> </xs:complexType> </xs:element> <xs:element name="class"> @@ -94,11 +94,11 @@ </xs:simpleType> <xs:simpleType name="DBClassType"> <xs:restriction base="xs:string"> - <xs:enumeration value="CMsSqlDatabase" /> - <xs:enumeration value="CMsAccessDatabase" /> - <xs:enumeration value="CMySqlDatabase" /> - <xs:enumeration value="CODBCDatabase" /> - <xs:enumeration value="CMaxDBDatabase" /> + <xs:enumeration value="AF_MSSQL" /> + <xs:enumeration value="AF_OLEDB" /> + <xs:enumeration value="AF_MySQL" /> + <xs:enumeration value="AF_ODBC" /> + <xs:enumeration value="AF_MSOracle" /> </xs:restriction> </xs:simpleType> <xs:simpleType name="paramNames"> Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- CXMLConfigLoader.vb 9 Nov 2004 11:46:04 -0000 1.29 +++ CXMLConfigLoader.vb 7 Feb 2005 07:37:35 -0000 1.30 @@ -4,6 +4,7 @@ Imports System.Reflection Imports System.Collections.Specialized Imports System.Xml +Imports System.IO '''----------------------------------------------------------------------------- ''' Project : AToMSFramework @@ -208,18 +209,33 @@ Dim relDb As _CRelationalDatabase relDb = Nothing Dim attrPMName As String - Dim attrClassName As XmlAttribute + Dim attrProviderName As XmlAttribute attrPMName = node.GetAttribute("name") - attrClassName = node.GetAttributeNode("class") + attrProviderName = node.GetAttributeNode("provider") Dim params As HybridDictionary Dim nodeChild As XmlNode Dim elementChild As XmlElement Dim attrName, attrValue As XmlAttribute - If ((Not attrPMName Is Nothing) And (Not attrClassName Is Nothing)) Then + ' + ' Need to load the provider .dll file and find a class that implements the + ' appropriate interface. + ' + + Dim pAsm As [Assembly] + Dim types(), t, reldbType As Type + If ((Not attrPMName Is Nothing) And (Not attrProviderName Is Nothing)) Then Try - relDb = Activator.CreateInstance(Type.GetType("AToMSFramework." + attrClassName.Value)) + pAsm = [Assembly].LoadFrom(attrProviderName.Value) + types = pAsm.GetTypes() + For Each t In types + If t.IsSubclassOf(GetType(CRelationalDatabase)) Then + reldbType = t + Exit For + End If + Next + relDb = Activator.CreateInstance(reldbType) Catch ex As Exception - Throw New XMLMappingException("Database Class " & attrClassName.Value & " does not exist in the AtomsFramework", ex) + Throw New XMLMappingException("Error Initialising Database Provider " & attrProviderName.Value & ". Error is: " & ex.Message, ex) End Try relDb.Name = attrPMName params = New HybridDictionary @@ -238,6 +254,8 @@ nodeChild = nodeChild.NextSibling Loop relDb.init(params) + Else + Throw New XMLMappingException("XML Database Mapping is missing provider and/or name attributes.") End If getRelationalDatabase = relDb Index: CConnection.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CConnection.vb,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- CConnection.vb 2 Feb 2005 05:08:37 -0000 1.32 +++ CConnection.vb 7 Feb 2005 07:37:34 -0000 1.33 @@ -1,11 +1,7 @@ Option Strict Off Option Explicit On -Imports System.Data.OleDb Imports System.Data.SqlClient -Imports ByteFX.Data.MySqlClient -Imports System.Data.Odbc -Imports System.Data.OracleClient '''----------------------------------------------------------------------------- ''' <summary> [...2290 lines suppressed...] - m_transaction = Nothing - End If - If Not m_connection Is Nothing Then - m_connection.Close() - m_connection.Dispose() - m_connection = Nothing - End If - m_db = Nothing - m_disposed = True - End If - End If - End Sub - - Protected Overrides Sub Finalize() - ' Simply call Dispose(False). - Dispose(False) - End Sub -End Class +End Interface \ No newline at end of file Index: XMLMapping.xsx =================================================================== RCS file: /cvsroot/jcframework/dotnet/XMLMapping.xsx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XMLMapping.xsx 15 Dec 2004 23:46:12 -0000 1.1 +++ XMLMapping.xsx 7 Feb 2005 07:37:35 -0000 1.2 @@ -1,20 +1,20 @@ <?xml version="1.0" encoding="utf-8"?> <!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.--> -<XSDDesignerLayout layoutVersion="2" viewPortLeft="-605" viewPortTop="4209" zoom="100"> - <map_XmlElement left="6112" top="979" width="7567" height="2963" selected="0" zOrder="11" index="0" expanded="1"> - <database_XmlElement left="398" top="4450" width="5292" height="2963" selected="0" zOrder="12" index="0" expanded="1"> - <parameter_XmlElement left="398" top="7921" width="5292" height="2964" selected="0" zOrder="14" index="0" expanded="1" /> +<XSDDesignerLayout layoutVersion="2" viewPortLeft="-602" viewPortTop="2598" zoom="100"> + <map_XmlElement left="6112" top="979" width="7567" height="2963" selected="0" zOrder="8" index="0" expanded="1"> + <database_XmlElement left="398" top="4450" width="5292" height="2963" selected="0" zOrder="9" index="0" expanded="1"> + <parameter_XmlElement left="398" top="7921" width="5292" height="2964" selected="0" zOrder="11" index="0" expanded="1" /> </database_XmlElement> - <class_XmlElement left="6324" top="4450" width="7143" height="7196" selected="0" zOrder="16" index="1" expanded="1"> - <attribute_XmlElement left="7250" top="12154" width="5291" height="4656" selected="0" zOrder="18" index="0" expanded="1" /> + <class_XmlElement left="6324" top="4450" width="7143" height="7196" selected="0" zOrder="13" index="1" expanded="1"> + <attribute_XmlElement left="7250" top="12154" width="5291" height="4656" selected="0" zOrder="15" index="0" expanded="1" /> </class_XmlElement> - <association_XmlElement left="14101" top="4450" width="5292" height="5926" selected="0" zOrder="20" index="2" expanded="1"> - <entry_XmlElement left="14101" top="10884" width="5292" height="2963" selected="0" zOrder="22" index="0" expanded="1" /> + <association_XmlElement left="14101" top="4450" width="5292" height="5926" selected="0" zOrder="17" index="2" expanded="1"> + <entry_XmlElement left="14101" top="10884" width="5292" height="2963" selected="0" zOrder="19" index="0" expanded="1" /> </association_XmlElement> </map_XmlElement> - <TrueFalse_XmlSimpleType left="15099" top="1079" width="5292" height="2540" selected="0" zOrder="24" index="1" expanded="1" /> - <cardinality_XmlSimpleType left="19818" top="3758" width="5291" height="2963" selected="0" zOrder="25" index="2" expanded="1" /> - <keyType_XmlSimpleType left="19844" top="6985" width="5291" height="2963" selected="0" zOrder="26" index="3" expanded="1" /> - <DBClassType_XmlSimpleType left="479" top="11335" width="5292" height="2963" selected="0" zOrder="27" index="4" expanded="1" /> - <paramNames_XmlSimpleType left="691" top="14583" width="5292" height="2963" selected="0" zOrder="29" index="5" expanded="1" /> + <TrueFalse_XmlSimpleType left="15099" top="1079" width="5292" height="2540" selected="0" zOrder="23" index="1" expanded="1" /> + <cardinality_XmlSimpleType left="19818" top="3758" width="5291" height="2963" selected="0" zOrder="24" index="2" expanded="1" /> + <keyType_XmlSimpleType left="19844" top="6985" width="5291" height="2963" selected="0" zOrder="25" index="3" expanded="1" /> + <DBClassType_XmlSimpleType left="479" top="11335" width="5292" height="2963" selected="0" zOrder="21" index="4" expanded="1" /> + <paramNames_XmlSimpleType left="691" top="14583" width="5292" height="2963" selected="0" zOrder="22" index="5" expanded="1" /> </XSDDesignerLayout> \ No newline at end of file Index: CSqlStatement.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CSqlStatement.vb,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- CSqlStatement.vb 18 Oct 2004 03:31:51 -0000 1.11 +++ CSqlStatement.vb 7 Feb 2005 07:37:35 -0000 1.12 @@ -170,67 +170,67 @@ ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- -Friend Class CSQLParameter +Public Class CSQLParameter Private m_Name As String Private m_Column As CColumnMap Private m_Value As Object Private m_ignore As Boolean - '''----------------------------------------------------------------------------- - ''' <summary> - ''' The name of the parameter - ''' </summary> - ''' <value></value> - ''' <remarks>All parameter names are of the format @pxxx where xxx is a number</remarks> - ''' <history> - ''' [rbanks] 23/01/2004 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Name() As String - Get - Return m_Name - End Get - Set(ByVal Value As String) - m_Name = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' The name of the parameter + ''' </summary> + ''' <value></value> + ''' <remarks>All parameter names are of the format @pxxx where xxx is a number</remarks> + ''' <history> + ''' [rbanks] 23/01/2004 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Name() As String + Get + Return m_Name + End Get + Set(ByVal Value As String) + m_Name = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' The column map the parameter value relates to - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 23/01/2004 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Column() As CColumnMap - Get - Return m_Column - End Get - Set(ByVal Value As CColumnMap) - m_Column = Value - End Set - End Property + '''----------------------------------------------------------------------------- + ''' <summary> + ''' The column map the parameter value relates to + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 23/01/2004 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Column() As CColumnMap + Get + Return m_Column + End Get + Set(ByVal Value As CColumnMap) + m_Column = Value + End Set + End Property - '''----------------------------------------------------------------------------- - ''' <summary> - ''' The value to be passed into the SQL statement. - ''' </summary> - ''' <value></value> - ''' <remarks></remarks> - ''' <history> - ''' [rbanks] 23/01/2004 Created - ''' </history> - '''----------------------------------------------------------------------------- - Public Property Value() As Object - Get - Return m_Value - End Get - Set(ByVal InValue As Object) - m_Value = InValue - End Set + '''----------------------------------------------------------------------------- + ''' <summary> + ''' The value to be passed into the SQL statement. + ''' </summary> + ''' <value></value> + ''' <remarks></remarks> + ''' <history> + ''' [rbanks] 23/01/2004 Created + ''' </history> + '''----------------------------------------------------------------------------- + Public Property Value() As Object + Get + Return m_Value + End Get + Set(ByVal InValue As Object) + m_Value = InValue + End Set End Property Public Property Ignore() As Boolean --- NEW FILE: AToMSFramework.sln --- Microsoft Visual Studio Solution File, Format Version 8.00 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AToMSFramework", "AToMSFramework.vbproj", "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_OLEDB", "Providers\AF_OLEDB\AF_OLEDB.vbproj", "{1E2BB267-A506-4F32-B2E0-6672184EC6BF}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_ODBC", "Providers\AF_ODBC\AF_ODBC.vbproj", "{DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_MySQL", "Providers\AF_MySQL\AF_MySQL.vbproj", "{0421A413-1FDE-452E-AB47-82E2CD959461}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_MSSQL", "Providers\AF_MSSQL\AF_MSSQL.vbproj", "{11985DFB-9B77-434C-98F2-89C219C5B506}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_MSOracle", "Providers\AF_MSOracle\AF_MSOracle.vbproj", "{D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_MaxDB", "Providers\AF_MaxDB\AF_MaxDB.vbproj", "{7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AF_Informix", "Providers\AF_Informix\AF_Informix.vbproj", "{09659A30-0220-42BF-9478-267278E89692}" ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject Global GlobalSection(DPCodeReviewSolutionGUID) = preSolution DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} EndGlobalSection GlobalSection(SolutionConfiguration) = preSolution Debug = Debug Release = Release EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}.Debug.ActiveCfg = Debug|.NET {8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}.Debug.Build.0 = Debug|.NET {8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}.Release.ActiveCfg = Release|.NET {8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}.Release.Build.0 = Release|.NET {1E2BB267-A506-4F32-B2E0-6672184EC6BF}.Debug.ActiveCfg = Debug|.NET {1E2BB267-A506-4F32-B2E0-6672184EC6BF}.Debug.Build.0 = Debug|.NET {1E2BB267-A506-4F32-B2E0-6672184EC6BF}.Release.ActiveCfg = Release|.NET {1E2BB267-A506-4F32-B2E0-6672184EC6BF}.Release.Build.0 = Release|.NET {DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}.Debug.ActiveCfg = Debug|.NET {DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}.Debug.Build.0 = Debug|.NET {DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}.Release.ActiveCfg = Release|.NET {DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}.Release.Build.0 = Release|.NET {0421A413-1FDE-452E-AB47-82E2CD959461}.Debug.ActiveCfg = Debug|.NET {0421A413-1FDE-452E-AB47-82E2CD959461}.Debug.Build.0 = Debug|.NET {0421A413-1FDE-452E-AB47-82E2CD959461}.Release.ActiveCfg = Release|.NET {0421A413-1FDE-452E-AB47-82E2CD959461}.Release.Build.0 = Release|.NET {11985DFB-9B77-434C-98F2-89C219C5B506}.Debug.ActiveCfg = Debug|.NET {11985DFB-9B77-434C-98F2-89C219C5B506}.Debug.Build.0 = Debug|.NET {11985DFB-9B77-434C-98F2-89C219C5B506}.Release.ActiveCfg = Release|.NET {11985DFB-9B77-434C-98F2-89C219C5B506}.Release.Build.0 = Release|.NET {D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}.Debug.ActiveCfg = Debug|.NET {D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}.Debug.Build.0 = Debug|.NET {D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}.Release.ActiveCfg = Release|.NET {D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}.Release.Build.0 = Release|.NET {7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}.Debug.ActiveCfg = Debug|.NET {7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}.Debug.Build.0 = Debug|.NET {7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}.Release.ActiveCfg = Release|.NET {7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}.Release.Build.0 = Release|.NET {09659A30-0220-42BF-9478-267278E89692}.Debug.ActiveCfg = Debug|.NET {09659A30-0220-42BF-9478-267278E89692}.Debug.Build.0 = Debug|.NET {09659A30-0220-42BF-9478-267278E89692}.Release.ActiveCfg = Release|.NET {09659A30-0220-42BF-9478-267278E89692}.Release.Build.0 = Release|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal |
From: Richard B. <rb...@us...> - 2005-02-07 07:38:07
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MySQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_MySQL Added Files: AF_MySQL.vbproj AssemblyInfo.vb CMySQLConnection.vb CMySqlDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("01A0B977-9E65-4337-8ADB-CD71D6A5ED5F")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: CMySqlDatabase.vb --- Option Strict Off Option Explicit On 'Imports System.Data.OleDb Imports ByteFX.Data.MySqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMySqlDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for MySQL Servers. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with MySQL databases. ADO.NET functionality is provided ''' through the ByteFX provider libraries available at <see href="http://www.bytefx.com">Byte FX</see>. ''' <para>The transaction handling version of MySQL should be used (ie mySql-max or similar).</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMySqlDatabase Inherits CRelationalDatabase '************************************************** 'Class: CMySqlDatabase 'Author: Juan Carlos Alvarez '************************************************** Private m_name As String Private m_user As String Private m_password As String Private m_serverName As String Private m_portNumber As String Private m_option As String '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A CMySqlConnection containing the newly established connection.</returns> ''' <remarks>The CMySqlConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New CMySqlConnection conn.Connection = New MySqlConnection 'MySql can manage transactions in if the mysql-max version is used. conn.ManageTransactions = True 'If you have the server on a local machine: 'The values (parameters defined in the xml file) are: 'option = 16834 'If you have the server on a remote machine 'The values (parameters defined in the xml file) are: 'option = 131072 If m_user Is Nothing OrElse m_user.Length = 0 Then m_user = "" m_password = "" Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) End If If m_user Is Nothing OrElse m_user.Length = 0 Then conn.Connection.ConnectionString = "Server=" & m_serverName & ";" & "Database=" & m_name & ";" Else conn.Connection.ConnectionString = "Server=" & m_serverName & ";" & "Database=" & m_name & ";" & "User ID=" & m_user & ";" & "Password=" & m_password End If conn.Connection.Open() 'If you have the server on a remote machine 'portNumber is by default 3306 'server for example is mydb.database.com 'conn.Connection.Open "Driver={mySQL};" & _ '"Server=" & m_serverName & ";" & _ '"Port=" & m_portNumber & ";" & _ '"Option=131072;" & _ '"Stmt=;" & _ '"Database=" & m_name & ";" & _ '"User Id=" & m_user & ";" & _ '"Password=" & m_password getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied ''' <list type="bullet"> ''' <item><description>Name: The name of the database on the server (ie the catalog name)</description></item> ''' <item><description>ServerName: The name of the database server</description></item> ''' <item><description>User: The user name for secured databases.</description></item> ''' <item><description>Password: The password for secured databases.</description></item> ''' <item><description>PortNumber: (optional - unused) The port number the database is running on.</description></item> ''' <item><description>Option: (optional - unused) Other options to pass in the connection string.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As System.Collections.Specialized.HybridDictionary) m_name = properties.Item("name") m_serverName = properties.Item("serverName") m_user = properties.Item("user") m_password = properties.Item("password") m_portNumber = properties.Item("portNumber") m_option = properties.Item("option") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in single quotes. If the string is already enclosed in single quotes then ''' nothing is changed. Also, any single quotes within the string are converted to a pair of single quotes.</para> ''' <para>Dates are converted to yyyy-MM-dd HH:mm:ss format and enclosed in single quotes. If a datetime field ''' only has a time value, then a time-only string is returned instead.</para> ''' <para>Booleans are converted to 1 or 0</para> ''' <para>Numbers are converted to strings directly. Note that floating point numbers from locales that use ''' a comma for the decimal marker are converted to use the period as the decimal marker.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then tempRetorno = "NULL" Else Select Case VarType(tempValue) Case VariantType.String If Left(tempValue, 1) = "'" And Right(tempValue, 1) = "'" And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quote with double quote, and enclose entire string in quotes tempRetorno = "'" & Replace(tempValue, "'", "''") & "'" End If Case VariantType.Date TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean 'tempRetorno = IIf(tempValue, "TRUE", "FALSE") tempRetorno = IIf(tempValue, "1", "0") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = Replace(tempValue, ",", ".") Case Else tempRetorno = tempValue End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New MySqlDataAdapter Dim cb As MySqlCommandBuilder Dim aValue As Integer Dim row As System.Data.DataRow Dim p As MySqlParameter Dim initvals() As Object = {1} Dim x As OIDException Dim conn As CMySqlConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try da.SelectCommand = New MySqlCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) cb = New MySqlCommandBuilder(da) da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As MySqlException conn.rollback() x = New OIDException(err.Message, err) Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying LAST_INSERT_ID.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New MySqlDataAdapter Dim cb As MySqlCommandBuilder Dim aValue As Integer Dim connection As CMySqlConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New MySqlCommand("select LAST_INSERT_ID()", connection.Connection, connection.Transaction) cb = New MySqlCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As MySqlException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> ''' <remarks>Since the parameter is for a MySQL connection only a single ''' question mark (?) is returned. (This required validation)</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String 'Return "?" Return "@p" & CStr(i) End Function Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return Me.m_name & "." & table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As CMySqlConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub Public Overrides Function supportsSelectOffsets() As Boolean Return True End Function End Class --- NEW FILE: CMySQLConnection.vb --- Imports ByteFX.Data.MySqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMySqlConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for MySQL data sources (MySQL 4.0 or higher) ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to MySQL datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMySqlConnection Implements _CConnection Implements IDisposable '************************************************** 'Class: CMySqlConnection 'Author: Richard Banks '************************************************** Private m_connection As MySqlConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As MySqlTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual MySQL connection for the object. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As MySqlConnection Get Connection = m_connection End Get Set(ByVal Value As MySqlConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction on the MySQL connection. ''' </summary> ''' <value></value> ''' <remarks>The MySQL database must support transactions is this is to be non-null.</remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As MySqlTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <remarks>The mySQL database must support transactions for this to function properly. ''' If the database does not support transactions results may be unpredictable.</remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <remarks>The mySQL database must support transactions for this to function properly. ''' If the database does not support transactions results may be unpredictable.</remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction(ByVal isolationLevel As IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' [rbanks] 23/01/2004 Changed to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New MySqlCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As MySqlParameter Try ' Me.startTransaction() Debug.WriteLine(statement.SqlString) m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters If Not cp.Ignore Then param = New MySqlParameter param.ParameterName = cp.Name param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected") End If Catch err As MySqlException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(CMySqlConnection) Dim x As RetrieveException Dim rs As New CResultset Dim m_command As New MySqlCommand Dim cp As CSQLParameter Dim param As MySqlParameter If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters If Not cp.Ignore Then param = New MySqlParameter param.ParameterName = cp.Name param.MySqlDbType = CType(cp.Column.ProviderType, MySqlDbType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New MySqlDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As MySqlException x = New RetrieveException("MySQL Error: " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. ''' </summary> ''' <param name="tName"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As MySqlCommand Dim dr As MySqlDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New MySqlCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Dispose() m_connection = Nothing End If m_db = Nothing m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class --- NEW FILE: AF_MySQL.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{0421A413-1FDE-452E-AB47-82E2CD959461}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_MySQL" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_MySQL" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "ByteFX.MySqlClient" AssemblyName = "ByteFX.MySqlClient" HintPath = "..\..\ByteFX.MySqlClient.dll" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMySQLConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMySqlDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> |
From: Richard B. <rb...@us...> - 2005-02-07 07:38:05
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_OLEDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_OLEDB Added Files: AF_OLEDB.vbproj AssemblyInfo.vb COleDBConnection.vb COleDbDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: COleDbDatabase.vb --- Option Strict Off Option Explicit On Imports System.Data.OleDb Imports System.Collections.Specialized Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMsAccessDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for Microsoft Access and other OLEDB sources ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with Microsoft Access databases and other OLEDB compliant ''' data sources.</remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class COleDbDatabase Inherits CRelationalDatabase '************************************************** 'Class: CMsAccessDatabase 'Author: Juan Carlos Alvarez '************************************************** Private m_name As String Private m_user As String Private m_password As String Private Const DEBUG_MODE As Boolean = True '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied. ''' <list type="bullet"> ''' <item><description>Name: The location of the database (ie the .mdb file)</description></item> ''' <item><description>User: The user name for secured databases. Use AnyUser for unsecured databases.</description></item> ''' <item><description>Password: The password for secured databases. Use AnyPassword for unsecured databases.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As HybridDictionary) m_name = properties.Item("name") m_user = properties.Item("user") m_password = properties.Item("password") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in double quotes. If the string is already enclosed in double quotes then ''' nothing is changed. Also, double quotes within the string are converted to a pair of double quotes.</para> ''' <para>Dates are converted to MM/dd/yy HH:mm:ss format and enclosed in hashes (#).</para> ''' <para>Booleans are converted to TRUE or FALSE</para> ''' <para>Numbers are converted to strings directly. Note that floating point numbers from locales that use ''' a comma for the decimal marker are converted to use the period as the decimal marker.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then tempRetorno = "NULL" Else Select Case VarType(tempValue) Case VariantType.String ' Chr(34) = " ' tempRetorno = Chr(34) & Replace(tempValue, Chr(34), "'") & Chr(34) If Left(tempValue, 1) = Chr(34) And Right(tempValue, 1) = Chr(34) And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quotes with doubles, and enclose entire string in quotes tempRetorno = Chr(34) & Replace(tempValue, Chr(34), """") & Chr(34) End If Case VariantType.Date ' Chr(35) = # TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else tempRetorno = Chr(35) & dd.ToString("MM/dd/yy HH:mm:ss") & Chr(35) End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "TRUE", "FALSE") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = Replace(tempValue, ",", ".") Case Else If tempValue Is Nothing Then tempRetorno = "NULL" Else tempRetorno = tempValue End If End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A COleDBConnection containing the newly established connection.</returns> ''' <remarks>The COleDBConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New COleDBConnection Try conn.Connection = New OleDbConnection If m_user Is Nothing OrElse m_user.Length = 0 Then m_user = "" m_password = "" Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) End If If m_user Is Nothing OrElse m_user.Length = 0 Then conn.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_name + ";" Else conn.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_name + ";Jet OLEDB:Database Password=" + m_password + ";" End If conn.Connection.Open() Catch err As Exception Throw New DatabaseConnectionException(err.Message, err) End Try getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New OleDbDataAdapter Dim aValue As Integer Dim row As System.Data.DataRow Dim p As OleDbParameter Dim x As OIDException Dim initvals() As Object = {1} Dim conn As COleDBConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine("Get OID A Value") End If da.SelectCommand = New OleDbCommand("select * from " & Me.OIDTable, conn.Connection, conn.Transaction) da.UpdateCommand = New OleDbCommand("UPDATE " & Me.OIDTable & " SET oidAValue = @oidAValue ", conn.Connection, conn.Transaction) p = da.UpdateCommand.Parameters.Add("@oidAValue", OleDbType.Integer) p.SourceColumn = "oidAValue" da.InsertCommand = New OleDbCommand("INSERT INTO " & Me.OIDTable & " VALUES(@oidAValue) ", conn.Connection, conn.Transaction) p = da.InsertCommand.Parameters.Add("@oidAValue", OleDbType.Integer) p.SourceColumn = "oidAValue" da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying the @@IDENTITY value.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New OleDbDataAdapter Dim cb As OleDbCommandBuilder Dim aValue As Integer Dim connection As COleDBConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New OleDbCommand("select @@IDENTITY", connection.Connection, connection.Transaction) cb = New OleDbCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value. No value was returned.") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As OleDbException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> ''' <remarks>Since the parameter is for an OLEDB connection only a single ''' question mark (?) is returned.</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String Return "?" End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CRelationalDatabase.getClauseStringTableAlias">_CRelationalDatabase</see>. ''' </summary> ''' <param name="table"></param> ''' <param name="pAlias"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 12/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As COleDBConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub Public Overrides Function limitClauseAtStart() As Boolean Return True End Function Public Overrides Function getClauseStringLimit() As String Return "TOP" End Function End Class --- NEW FILE: COleDBConnection.vb --- Imports System.Data.OleDb Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : COleDBConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for OLEDB data sources (specifically Microsoft Access) ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to OLEDB datasources (specifically Microsoft Access).</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class COleDBConnection Implements _CConnection Implements IDisposable '************************************************** 'Class: CConnection 'Author: Juan Carlos Alvarez '************************************************** Private m_connection As OleDbConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As OleDbTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual OLEDB Connection for the object. ''' </summary> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As OleDbConnection Get Connection = m_connection End Get Set(ByVal Value As OleDbConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction operating on the database connection ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As OleDbTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - Not called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' [rbanks] 23/01/2004 Changed to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New OleDbCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As OleDbParameter Try 'Me.startTransaction() - transaction is started further up Debug.WriteLine(statement.SqlString) m_command.Connection = m_connection m_command.CommandText = statement.SqlString 'new bit for parameters For Each cp In statement.Parameters If Not cp.Ignore Then param = New OleDbParameter param.ParameterName = cp.Name param.OleDbType = CType(cp.Column.ProviderType, System.Data.OleDb.OleDbType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected") End If Catch err As OleDbException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(COleDBConnection) Dim x As RetrieveException Dim rs As New CResultset Dim param As OleDbParameter Dim dd As Date Dim m_command As New OleDbCommand If DEBUG_MODE Then Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters If Not cp.Ignore Then param = New OleDbParameter param.ParameterName = cp.Name param.OleDbType = CType(cp.Column.ProviderType, OleDbType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New OleDbDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction rs.ResultSet.Tables.Add("ole") m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As OleDbException x = New RetrieveException("SQL Error " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - Not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() 'By default we manage tranactions 'For DB's that do not manage transactions we should 'set this attribute to false m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTablesSchema">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New OleDbCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - Not called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Try If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Dispose() m_connection = Nothing End If m_db = Nothing Catch ex As Exception Debug.WriteLine(ex.Message) End Try m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class --- NEW FILE: AF_OLEDB.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{1E2BB267-A506-4F32-B2E0-6672184EC6BF}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_OLEDB" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_OLEDB" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "COleDBConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "COleDbDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("38550C02-EF94-410F-9DB5-DCF4046889C6")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> |
From: Richard B. <rb...@us...> - 2005-02-07 07:38:05
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_ODBC In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_ODBC Added Files: AF_ODBC.vbproj AssemblyInfo.vb CODBCConnection.vb CODBCDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("B02291D0-DF67-455A-8EDC-AEC19EA5A400")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: CODBCDatabase.vb --- Option Strict Off Option Explicit On Imports System.Data.Odbc Imports System.Collections.Specialized Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMsAccessDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for ODBC sources ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with ODBC compliant ''' data sources.</remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CODBCDatabase Inherits CRelationalDatabase '************************************************** 'Class: CODBCDatabase 'Author: Richard Banks '************************************************** Private m_connectionString As String Private Const DEBUG_MODE As Boolean = True '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied. ''' <list type="bullet"> ''' <item><description>Name: The location of the database (ie the .mdb file)</description></item> ''' <item><description>User: The user name for secured databases. Use AnyUser for unsecured databases.</description></item> ''' <item><description>Password: The password for secured databases. Use AnyPassword for unsecured databases.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As HybridDictionary) m_connectionString = properties.Item("name") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in double quotes. If the string is already enclosed in double quotes then ''' nothing is changed. Also, double quotes within the string are converted to a pair of double quotes.</para> ''' <para>Dates are converted to MM/dd/yy HH:mm:ss format and enclosed in hashes (#).</para> ''' <para>Booleans are converted to TRUE or FALSE</para> ''' <para>Numbers are converted to strings directly. Note that floating point numbers from locales that use ''' a comma for the decimal marker are converted to use the period as the decimal marker.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then tempRetorno = "NULL" Else Select Case VarType(tempValue) Case VariantType.String If Left(tempValue, 1) = "'" And Right(tempValue, 1) = "'" And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quote with double quote, and enclose entire string in quotes tempRetorno = "'" & Replace(tempValue, "'", "''") & "'" End If Case VariantType.Date TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "TRUE", "FALSE") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = Replace(tempValue, ",", ".") Case Else If tempValue Is Nothing Then tempRetorno = "NULL" Else tempRetorno = tempValue End If End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A CODBCConnection containing the newly established connection.</returns> ''' <remarks>The CODBCConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New CODBCConnection Try conn.Connection = New OdbcConnection conn.Connection.ConnectionString = m_connectionString conn.Connection.Open() Catch err As Exception Throw New DatabaseConnectionException(err.Message, err) End Try getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New OdbcDataAdapter Dim aValue As Integer Dim row As System.Data.DataRow Dim p As OdbcParameter Dim x As OIDException Dim initvals() As Object = {1} Dim conn As CODBCConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine("Get OID A Value") End If da.SelectCommand = New OdbcCommand("select * from " & Me.OIDTable, conn.Connection, conn.Transaction) da.UpdateCommand = New OdbcCommand("UPDATE " & Me.OIDTable & " SET oidAValue = @oidAValue ", conn.Connection, conn.Transaction) p = da.UpdateCommand.Parameters.Add("@oidAValue", OdbcType.Int) p.SourceColumn = "oidAValue" da.InsertCommand = New OdbcCommand("INSERT INTO " & Me.OIDTable & " VALUES(@oidAValue) ", conn.Connection, conn.Transaction) p = da.InsertCommand.Parameters.Add("@oidAValue", OdbcType.Int) p.SourceColumn = "oidAValue" da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying the @@IDENTITY value.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New OdbcDataAdapter Dim cb As OdbcCommandBuilder Dim aValue As Integer Dim connection As CODBCConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New OdbcCommand("select @@IDENTITY", connection.Connection, connection.Transaction) cb = New OdbcCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value. No value was returned.") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As OdbcException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> ''' <remarks>Since the parameter is for an ODBC connection only a single ''' question mark (?) is returned.</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String Return "?" End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CRelationalDatabase.getClauseStringTableAlias">_CRelationalDatabase</see>. ''' </summary> ''' <param name="table"></param> ''' <param name="pAlias"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 12/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As CODBCConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub End Class '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMaxDBDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for MaxDB Servers. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with MaxDB databases. The only .NET provider is an ODBC connection ''' at this stage, so we just inherit from the existing ODBC database class for now. ''' </remarks> ''' <history> ''' [rbanks] 02/09/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMaxDBDatabase Inherits CODBCDatabase Public Overrides Function useBracketsForJoins() As Boolean Return False End Function End Class --- NEW FILE: CODBCConnection.vb --- Imports AToMSFramework Imports System.Data.Odbc '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CODBCConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for ODBC data sources ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to ODBC datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CODBCConnection Implements _CConnection Implements IDisposable '************************************************** 'Class: CConnection 'Author: Juan Carlos Alvarez '************************************************** Private m_connection As OdbcConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As OdbcTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual ODBC Connection for the object. ''' </summary> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As OdbcConnection Get Connection = m_connection End Get Set(ByVal Value As OdbcConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 28/11/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction operating on the database connection ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As OdbcTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - Not called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' [rbanks] 23/01/2004 Changed to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New OdbcCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As OdbcParameter Try 'Me.startTransaction() - transaction is started further up Debug.WriteLine(statement.SqlString) m_command.Connection = m_connection m_command.CommandText = statement.SqlString 'new bit for parameters For Each cp In statement.Parameters If Not cp.Ignore Then param = New OdbcParameter param.ParameterName = cp.Name param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected") End If Catch err As OdbcException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(CODBCConnection) Dim x As RetrieveException Dim rs As New CResultset Dim m_command As New OdbcCommand Dim param As OdbcParameter If DEBUG_MODE Then Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters If Not cp.Ignore Then param = New OdbcParameter param.ParameterName = cp.Name param.OdbcType = CType(cp.Column.ProviderType, System.Data.odbc.OdbcType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New OdbcDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As OdbcException x = New RetrieveException("SQL Error " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - Not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() 'By default we manage tranactions 'For DB's that do not manage transactions we should 'set this attribute to false m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTablesSchema">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As OdbcCommand Dim dr As OdbcDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New OdbcCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - Not called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Dispose() m_connection = Nothing End If m_db = Nothing m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class --- NEW FILE: AF_ODBC.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_ODBC" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_ODBC" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CODBCConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CODBCDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> |
From: Richard B. <rb...@us...> - 2005-02-07 07:37:53
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MaxDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_MaxDB Added Files: AF_MaxDB.vbproj AssemblyInfo.vb CMaxDBDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AF_MaxDB.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{7389B1D2-9133-463F-B1ED-B9C0AFE6E2B5}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_MaxDB" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_MaxDB" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "AF_ODBC" Project = "{DD36FC68-80E0-47F6-9C1D-00D1F8D59EBC}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMaxDBDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: CMaxDBDatabase.vb --- Option Strict Off Option Explicit On Imports AF_ODBC '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMaxDBDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for MaxDB Servers. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with MaxDB databases. The only .NET provider is an ODBC connection ''' at this stage, so we just inherit from the existing ODBC database class for now. ''' </remarks> ''' <history> ''' [rbanks] 02/09/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMaxDBDatabase Inherits CODBCDatabase Public Overrides Function useBracketsForJoins() As Boolean Return False End Function End Class --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("6BBD01DC-8C01-414B-8DF7-B070E4BFA4D7")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> |
From: Richard B. <rb...@us...> - 2005-02-07 07:37:53
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MSSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_MSSQL Added Files: AF_MSSQL.vbproj AssemblyInfo.vb CMsSqlConnection.vb CMsSqlDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("88EEC41E-58C3-409C-B89B-DD282479D729")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: AF_MSSQL.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{11985DFB-9B77-434C-98F2-89C219C5B506}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_MSSQL" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_MSSQL" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMsSqlConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMsSqlDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: CMsSqlDatabase.vb --- Option Strict Off Option Explicit On Imports System.Data.SqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMsSqlDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for Microsoft SQL Server. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with Microsoft SQL databases.</remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMsSqlDatabase Inherits CRelationalDatabase Private m_name As String Private m_user As String Private m_password As String Private m_serverName As String '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A CMSSqlConnection containing the newly established connection.</returns> ''' <remarks>The CMSSqlConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para> ''' <para>The connection is established using normal SQL server authentication (ie ''' Integrated security is false, and persiste security info is false.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New CMSSqlConnection conn.Connection = New SqlConnection conn.ManageTransactions = True Try If m_user Is Nothing OrElse m_user.Length = 0 Then m_user = "" m_password = "" Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) End If If m_user = "SSPI" Then conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Initial Catalog=" & m_name & ";" & _ "Integrated Security=SSPI;" & _ "Persist Security Info=False;" Else conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Initial Catalog=" & m_name & ";" & _ "Integrated Security=false;" & _ "Persist Security Info=False;" & _ "User Id=" & m_user & ";" & _ "Password=" & m_password End If conn.Connection.Open() Catch ex As SqlClient.SqlException Throw New DatabaseConnectionException(ex.Message, ex) Catch ex As Exception Throw New DatabaseConnectionException(ex.Message, ex) End Try getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied ''' <list type="bullet"> ''' <item><description>Name: The name of the database on the server (ie the catalog name)</description></item> ''' <item><description>ServerName: The name of the database server</description></item> ''' <item><description>User: The user name for secured databases.</description></item> ''' <item><description>Password: The password for secured databases.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As System.Collections.Specialized.HybridDictionary) m_name = properties.Item("name") m_serverName = properties.Item("serverName") m_user = properties.Item("user") m_password = properties.Item("password") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in single quotes. If the string is already enclosed in single quotes then ''' nothing is changed. Also, any single quotes within the string are converted to a pair of single quotes.</para> ''' <para>Dates are converted to yyyy-MM-dd HH:mm:ss format and enclosed in single quotes. If a datetime field ''' only has a time value, then a time-only string is returned instead.</para> ''' <para>Booleans are converted to 1 or 0</para> ''' <para>Numbers are converted to strings directly.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then Return "NULL" Else Select Case VarType(tempValue) Case VariantType.String If Left(tempValue, 1) = "'" And Right(tempValue, 1) = "'" And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quote with double quote, and enclose entire string in quotes tempRetorno = "'" & Replace(tempValue, "'", "''") & "'" End If Case VariantType.Date TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else If dd.Date.Ticks = 0 Then 'MSSQL doesn't support dates with years less than 1753, so time only 'values that format to "0001-01-01 11:23:00" for example produce errors. 'If it's just a time we will only return time portion. tempRetorno = "'" & dd.ToString("HH:mm:ss") & "'" Else tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" End If End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "1", "0") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = tempValue.ToString Case Else tempRetorno = tempValue End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New SqlDataAdapter Dim cb As SqlCommandBuilder Dim aValue As Integer Dim row As System.Data.DataRow Dim p As SqlParameter Dim initvals() As Object = {1} Dim x As OIDException Dim conn As CMSSqlConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try da.SelectCommand = New SqlCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) cb = New SqlCommandBuilder(da) da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As SqlException conn.rollback() x = New OIDException(err.Message, err) Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying the @@IDENTITY value.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New SqlDataAdapter Dim cb As SqlCommandBuilder Dim aValue As Integer Dim connection As CMSSqlConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New SqlCommand("select @@IDENTITY", connection.Connection, connection.Transaction) cb = New SqlCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As SqlException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> ''' <remarks>Since the parameter is for an MSSQL connection only a the returned ''' string is in the format of @pxxx where xxx is the value of the input integer (i).</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String Return "@p" & CStr(i) End Function Public Overrides Function limitClauseAtStart() As Boolean Return True End Function Public Overrides Function getClauseStringLimit() As String Return "TOP" End Function Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return Me.m_name & "." & owner & "." & table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As CMSSqlConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub End Class --- NEW FILE: CMsSqlConnection.vb --- Imports System.Data.SqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMSSqlConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for MSSql data sources ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to MSSQL datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CMSSqlConnection Implements _CConnection Implements IDisposable '************************************************** 'Class: CMSSqlConnection 'Author: Richard Banks '************************************************** Private m_connection As SqlConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As SqlTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual SQL Server connection for the object. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As SqlConnection Get Connection = m_connection End Get Set(ByVal Value As SqlConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction for the connection. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As SqlTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' [rbanks] 23/01/2004 Changed to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New SqlCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As SqlParameter Dim dd As Date Try m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters If Not cp.Ignore Then param = New SqlParameter param.ParameterName = cp.Name param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) If TypeOf (cp.Value) Is DateTime Then dd = cp.Value If dd.Ticks = 0 Then dd = DateAdd(DateInterval.Year, 1899, dd) Else dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) End If cp.Value = dd End If param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction Debug.WriteLine(m_command.CommandText) m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected by the update") End If Catch err As SqlException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(CMsSqlConnection) Dim x As RetrieveException Dim rs As New CResultset Dim param As SqlParameter Dim dd As Date Dim m_command As New SqlCommand If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters If Not cp.Ignore Then param = New SqlParameter param.ParameterName = cp.Name param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) If TypeOf (cp.Value) Is DateTime Then dd = cp.Value If dd.Ticks = 0 Then dd = DateAdd(DateInterval.Year, 1899, dd) Else dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) End If cp.Value = dd End If param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New SqlDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As SqlException x = New RetrieveException("SQL Error: " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback Dim pb As CPersistenceBroker If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() 'By default we manage tranactions 'For DB's that do not manage transactions we should 'set this attribute to false m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. ''' </summary> ''' <param name="tName"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As SqlCommand Dim dr As SqlDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New SqlCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Close() m_connection.Dispose() m_connection = Nothing End If m_db = Nothing m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class |
From: Richard B. <rb...@us...> - 2005-02-07 07:37:53
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MSOracle In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_MSOracle Added Files: AF_MSOracle.vbproj AssemblyInfo.vb COracleConnection.vb COracleDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("A680CAA6-4CA2-4F84-A76A-64FF06C06355")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: COracleDatabase.vb --- Option Strict Off Option Explicit On Imports System.Data.OracleClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : COracleDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for Oracle Database Servers. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with oracle databases.</remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class COracleDatabase Inherits CRelationalDatabase Private m_user As String Private m_password As String Private m_serverName As String '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A COracleConnection containing the newly established connection.</returns> ''' <remarks>The COracleConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New COracleConnection conn.Connection = New OracleConnection conn.ManageTransactions = True Try If m_user Is Nothing OrElse m_user.Length = 0 Then m_user = "" m_password = "" Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) End If If m_user = "SSPI" Then conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Integrated Security=true;" & _ "Persist Security Info=False;" Else conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Integrated Security=false;" & _ "Persist Security Info=False;" & _ "User Id=" & m_user & ";" & _ "Password=" & m_password End If conn.Connection.Open() Catch ex As OracleClient.OracleException Throw New DatabaseConnectionException(ex.Message, ex) Catch ex As Exception Throw New DatabaseConnectionException(ex.Message, ex) End Try getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied ''' <list type="bullet"> ''' <item><description>ServerName: The name of the database server</description></item> ''' <item><description>User: The user name for secured databases. Use SSPI to suppply a user at runtime</description></item> ''' <item><description>Password: The password for secured databases.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As System.Collections.Specialized.HybridDictionary) m_serverName = properties.Item("serverName") m_user = properties.Item("user") m_password = properties.Item("password") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in single quotes. If the string is already enclosed in single quotes then ''' nothing is changed. Also, any single quotes within the string are converted to a pair of single quotes.</para> ''' <para>Dates are converted to yyyy-MM-dd HH:mm:ss format and enclosed in single quotes. If a datetime field ''' only has a time value, then a time-only string is returned instead.</para> ''' <para>Booleans are converted to 1 or 0</para> ''' <para>Numbers are converted to strings directly.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then Return "NULL" Else Select Case VarType(tempValue) Case VariantType.String If Left(tempValue, 1) = "'" And Right(tempValue, 1) = "'" And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quote with double quote, and enclose entire string in quotes tempRetorno = "'" & Replace(tempValue, "'", "''") & "'" End If Case VariantType.Date TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else If dd.Date.Ticks = 0 Then 'MSSQL doesn't support dates with years less than 1753, so time only 'values that format to "0001-01-01 11:23:00" for example produce errors. 'If it's just a time we will only return time portion. tempRetorno = "'" & dd.ToString("HH:mm:ss") & "'" Else tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" End If End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "1", "0") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = tempValue.ToString Case Else tempRetorno = tempValue End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New OracleDataAdapter Dim cb As OracleCommandBuilder Dim aValue As Integer Dim row As System.Data.DataRow Dim p As OracleParameter Dim initvals() As Object = {1} Dim x As OIDException Dim conn As COracleConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try da.SelectCommand = New OracleCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) cb = New OracleCommandBuilder(da) da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As OracleException conn.rollback() x = New OIDException(err.Message, err) Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying the @@IDENTITY value.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New OracleDataAdapter Dim cb As OracleCommandBuilder Dim aValue As Integer Dim connection As COracleConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New OracleCommand("select @@IDENTITY", connection.Connection, connection.Transaction) cb = New OracleCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As OracleException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the oracle parameter placeholder</returns> ''' <remarks>Since the parameter is for an Oracle connection only a the returned ''' string is in the format of :pxxx where xxx is the value of the input integer (i).</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String Return ":p" & CStr(i) End Function Public Overrides Function limitClauseAtStart() As Boolean Return True End Function Public Overrides Function getClauseStringLimit() As String Return "TOP" End Function Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return owner & "." & table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As COracleConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub End Class --- NEW FILE: AF_MSOracle.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{D50BB1EF-4B22-4D0F-88AC-0344F5AF3118}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_MSOracle" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_MSOracle" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "System.Data.OracleClient" AssemblyName = "System.Data.OracleClient" HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.OracleClient.dll" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "COracleConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "COracleDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: COracleConnection.vb --- Imports System.Data.OracleClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : COracleConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for Oracle data sources ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to Oracle datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Class COracleConnection Implements _CConnection Implements IDisposable Private m_connection As OracleConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As OracleTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual Oracle connection for the object. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As OracleConnection Get Connection = m_connection End Get Set(ByVal Value As OracleConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction for the connection. ''' </summary> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As OracleTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New OracleCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As OracleParameter Dim dd As Date Try m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters If Not cp.Ignore Then param = New OracleParameter param.ParameterName = cp.Name param.OracleType = CType(cp.Column.ProviderType, OracleType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction Debug.WriteLine(m_command.CommandText) m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected by the update") End If Catch err As OracleException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(COracleConnection) Dim x As RetrieveException Dim rs As New CResultset Dim param As OracleParameter Dim dd As Date Dim m_command As New OracleCommand If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters If Not cp.Ignore Then param = New OracleParameter param.ParameterName = cp.Name param.OracleType = CType(cp.Column.ProviderType, OracleType) param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New OracleDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As OracleException x = New RetrieveException("Oracle Error: " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback Dim pb As CPersistenceBroker If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() 'By default we manage tranactions 'For DB's that do not manage transactions we should 'set this attribute to false m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. ''' </summary> ''' <param name="tName"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 23/12/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As OracleCommand Dim dr As OracleDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New OracleCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Close() m_connection.Dispose() m_connection = Nothing End If m_db = Nothing m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class |
From: Richard B. <rb...@us...> - 2005-02-07 07:37:53
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_Informix In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10604/Providers/AF_Informix Added Files: AF_Informix.vbproj AssemblyInfo.vb CInformixConnection.vb CInformixDatabase.vb Log Message: Break out providers to separate .DLL files. Change <database /> mapping to use proider="xx" instead of class="xx" Start prep work for Informix provider --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("9C60B971-79A3-4B77-AE05-1C3C33B3F6BE")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: CInformixDatabase.vb --- Option Strict Off Option Explicit On Imports System.Data.SqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMsSqlDatabase ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Implementation of CRelationalDatabase for Microsoft SQL Server. ''' </summary> ''' <remarks>This class contains the specific functionality required for the ''' framework to interact with Microsoft SQL databases.</remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CInformixDatabase Inherits CRelationalDatabase Private m_name As String Private m_user As String Private m_password As String Private m_serverName As String '''----------------------------------------------------------------------------- ''' <summary> ''' Establishes a new database connection. ''' </summary> ''' <returns>A CMSSqlConnection containing the newly established connection.</returns> ''' <remarks>The CMSSqlConnection class implements the _CConnection interface which ''' is required by this method. ''' <para>If the connection cannot be established an exception will be thrown.</para> ''' <para>The connection is established using normal SQL server authentication (ie ''' Integrated security is false, and persiste security info is false.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNewConnection() As _CConnection Dim conn As New CInformixConnection conn.Connection = New SqlConnection conn.ManageTransactions = True Try If m_user Is Nothing OrElse m_user.Length = 0 Then m_user = "" m_password = "" Dim pbroker As CPersistenceBroker pbroker = getPersistenceBrokerInstance() pbroker.GetLoginDetails(Me, m_user, m_password) End If If m_user = "SSPI" Then conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Initial Catalog=" & m_name & ";" & _ "Integrated Security=SSPI;" & _ "Persist Security Info=False;" Else conn.Connection.ConnectionString = _ "Data Source=" & m_serverName & ";" & _ "Initial Catalog=" & m_name & ";" & _ "Integrated Security=false;" & _ "Persist Security Info=False;" & _ "User Id=" & m_user & ";" & _ "Password=" & m_password End If conn.Connection.Open() Catch ex As SqlClient.SqlException Throw New DatabaseConnectionException(ex.Message, ex) Catch ex As Exception Throw New DatabaseConnectionException(ex.Message, ex) End Try getNewConnection = conn End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Sets the initial properties of the database. ''' </summary> ''' <param name="properties">The property information supplied in the XML mapping file.</param> ''' <remarks>In order to initialise the database object properly the following must be supplied ''' <list type="bullet"> ''' <item><description>Name: The name of the database on the server (ie the catalog name)</description></item> ''' <item><description>ServerName: The name of the database server</description></item> ''' <item><description>User: The user name for secured databases.</description></item> ''' <item><description>Password: The password for secured databases.</description></item> ''' <item><description>OIDTable: The table name containing the OID A-value. Can be ignored if OIDs are not used.</description></item> ''' </list> ''' <para>If the database is used without having been properly initialised you are likely ''' to get exceptions thrown in your application.</para> ''' </remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Sub init(ByVal properties As System.Collections.Specialized.HybridDictionary) m_name = properties.Item("name") m_serverName = properties.Item("serverName") m_user = properties.Item("user") m_password = properties.Item("password") If properties.Item("ansinulls") Is Nothing Then UseANSINulls = False Else UseANSINulls = properties.Item("ansinulls") End If MyBase.OIDTable = properties.Item("OIDTable") End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the value of an object in a format the database can understand. ''' </summary> ''' <param name="tempValue">The object being evaluated.</param> ''' <returns>A string containing the SQL compatible value for the object</returns> ''' <remarks>The following rules are applied when converting object values into ''' database compatible strings ''' <para>Any value that is a Null Alias <see cref="M:AToMSFramework.ModAliasNull.IsNullAlias"/> ''' will be returned as NULL.</para> ''' <para>Strings are enclosed in single quotes. If the string is already enclosed in single quotes then ''' nothing is changed. Also, any single quotes within the string are converted to a pair of single quotes.</para> ''' <para>Dates are converted to yyyy-MM-dd HH:mm:ss format and enclosed in single quotes. If a datetime field ''' only has a time value, then a time-only string is returned instead.</para> ''' <para>Booleans are converted to 1 or 0</para> ''' <para>Numbers are converted to strings directly.</para> ''' <para>Objects that are nothing return a NULL and all other objects are directly converted to strings using their ''' inbuilt ToString methods.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getValueFor(ByVal tempValue As Object) As String Dim tempRetorno As String Dim dd As DateTime Dim OriginalCulture As System.Globalization.CultureInfo Dim TempCulture As System.Globalization.CultureInfo If IsNullAlias(tempValue) Then Return "NULL" Else Select Case VarType(tempValue) Case VariantType.String If Left(tempValue, 1) = "'" And Right(tempValue, 1) = "'" And CStr(tempValue).Length > 2 Then 'string already enclosed in quotes so ignore tempRetorno = tempValue Else 'replace single quote with double quote, and enclose entire string in quotes tempRetorno = "'" & Replace(tempValue, "'", "''") & "'" End If Case VariantType.Date TempCulture = New System.Globalization.CultureInfo("en-US") OriginalCulture = System.Threading.Thread.CurrentThread.CurrentCulture System.Threading.Thread.CurrentThread.CurrentCulture = TempCulture System.Threading.Thread.CurrentThread.CurrentUICulture = TempCulture dd = CType(tempValue, DateTime) If dd = Date.MinValue Then tempRetorno = "NULL" Else If dd.Date.Ticks = 0 Then 'MSSQL doesn't support dates with years less than 1753, so time only 'values that format to "0001-01-01 11:23:00" for example produce errors. 'If it's just a time we will only return time portion. tempRetorno = "'" & dd.ToString("HH:mm:ss") & "'" Else tempRetorno = "'" & dd.ToString("yyyy-MM-dd HH:mm:ss") & "'" End If End If System.Threading.Thread.CurrentThread.CurrentCulture = OriginalCulture System.Threading.Thread.CurrentThread.CurrentUICulture = OriginalCulture Case VariantType.Boolean tempRetorno = IIf(tempValue, "1", "0") Case VariantType.Single, VariantType.Double, VariantType.Decimal, VariantType.Decimal tempRetorno = tempValue.ToString Case Else tempRetorno = tempValue End Select End If getValueFor = tempRetorno End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Gets the next OID A-Value from the database. ''' </summary> ''' <returns>A integer containing the A-Value.</returns> ''' <remarks>A connection is established to the database and the OIDTable (specified in ''' the XML mapping) is queried and updated. The obtained A-Value is returned. ''' <para>Should an error occur a value of 0 will be returned.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getNextOIDAvalue() As Integer Dim rs As New DataSet Dim da As New SqlDataAdapter Dim cb As SqlCommandBuilder Dim aValue As Integer Dim row As System.Data.DataRow Dim p As SqlParameter Dim initvals() As Object = {1} Dim x As OIDException Dim conn As CInformixConnection conn = Me.getConnection(Nothing) conn.AutoCommit = False conn.startTransaction() Try da.SelectCommand = New SqlCommand("select oidAValue from " & Me.OIDTable, conn.Connection, conn.Transaction) cb = New SqlCommandBuilder(da) da.Fill(rs, "oid") If rs.Tables(0).Rows.Count = 0 Then 'Seed with value = 1 row = rs.Tables(0).Rows.Add(initvals) aValue = 1 Else rs.Tables(0).Rows(0).Item(0) += 1 aValue = rs.Tables(0).Rows(0).Item(0) End If da.Update(rs, "oid") da.Dispose() conn.commit() Catch err As SqlException conn.rollback() x = New OIDException(err.Message, err) Catch err As Exception conn.rollback() x = New OIDException(err.Message, err) Finally Me.freeConnection(conn) If Not x Is Nothing Then Throw x End If End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Method to get the last Identity value for the connection. ''' </summary> ''' <param name="conn">The connection to use.</param> ''' <returns>An integer containing the value of the last updated identity column</returns> ''' <remarks>If multiple identity columns were updated the return value will only contain ''' the value of the last identity column updated. ''' <para>Identity values are retrieved by querying the @@IDENTITY value.</para> ''' <para>Should an error occur an exception will be thrown.</para></remarks> ''' <history> ''' [rbanks] 11/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getIdentityValue(ByVal conn As _CConnection) As Integer Dim rs As New DataSet Dim da As New SqlDataAdapter Dim cb As SqlCommandBuilder Dim aValue As Integer Dim connection As CInformixConnection connection = conn connection.AutoCommit = False Try da.SelectCommand = New SqlCommand("select @@IDENTITY", connection.Connection, connection.Transaction) cb = New SqlCommandBuilder(da) da.Fill(rs, "identity") If rs.Tables(0).Rows.Count = 0 Then Throw New IdentityValueException("Could not retrieve identity value") Else If IsDBNull(rs.Tables(0).Rows(0).Item(0)) Then aValue = 0 Else aValue = rs.Tables(0).Rows(0).Item(0) End If Debug.WriteLine("Returned Identity value: " & aValue.ToString) End If da.Dispose() Catch err As SqlException Throw New IdentityValueException(err.Message, err) End Try Return aValue End Function '''----------------------------------------------------------------------------- ''' <summary> ''' Returns the SQL syntax placeholder for a parameter ''' </summary> ''' <param name="i">The number of the parameter being added</param> ''' <returns>A string containing the SQL parameter placeholder</returns> ''' <remarks>Since the parameter is for an MSSQL connection only a the returned ''' string is in the format of @pxxx where xxx is the value of the input integer (i).</remarks> ''' <history> ''' [rbanks] 23/01/2004 Created ''' </history> '''----------------------------------------------------------------------------- Public Overrides Function getParamHolder(ByVal i As Integer) As String Return "@p" & CStr(i) End Function Public Overrides Function limitClauseAtStart() As Boolean Return True End Function Public Overrides Function getClauseStringLimit() As String Return "TOP" End Function Public Overrides Function getClauseStringTableAlias(ByVal table As String, ByVal owner As String, ByVal pAlias As String) As String Return Me.m_name & "." & owner & "." & table & " as " & pAlias End Function Public Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then Dim conn As CInformixConnection While ConnectionPool.Count > 0 conn = ConnectionPool.Pop conn.Dispose() End While m_disposed = True End If End If End Sub End Class --- NEW FILE: CInformixConnection.vb --- Imports System.Data.SqlClient Imports AToMSFramework '''----------------------------------------------------------------------------- ''' Project : AToMSFramework ''' Class : CMSSqlConnection ''' '''----------------------------------------------------------------------------- ''' <summary> ''' Connection class for MSSql data sources ''' </summary> ''' <remarks><para>This class implements the <see cref="T:AToMSFramework._CConnection"/> interface and is used ''' to manage connections to MSSQL datasources.</para> ''' <para>The following should be taken into consideration when using this ''' class:</para> ''' <para>1. Only one physical transaction runs on a database connection at any one time</para> ''' <para>2. Only one physical connection to the database exists. Multiple connection ''' objects will share a connection where possible</para> ''' <para>3. If nested transactions are started, the commit or rollback only occurs on the ''' first transaction created. A rollback on any nested transaction will cause all ''' outside transactions to also roll back.</para> ''' </remarks> ''' <seealso cref="T:AToMSFramework._CConnection"/> ''' <history> ''' [rbanks] 18/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Class CInformixConnection Implements _CConnection Implements IDisposable '************************************************** 'Class: CMSSqlConnection 'Author: Richard Banks '************************************************** Private m_connection As InformixConnection Private m_autoCommit As Boolean Private m_started As Boolean Private m_manageTransactions As Boolean Private m_transaction As sqlTransaction Private m_transactioncalls As Integer Private m_references As Integer Private m_db As _CRelationalDatabase Private Const DEBUG_MODE As Boolean = True Private m_disposed As Boolean '''----------------------------------------------------------------------------- ''' <summary> ''' The actual SQL Server connection for the object. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Connection() As SqlConnection Get Connection = m_connection End Get Set(ByVal Value As SqlConnection) m_connection = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.AutoCommit">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property AutoCommit() As Boolean Implements _CConnection.AutoCommit Get AutoCommit = m_autoCommit End Get Set(ByVal Value As Boolean) m_autoCommit = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.Started">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property Started() As Boolean Implements _CConnection.Started Get Started = m_started End Get Set(ByVal Value As Boolean) m_started = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ManageTransactions">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ManageTransactions() As Boolean Implements _CConnection.ManageTransactions Get ManageTransactions = m_manageTransactions End Get Set(ByVal Value As Boolean) m_manageTransactions = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.commit">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub commit() Implements _CConnection.commit If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("COMMIT TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested COMMIT TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then m_transaction.Commit() getPersistenceBrokerInstance().commitCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' The current transaction for the connection. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property Transaction() As SqlTransaction Get Transaction = m_transaction End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.startTransaction">_CConnection</see>. ''' </summary> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Overloads Sub startTransaction() Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' [rbanks] 23/01/2004 Changed to use SQL parameters ''' </history> '''----------------------------------------------------------------------------- Public Sub processStatement(ByVal statement As CSqlStatement) Implements _CConnection.processStatement Dim m_command As New SqlCommand Dim m_recordcount As Integer Dim cp As CSQLParameter Dim param As SqlParameter Dim dd As Date Try m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp In statement.Parameters If Not cp.Ignore Then param = New SqlParameter param.ParameterName = cp.Name param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) If TypeOf (cp.Value) Is DateTime Then dd = cp.Value If dd.Ticks = 0 Then dd = DateAdd(DateInterval.Year, 1899, dd) Else dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) End If cp.Value = dd End If param.Value = cp.Value m_command.Parameters.Add(param) End If Next m_command.Transaction = m_transaction Debug.WriteLine(m_command.CommandText) m_recordcount = m_command.ExecuteNonQuery() If m_recordcount = 0 Then Throw New NothingUpdatedException("No records were affected by the update") End If Catch err As SqlException Throw err Catch err As Exception Throw err End Try End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.processSelectStatement">_CConnection</see>. ''' </summary> ''' <param name="statement"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function processSelectStatement(ByVal statement As CSqlStatement) As CResultset Implements _CConnection.processSelectStatement SyncLock GetType(CInformixConnection) Dim x As RetrieveException Dim rs As New CResultset Dim param As SqlParameter Dim dd As Date Dim m_command As New SqlCommand If DEBUG_MODE Then System.Diagnostics.Debug.WriteLine(statement.SqlString) End If m_command.Connection = m_connection m_command.CommandText = statement.SqlString For Each cp As CSQLParameter In statement.Parameters If Not cp.Ignore Then param = New SqlParameter param.ParameterName = cp.Name param.SqlDbType = CType(cp.Column.ProviderType, SqlDbType) If TypeOf (cp.Value) Is DateTime Then dd = cp.Value If dd.Ticks = 0 Then dd = DateAdd(DateInterval.Year, 1899, dd) Else dd = New Date(dd.Year, dd.Month, dd.Day, dd.Hour, dd.Minute, dd.Second, 0) End If cp.Value = dd End If param.Value = cp.Value m_command.Parameters.Add(param) End If Next Try Dim m_adapter As New SqlDataAdapter(m_command) If m_transactioncalls > 0 Then m_adapter.SelectCommand.Transaction = m_transaction m_adapter.Fill(rs.ResultSet, "ole") m_adapter.Dispose() Catch err As SqlException x = New RetrieveException("SQL Error: " & err.Message, err) Catch err As Exception x = New RetrieveException(err.Message, err) End Try If Not x Is Nothing Then Throw x End If processSelectStatement = rs End SyncLock End Function '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.rollback">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub rollback() Implements _CConnection.rollback Dim pb As CPersistenceBroker If DEBUG_MODE Then If m_transactioncalls = 1 Then System.Diagnostics.Debug.WriteLine("ROLLBACK TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested ROLLBACK TRANSACTION - not actually performed") End If End If If Me.ManageTransactions Then If m_transactioncalls = 1 Then Try m_transaction.Rollback() Catch ex As Exception End Try getPersistenceBrokerInstance().rollbackCache(Me.Database) Me.Started = False m_transaction = Nothing End If m_transactioncalls -= 1 End If End Sub Public Sub New() MyBase.New() 'By default we manage tranactions 'For DB's that do not manage transactions we should 'set this attribute to false m_manageTransactions = True m_references = 0 End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="M:AToMSFramework._CConnection.CloseConnection">_CConnection</see>. ''' </summary> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Sub CloseConnection() Implements _CConnection.CloseConnection m_references -= 1 If m_references = 0 Then m_connection.Close() End If End Sub '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.IsClosed">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public ReadOnly Property IsClosed() As Boolean Implements _CConnection.IsClosed Get Return m_connection.State = ConnectionState.Closed End Get End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.ReferenceCount">_CConnection</see>. ''' </summary> ''' <value></value> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Property ReferenceCount() As Integer Implements _CConnection.ReferenceCount Get Return m_references End Get Set(ByVal Value As Integer) m_references = Value End Set End Property '''----------------------------------------------------------------------------- ''' <summary> ''' See <see cref="P:AToMSFramework._CConnection.getTableSchema">_CConnection</see>. ''' </summary> ''' <param name="tName"></param> ''' <returns></returns> ''' <remarks></remarks> ''' <history> ''' [rbanks] 1/12/2003 Created ''' </history> '''----------------------------------------------------------------------------- Public Function getTableSchema(ByVal tName As String) As System.Data.DataTable Implements _CConnection.getTableSchema Dim statement As String Dim cmd As SqlCommand Dim dr As SqlDataReader Dim dt As DataTable statement = "select * from " & tName Try cmd = New SqlCommand(statement, Me.Connection) dr = cmd.ExecuteReader(CommandBehavior.SchemaOnly) dt = dr.GetSchemaTable Catch ex As Exception dt = Nothing Throw ex End Try Return dt End Function Public Overloads Sub startTransaction(ByVal isolationLevel As System.Data.IsolationLevel) Implements _CConnection.startTransaction If DEBUG_MODE Then If m_transactioncalls = 0 Then System.Diagnostics.Debug.WriteLine("BEGIN TRANSACTION") Else System.Diagnostics.Debug.WriteLine("Nested BEGIN TRANSACTION - not actually called") End If End If If Me.ManageTransactions Then If Not Me.Started Then m_transaction = m_connection.BeginTransaction(isolationLevel) getPersistenceBrokerInstance().startCacheTransaction(Me.Database) End If m_transactioncalls += 1 Me.Started = True End If End Sub Public Property Database() As _CRelationalDatabase Implements _CConnection.Database Get Return m_db End Get Set(ByVal Value As _CRelationalDatabase) m_db = Value End Set End Property Public Overloads Sub Dispose() Implements System.IDisposable.Dispose Dispose(True) GC.SuppressFinalize(Me) End Sub Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean) If Not m_disposed Then If disposing Then If Me.Started AndAlso Not m_transaction Is Nothing Then m_transaction.Rollback() m_transaction = Nothing End If If Not m_connection Is Nothing Then m_connection.Close() m_connection.Dispose() m_connection = Nothing End If m_db = Nothing m_disposed = True End If End If End Sub Protected Overrides Sub Finalize() ' Simply call Dispose(False). Dispose(False) End Sub End Class --- NEW FILE: AF_Informix.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{09659A30-0220-42BF-9478-267278E89692}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AF_Informix" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AF_Informix" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> <Reference Name = "AToMSFramework" Project = "{8FFD05CF-E733-4D8E-BC0E-D9DD37B87384}" Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CInformixConnection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CInformixDatabase.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:33
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_ODBC In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_ODBC Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_ODBC added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:33
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_OLEDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_OLEDB Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_OLEDB added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:33
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MaxDB In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_MaxDB Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_MaxDB added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:32
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MySQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_MySQL Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_MySQL added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:32
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MSSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_MSSQL Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_MSSQL added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:31
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_MSOracle In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_MSOracle Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_MSOracle added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:26
|
Update of /cvsroot/jcframework/dotnet/Providers/AF_Informix In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10133/AF_Informix Log Message: Directory /cvsroot/jcframework/dotnet/Providers/AF_Informix added to the repository |
From: Richard B. <rb...@us...> - 2005-02-07 07:35:10
|
Update of /cvsroot/jcframework/dotnet/Providers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10029/Providers Log Message: Directory /cvsroot/jcframework/dotnet/Providers added to the repository |
From: Richard B. <rb...@us...> - 2005-02-06 02:50:00
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4173/InheritedClasses Modified Files: Tag: v2_0 AtomsFrameworkTests.vb SuperClassTests.vb TableA_B.vb Log Message: Extra test for collection restoration in the cache after transaction rollback. Slight fix for tableA/B classes in unit tests Index: TableA_B.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/TableA_B.vb,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- TableA_B.vb 31 Jan 2005 22:27:19 -0000 1.4 +++ TableA_B.vb 6 Feb 2005 02:49:52 -0000 1.4.2.1 @@ -62,6 +62,14 @@ _tableBCol.ContainerObject = Me _tableCCol.ContainerObject = Me End Sub + + Private Sub _tableBCol_ObjectAdded(ByVal index As Integer, ByRef value As Object) Handles _tableBCol.ObjectAdded + Me.SetDirtyFlag() + End Sub + + Private Sub _tableBCol_ObjectRemoved(ByVal index As Integer, ByRef value As Object) Handles _tableBCol.ObjectRemoved + Me.SetDirtyFlag() + End Sub End Class Public Class TableB Index: SuperClassTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SuperClassTests.vb,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -d -r1.5 -r1.5.2.1 --- SuperClassTests.vb 2 Jan 2005 09:41:10 -0000 1.5 +++ SuperClassTests.vb 6 Feb 2005 02:49:52 -0000 1.5.2.1 @@ -216,7 +216,7 @@ a1 = CType(cpo, A) - Assert.AreEqual(1, a1.BCol.Count, "Number of objects in collection is grater then 1") + Assert.AreEqual(1, a1.BCol.Count, "Number of objects in collection is greater then 1") End Sub End Class Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -d -r1.11 -r1.11.2.1 --- AtomsFrameworkTests.vb 2 Feb 2005 05:09:03 -0000 1.11 +++ AtomsFrameworkTests.vb 6 Feb 2005 02:49:52 -0000 1.11.2.1 @@ -446,5 +446,44 @@ Assert.AreEqual("2b", CType(a1.TableBCollection.Item(1), TableB).Id) End Sub + <Test()> Public Sub CheckCacheAfterRollback3() + 'Check that null collections are correctly handled + Dim a As New TableA + Dim b As New TableB + Dim a1 As New TableA + a.Id = "aa1a" + a.TableBCollection = Nothing + a.TableCCollection = Nothing + a.Save() + Assert.IsNull(a.TableBCollection) + pbroker.startTransaction() + a1.Id = "aa1a" + a1.Retrieve() + a1.TableBCollection = New CPersistentCollection + b.Id = "b1b" + b.TableA = a1 + a1.TableBCollection.Add(b) + Assert.AreEqual(1, a1.TableBCollection.Count) + a1.Save() + a1 = New TableA + a1.Id = "aa1a" + a1.Retrieve() + b = New TableB + b.Id = "b1b" + b.Retrieve() + Assert.IsTrue(b.Persistent) + Assert.AreEqual(1, a1.TableBCollection.Count) + 'Now abort the transaction + pbroker.rollback() + a1 = New TableA + a1.Id = "aa1a" + a1.Retrieve() + b = New TableB + b.Id = "b1b" + b.Retrieve() + Assert.IsFalse(b.Persistent) + Assert.IsNull(a1.TableBCollection) + End Sub + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-02-06 02:48:56
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3728 Modified Files: Tag: v2_0 AtomsFramework.xml CCacheEntry.vb CPersistenceBroker.vb Log Message: Fix in the cache for precopying collections that haven't been initialized. Fix for multi retrieve criteria when using 3+ level class hierarchies Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.89 retrieving revision 1.89.2.1 diff -u -d -r1.89 -r1.89.2.1 --- CPersistenceBroker.vb 2 Feb 2005 05:08:37 -0000 1.89 +++ CPersistenceBroker.vb 6 Feb 2005 02:48:36 -0000 1.89.2.1 @@ -776,8 +776,11 @@ If udaMap.LazyLoad Then cursor.loadProxy(anObjPers.GetSourceObject) Else - cursor.loadObject(anObjPers.GetSourceObject) - retrieveAssociations(anObjPers, conn, anObjPers.GetClassMap, useCache) + cursor.loadObject(anObjPers.GetSourceObject) + 'To prevent recursive associations causing problems we need to add the + 'object to the cache here as a preliminary measure + m_cache.Add(anObjPers) + retrieveAssociations(anObjPers, conn, anObjPers.GetClassMap, useCache) End If anObjPers.IsDirty = False 'After populating a new object anObjPers.OriginalCacheKey = New CCacheKey(anObjPers) Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.25.2.1 retrieving revision 1.25.2.2 diff -u -d -r1.25.2.1 -r1.25.2.2 --- CCacheEntry.vb 4 Feb 2005 04:46:08 -0000 1.25.2.1 +++ CCacheEntry.vb 6 Feb 2005 02:48:36 -0000 1.25.2.2 @@ -130,35 +130,41 @@ Dim value As Object 'We must precopy this collection into the collection copy 'A simple assignment would just copy a reference to the colletion, while 'we need to copy the collection itself, so that adding/removing elements 'of the original won't effect the copy - m_collectionCollection = New Specialized.HybridDictionary t = m_object.GetObjectType - fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + m_collectionCollection = New Specialized.HybridDictionary t = m_object.GetObjectType + fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) For Each f In fields iListType = f.FieldType.GetInterface("IList", True) iDicType = f.FieldType.GetInterface("IDictionary", True) - 'iEnumerableType = f.FieldType.GetInterface("IEnumerable", True) - If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) - If Not ICloneType Is Nothing Then - 'Getting the ICloneable interface from the object. - Dim IClone As ICloneable = CType(f.GetValue(m_object), ICloneable) - 'We use the clone method to set the new value to the field. - coll = IClone.Clone() - Else - 'If the field doesn't support the ICloneable interface then just set it. - coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one - If Not iListType Is Nothing Then - il = CType(coll, IList) - For Each obj In f.GetValue(m_object.GetSourceObject) - il.Add(obj) - Next - Else - id = CType(coll, IDictionary) - For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) - id.Add(de.Key, de.Value) - Next - End If - End If - m_collectionCollection.Add(f.Name, coll) End If Next + If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then + Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) + If Not ICloneType Is Nothing Then + 'Getting the ICloneable interface from the object. + If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then + Dim IClone As ICloneable = CType(f.GetValue(m_object.GetSourceObject), ICloneable) + coll = IClone.Clone() + Else + coll = Nothing + End If + Else + If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then + 'If the field doesn't support the ICloneable interface then just set it. + coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one + If Not iListType Is Nothing Then + il = CType(coll, IList) + For Each obj In f.GetValue(m_object.GetSourceObject) + il.Add(obj) + Next + Else + id = CType(coll, IDictionary) + For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) + id.Add(de.Key, de.Value) + Next + End If + Else + coll = Nothing + End If + End If + m_collectionCollection.Add(f.Name, coll) End If Next End Sub Public Sub RestoreCollections() Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/dotnet/AtomsFramework.xml,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -d -r1.8 -r1.8.2.1 --- AtomsFramework.xml 16 Aug 2004 04:16:54 -0000 1.8 +++ AtomsFramework.xml 6 Feb 2005 02:48:36 -0000 1.8.2.1 @@ -1,7270 +1,7258 @@ -<?xml version="1.0"?> -<doc> - <assembly> - <name>AToMSFramework</name> - <version>1.22.0.0</version> - <fullname>AToMSFramework, Version=1.22.0.0, Culture=neutral, PublicKeyToken=e5c3a6c915b93944</fullname> - </assembly> - <members> - <member name="T:AToMSFramework.AFTableAttribute"> - <summary> - Custom attribute to define table mappings for a class [...14497 lines suppressed...] + <history> + [rbanks] 18/12/2003 Created + </history></member><member name="T:AToMSFramework.modOIDFactorySingleton"><summary> + Module for managing the ObjectID Factory singleton object + </summary> + <remarks>Manages the references to the singleton <see cref="T:AToMSFramework.COIDFactory" /> object.</remarks> + <history> + [rbanks] 18/12/2003 Created + </history></member><member name="M:AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance"><summary> + Gets a reference to the COIDFactory instance. + </summary> + <returns>A reference to the COIDFactory object.</returns> + <remarks>If the <see cref="T:AToMSFramework.COIDFactory" /> instance does not yet + exist it is created.</remarks> + <history> + [rbanks] 18/12/2003 Created + </history></member></remarks></member> + </members> </doc> \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-02-06 02:45:29
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3333/InheritedClasses Modified Files: AtomsFrameworkTests.vb SuperClassTests.vb TableA_B.vb Log Message: Extra test for collection restoration in the cache after transaction rollback. Slight fix for tableA/B classes in unit tests Index: TableA_B.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/TableA_B.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- TableA_B.vb 31 Jan 2005 22:27:19 -0000 1.4 +++ TableA_B.vb 6 Feb 2005 02:45:19 -0000 1.5 @@ -62,6 +62,14 @@ _tableBCol.ContainerObject = Me _tableCCol.ContainerObject = Me End Sub + + Private Sub _tableBCol_ObjectAdded(ByVal index As Integer, ByRef value As Object) Handles _tableBCol.ObjectAdded + Me.SetDirtyFlag() + End Sub + + Private Sub _tableBCol_ObjectRemoved(ByVal index As Integer, ByRef value As Object) Handles _tableBCol.ObjectRemoved + Me.SetDirtyFlag() + End Sub End Class Public Class TableB Index: SuperClassTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SuperClassTests.vb,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- SuperClassTests.vb 2 Jan 2005 09:41:10 -0000 1.5 +++ SuperClassTests.vb 6 Feb 2005 02:45:19 -0000 1.6 @@ -216,7 +216,7 @@ a1 = CType(cpo, A) - Assert.AreEqual(1, a1.BCol.Count, "Number of objects in collection is grater then 1") + Assert.AreEqual(1, a1.BCol.Count, "Number of objects in collection is greater then 1") End Sub End Class Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- AtomsFrameworkTests.vb 2 Feb 2005 05:09:03 -0000 1.11 +++ AtomsFrameworkTests.vb 6 Feb 2005 02:45:19 -0000 1.12 @@ -446,5 +446,44 @@ Assert.AreEqual("2b", CType(a1.TableBCollection.Item(1), TableB).Id) End Sub + <Test()> Public Sub CheckCacheAfterRollback3() + 'Check that null collections are correctly handled + Dim a As New TableA + Dim b As New TableB + Dim a1 As New TableA + a.Id = "aa1a" + a.TableBCollection = Nothing + a.TableCCollection = Nothing + a.Save() + Assert.IsNull(a.TableBCollection) + pbroker.startTransaction() + a1.Id = "aa1a" + a1.Retrieve() + a1.TableBCollection = New CPersistentCollection + b.Id = "b1b" + b.TableA = a1 + a1.TableBCollection.Add(b) + Assert.AreEqual(1, a1.TableBCollection.Count) + a1.Save() + a1 = New TableA + a1.Id = "aa1a" + a1.Retrieve() + b = New TableB + b.Id = "b1b" + b.Retrieve() + Assert.IsTrue(b.Persistent) + Assert.AreEqual(1, a1.TableBCollection.Count) + 'Now abort the transaction + pbroker.rollback() + a1 = New TableA + a1.Id = "aa1a" + a1.Retrieve() + b = New TableB + b.Id = "b1b" + b.Retrieve() + Assert.IsFalse(b.Persistent) + Assert.IsNull(a1.TableBCollection) + End Sub + End Class End Namespace \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-02-06 02:44:15
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3039 Modified Files: AtomsFramework.xml CCacheEntry.vb CPersistenceBroker.vb Log Message: Fix in the cache for precopying collections that haven't been initialized. Fix for multi retrieve criteria when using 3+ level class hierarchies Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- CPersistenceBroker.vb 2 Feb 2005 05:08:37 -0000 1.89 +++ CPersistenceBroker.vb 6 Feb 2005 02:44:00 -0000 1.90 @@ -776,8 +776,11 @@ If udaMap.LazyLoad Then cursor.loadProxy(anObjPers.GetSourceObject) Else - cursor.loadObject(anObjPers.GetSourceObject) - retrieveAssociations(anObjPers, conn, anObjPers.GetClassMap, useCache) + cursor.loadObject(anObjPers.GetSourceObject) + 'To prevent recursive associations causing problems we need to add the + 'object to the cache here as a preliminary measure + m_cache.Add(anObjPers) + retrieveAssociations(anObjPers, conn, anObjPers.GetClassMap, useCache) End If anObjPers.IsDirty = False 'After populating a new object anObjPers.OriginalCacheKey = New CCacheKey(anObjPers) Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- CCacheEntry.vb 4 Feb 2005 04:39:09 -0000 1.26 +++ CCacheEntry.vb 6 Feb 2005 02:44:00 -0000 1.27 @@ -130,35 +130,41 @@ Dim value As Object 'We must precopy this collection into the collection copy 'A simple assignment would just copy a reference to the colletion, while 'we need to copy the collection itself, so that adding/removing elements 'of the original won't effect the copy - m_collectionCollection = New Specialized.HybridDictionary t = m_object.GetObjectType - fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) + m_collectionCollection = New Specialized.HybridDictionary t = m_object.GetObjectType + fields = t.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public) For Each f In fields iListType = f.FieldType.GetInterface("IList", True) iDicType = f.FieldType.GetInterface("IDictionary", True) - 'iEnumerableType = f.FieldType.GetInterface("IEnumerable", True) - If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) - If Not ICloneType Is Nothing Then - 'Getting the ICloneable interface from the object. - Dim IClone As ICloneable = CType(f.GetValue(m_object), ICloneable) - 'We use the clone method to set the new value to the field. - coll = IClone.Clone() - Else - 'If the field doesn't support the ICloneable interface then just set it. - coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one - If Not iListType Is Nothing Then - il = CType(coll, IList) - For Each obj In f.GetValue(m_object.GetSourceObject) - il.Add(obj) - Next - Else - id = CType(coll, IDictionary) - For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) - id.Add(de.Key, de.Value) - Next - End If - End If - m_collectionCollection.Add(f.Name, coll) End If Next + If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then + Dim ICloneType As Type = f.FieldType.GetInterface("ICloneable", True) + If Not ICloneType Is Nothing Then + 'Getting the ICloneable interface from the object. + If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then + Dim IClone As ICloneable = CType(f.GetValue(m_object.GetSourceObject), ICloneable) + coll = IClone.Clone() + Else + coll = Nothing + End If + Else + If Not f.GetValue(m_object.GetSourceObject) Is Nothing Then + 'If the field doesn't support the ICloneable interface then just set it. + coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one + If Not iListType Is Nothing Then + il = CType(coll, IList) + For Each obj In f.GetValue(m_object.GetSourceObject) + il.Add(obj) + Next + Else + id = CType(coll, IDictionary) + For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) + id.Add(de.Key, de.Value) + Next + End If + Else + coll = Nothing + End If + End If + m_collectionCollection.Add(f.Name, coll) End If Next End Sub Public Sub RestoreCollections() Index: AtomsFramework.xml =================================================================== RCS file: /cvsroot/jcframework/dotnet/AtomsFramework.xml,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- AtomsFramework.xml 16 Aug 2004 04:16:54 -0000 1.8 +++ AtomsFramework.xml 6 Feb 2005 02:44:00 -0000 1.9 @@ -1,7270 +1,7258 @@ -<?xml version="1.0"?> -<doc> - <assembly> - <name>AToMSFramework</name> - <version>1.22.0.0</version> - <fullname>AToMSFramework, Version=1.22.0.0, Culture=neutral, PublicKeyToken=e5c3a6c915b93944</fullname> - </assembly> - <members> - <member name="T:AToMSFramework.AFTableAttribute"> - <summary> - Custom attribute to define table mappings for a class [...14497 lines suppressed...] + <history> + [rbanks] 18/12/2003 Created + </history></member><member name="T:AToMSFramework.modOIDFactorySingleton"><summary> + Module for managing the ObjectID Factory singleton object + </summary> + <remarks>Manages the references to the singleton <see cref="T:AToMSFramework.COIDFactory" /> object.</remarks> + <history> + [rbanks] 18/12/2003 Created + </history></member><member name="M:AToMSFramework.modOIDFactorySingleton.getOIDFactoryInstance"><summary> + Gets a reference to the COIDFactory instance. + </summary> + <returns>A reference to the COIDFactory object.</returns> + <remarks>If the <see cref="T:AToMSFramework.COIDFactory" /> instance does not yet + exist it is created.</remarks> + <history> + [rbanks] 18/12/2003 Created + </history></member></remarks></member> + </members> </doc> \ No newline at end of file |
From: Richard B. <rb...@us...> - 2005-02-04 04:46:19
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27342 Modified Files: Tag: v2_0 CCacheEntry.vb CInjectedObject.vb Log Message: -- Merged from HEAD Fix for collection/transaction handling when using interface based persistence. Fix for x.y format mapping when object x is nothing Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -u -d -r1.9 -r1.9.2.1 --- CInjectedObject.vb 31 Jan 2005 06:17:39 -0000 1.9 +++ CInjectedObject.vb 4 Feb 2005 04:46:08 -0000 1.9.2.1 @@ -205,6 +205,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CallByName(o, propertyName, CallType.Get) End If End Function @@ -221,6 +224,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_originalObject, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CallByName(o, propertyName, CallType.Get) End If End Function @@ -427,6 +433,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CType(CallByName(o, propertyName, CallType.Get), IList) End If Catch err As Exception @@ -450,6 +459,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If obj = CallByName(o, propertyName, CallType.Get) End If If obj Is Nothing Then Return Nothing @@ -489,6 +501,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return + End If If o.GetType.IsValueType Then val = o If TypeOf (Value) Is System.SByte Then Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.25 retrieving revision 1.25.2.1 diff -u -d -r1.25 -r1.25.2.1 --- CCacheEntry.vb 2 Feb 2005 05:08:37 -0000 1.25 +++ CCacheEntry.vb 4 Feb 2005 04:46:08 -0000 1.25.2.1 @@ -148,12 +148,12 @@ coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one If Not iListType Is Nothing Then il = CType(coll, IList) - For Each obj In f.GetValue(m_object) + For Each obj In f.GetValue(m_object.GetSourceObject) il.Add(obj) Next Else id = CType(coll, IDictionary) - For Each de As DictionaryEntry In f.GetValue(m_object) + For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) id.Add(de.Key, de.Value) Next End If @@ -170,7 +170,7 @@ iDicType = f.FieldType.GetInterface("IDictionary", True) 'iEnumerableType = f.FieldType.GetInterface("IEnumerable", True) If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - 'We must restore this collection from the collection copy 'Just use a straight value assignment - no need to worry about cloning f.SetValue(m_object, m_collectionCollection.Item(f.Name)) End If Next + 'We must restore this collection from the collection copy 'Just use a straight value assignment - no need to worry about cloning f.SetValue(m_object.GetSourceObject, m_collectionCollection.Item(f.Name)) End If Next End Sub Public Sub New(ByVal lifetime As Double) |
From: Richard B. <rb...@us...> - 2005-02-04 04:39:30
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25699 Modified Files: CCacheEntry.vb CInjectedObject.vb Log Message: Fix for collection/transaction handling when using interface based persistence. Fix for x.y format mapping when object x is nothing Index: CInjectedObject.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CInjectedObject.vb,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CInjectedObject.vb 31 Jan 2005 06:17:39 -0000 1.9 +++ CInjectedObject.vb 4 Feb 2005 04:39:20 -0000 1.10 @@ -205,6 +205,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CallByName(o, propertyName, CallType.Get) End If End Function @@ -221,6 +224,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_originalObject, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CallByName(o, propertyName, CallType.Get) End If End Function @@ -427,6 +433,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If Return CType(CallByName(o, propertyName, CallType.Get), IList) End If Catch err As Exception @@ -450,6 +459,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return Nothing + End If obj = CallByName(o, propertyName, CallType.Get) End If If obj Is Nothing Then Return Nothing @@ -489,6 +501,9 @@ objName = pName.Substring(0, dotPos) propertyName = pName.Substring(dotPos + 1) o = CallByName(m_object, objName, CallType.Get) + If o Is Nothing Then + Return + End If If o.GetType.IsValueType Then val = o If TypeOf (Value) Is System.SByte Then Index: CCacheEntry.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CCacheEntry.vb,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- CCacheEntry.vb 2 Feb 2005 05:08:37 -0000 1.25 +++ CCacheEntry.vb 4 Feb 2005 04:39:09 -0000 1.26 @@ -148,12 +148,12 @@ coll = Activator.CreateInstance(f.FieldType) 'need to copy references one-by-one If Not iListType Is Nothing Then il = CType(coll, IList) - For Each obj In f.GetValue(m_object) + For Each obj In f.GetValue(m_object.GetSourceObject) il.Add(obj) Next Else id = CType(coll, IDictionary) - For Each de As DictionaryEntry In f.GetValue(m_object) + For Each de As DictionaryEntry In f.GetValue(m_object.GetSourceObject) id.Add(de.Key, de.Value) Next End If @@ -170,7 +170,7 @@ iDicType = f.FieldType.GetInterface("IDictionary", True) 'iEnumerableType = f.FieldType.GetInterface("IEnumerable", True) If Not iListType Is Nothing OrElse Not iDicType Is Nothing Then - 'We must restore this collection from the collection copy 'Just use a straight value assignment - no need to worry about cloning f.SetValue(m_object, m_collectionCollection.Item(f.Name)) End If Next + 'We must restore this collection from the collection copy 'Just use a straight value assignment - no need to worry about cloning f.SetValue(m_object.GetSourceObject, m_collectionCollection.Item(f.Name)) End If Next End Sub Public Sub New(ByVal lifetime As Double) |
From: Richard B. <rb...@us...> - 2005-02-02 05:09:13
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22485/InheritedClasses Modified Files: AtomsFrameworkTests.vb Log Message: Extra unit test for restoring collections of cached objects after transaction aborts. Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- AtomsFrameworkTests.vb 31 Jan 2005 22:27:17 -0000 1.10 +++ AtomsFrameworkTests.vb 2 Feb 2005 05:09:03 -0000 1.11 @@ -443,7 +443,7 @@ b.Retrieve() Assert.IsTrue(b.Persistent) Assert.AreEqual(3, a1.TableBCollection.Count) - Assert.AreEqual("2b", a1.TableBCollection.Item(1)) + Assert.AreEqual("2b", CType(a1.TableBCollection.Item(1), TableB).Id) End Sub End Class |