Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs')
-rw-r--r--mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs204
1 files changed, 137 insertions, 67 deletions
diff --git a/mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs b/mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs
index 2558a011120..0e0f3e3e5e7 100644
--- a/mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs
+++ b/mcs/class/System.Data/System.Data.SqlClient.jvm/SqlConnection.cs
@@ -1,70 +1,62 @@
//
// System.Data.SqlClient.SqlConnection
-//
-// Authors:
-// Konstantin Triger <kostat@mainsoft.com>
-// Boris Kirzner <borisk@mainsoft.com>
-//
-// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Authors:
+// Konstantin Triger <kostat@mainsoft.com>
+// Boris Kirzner <borisk@mainsoft.com>
+//
+// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Data;
using System.Data.Common;
using System.Collections;
-using System.Data.ProviderBase;
using java.sql;
-using System.Configuration;
-using Mainsoft.Data.Configuration;
-using Mainsoft.Data.Jdbc.Providers;
-
namespace System.Data.SqlClient
{
- public class SqlConnection : AbstractDBConnection
+ public class SqlConnection : AbstractDBConnection, IDbConnection, System.ICloneable
{
#region Fields
private const int DEFAULT_PACKET_SIZE = 8192;
- static readonly IConnectionProvider _connectionProvider;
+ protected static Hashtable _skippedUserParameters = new Hashtable(new CaseInsensitiveHashCodeProvider(),new CaseInsensitiveComparer());
+
+ private static readonly object _lockObjectStringManager = new object();
+ //private static DbStringManager _stringManager = new DbStringManager("System.Data.System.Data.ProviderBase.jvm.SqlClientStrings");
+
+ private static readonly string[] _resourceIgnoredKeys = new string[] {"CON_DATA_SOURCE","CON_DATABASE",
+ "CON_PASSWORD","CON_USER_ID","CON_TIMEOUT",
+ "CON_JNDI_NAME","CON_JNDI_PROVIDER","CON_JNDI_FACTORY",
+ "CON_WORKSTATION_ID","CON_PACKET_SIZE"};
#endregion // Fields
#region Constructors
- static SqlConnection() {
- IDictionary providerInfo = (IDictionary)((IList) ConfigurationSettings.GetConfig("Mainsoft.Data.Configuration/SqlClientProvider"))[0];
- string providerType = (string) providerInfo [ConfigurationConsts.ProviderType];
- if (providerType == null || providerType.Length == 0)
- _connectionProvider = new GenericProvider (providerInfo);
- else {
- Type t = Type.GetType (providerType);
- _connectionProvider = (IConnectionProvider) Activator.CreateInstance (t , new object[] {providerInfo});
- }
- }
-
public SqlConnection() : this(null)
{
}
@@ -77,12 +69,12 @@ namespace System.Data.SqlClient
#region Events
- [DataCategory ("InfoMessage")]
- [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
- public event SqlInfoMessageEventHandler InfoMessage;
-
- [DataCategory ("StateChange")]
- [DataSysDescription ("Event triggered when the connection changes state.")]
+ [DataCategory ("InfoMessage")]
+ [DataSysDescription ("Event triggered when messages arrive from the DataSource.")]
+ public event SqlInfoMessageEventHandler InfoMessage;
+
+ [DataCategory ("StateChange")]
+ [DataSysDescription ("Event triggered when the connection changes state.")]
public event StateChangeEventHandler StateChange;
#endregion // Events
@@ -91,14 +83,30 @@ namespace System.Data.SqlClient
public string WorkstationId
{
- get { return (string)ConnectionStringBuilder["workstation id"]; }
+ get { return ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_WORKSTATION_ID")); }
+ }
+
+ protected override string JdbcDriverName
+ {
+ get { return StringManager.GetString("JDBC_DRIVER"); }
+ }
+
+ protected internal override JDBC_MODE JdbcMode
+ {
+ get {
+ string[] conJndiNameStr = StringManager.GetStringArray("CON_JNDI_NAME");
+ if (!String.Empty.Equals(ConnectionStringHelper.FindValue(UserParameters,conJndiNameStr))) {
+ return JDBC_MODE.DATA_SOURCE_MODE;
+ }
+ return JDBC_MODE.PROVIDER_MODE;
+ }
}
public int PacketSize
{
get {
- string packetSize = (string)ConnectionStringBuilder["Packet Size"];
- if (packetSize == null || packetSize.Length == 0) {
+ string packetSize = ConnectionStringHelper.FindValue(UserParameters,StringManager.GetStringArray("CON_PACKET_SIZE"));
+ if (String.Empty.Equals(packetSize)) {
return DEFAULT_PACKET_SIZE;
}
try {
@@ -113,14 +121,55 @@ namespace System.Data.SqlClient
}
}
- protected override IConnectionProvider GetConnectionProvider() {
- return _connectionProvider;
+ protected override string[] ResourceIgnoredKeys
+ {
+ get { return _resourceIgnoredKeys; }
+ }
+
+ protected override Hashtable SkippedUserParameters
+ {
+ get { return _skippedUserParameters; }
+ }
+
+ protected override PROVIDER_TYPE ProviderType
+ {
+ get {
+ if (JdbcMode != JDBC_MODE.PROVIDER_MODE) {
+ return PROVIDER_TYPE.NONE;
+ }
+ return PROVIDER_TYPE.SQLOLEDB;
+ }
+ }
+
+ protected override DbStringManager StringManager
+ {
+ get {
+ const string stringManagerName = "System.Data.OleDbConnection.stringManager";
+ object stringManager = AppDomain.CurrentDomain.GetData(stringManagerName);
+ if (stringManager == null) {
+ lock(_lockObjectStringManager) {
+ stringManager = AppDomain.CurrentDomain.GetData(stringManagerName);
+ if (stringManager != null)
+ return (DbStringManager)stringManager;
+ stringManager = new DbStringManager("System.Data.System.Data.ProviderBase.jvm.SqlClientStrings");
+ AppDomain.CurrentDomain.SetData(stringManagerName, stringManager);
+ }
+ }
+ return (DbStringManager)stringManager;
+ }
}
#endregion // Properties
#region Methods
+ protected internal override void ValidateConnectionString(string connectionString)
+ {
+ base.ValidateConnectionString(connectionString);
+
+ // FIXME : validate packet size
+ }
+
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) {
return BeginTransaction(isolationLevel);
}
@@ -154,30 +203,42 @@ namespace System.Data.SqlClient
return CreateCommand();
}
- protected internal sealed override void OnSqlWarning(SQLWarning warning)
+ internal override void OnSqlWarning(SQLWarning warning)
{
SqlErrorCollection col = new SqlErrorCollection(warning, this);
OnSqlInfoMessage(new SqlInfoMessageEventArgs(col));
}
- protected sealed override SystemException CreateException(SQLException e)
+ protected internal override void CopyTo(AbstractDBConnection target)
{
- return new SqlException(e, this);
+ base.CopyTo(target);
}
- protected sealed override SystemException CreateException(string message)
+ public object Clone()
{
- return new SqlException(message, null, this);
+ SqlConnection clone = new SqlConnection();
+ CopyTo(clone);
+ return clone;
}
- private void OnSqlInfoMessage (SqlInfoMessageEventArgs value)
+ protected override SystemException CreateException(SQLException e)
{
- if (InfoMessage != null) {
- InfoMessage (this, value);
- }
+ return new SqlException(e, this);
+ }
+
+ protected override SystemException CreateException(string message)
+ {
+ return new SqlException(message, null, this);
}
- protected internal sealed override void OnStateChanged(ConnectionState orig, ConnectionState current)
+ private void OnSqlInfoMessage (SqlInfoMessageEventArgs value)
+ {
+ if (InfoMessage != null) {
+ InfoMessage (this, value);
+ }
+ }
+
+ internal override void OnStateChanged(ConnectionState orig, ConnectionState current)
{
if(StateChange != null) {
StateChange(this, new StateChangeEventArgs(orig, current));
@@ -194,7 +255,16 @@ namespace System.Data.SqlClient
}
}
+ protected override string BuildJdbcUrl()
+ {
+ switch (JdbcMode) {
+ case JDBC_MODE.PROVIDER_MODE :
+ return BuildMsSqlUrl();
+ }
+ return base.BuildJdbcUrl();
+ }
+
#endregion // Methods
}
-}
+} \ No newline at end of file