18 using System.Collections.Generic;
26 namespace Deveel.Data.Client {
33 private readonly
object stateLock =
new object();
42 connectionString = settings;
51 if (Transaction != null)
58 throw new NotSupportedException(
String.Format(
"Isolation Level '{0}' is not supported yet.", isolationLevel));
60 var commitId = BeginServerTransaction(isolationLevel);
65 return BeginTransaction(isolationLevel);
71 if (State == ConnectionState.Closed)
74 if (openReaders != null) {
75 foreach (var reader
in openReaders.Values) {
84 if (Transaction != null) {
85 Transaction.Rollback();
90 }
catch (Exception ex) {
91 throw new DeveelDbException(
"An error occurred while closing the connection.", ex);
93 ChangeState(ConnectionState.Closed);
99 throw new NotImplementedException();
104 if (State == ConnectionState.Open)
107 if (State != ConnectionState.Closed)
111 ChangeState(ConnectionState.Connecting);
114 Client.Authenticate();
116 serverVersion = Client.ServerVersion;
117 }
catch (Exception) {
118 ChangeState(ConnectionState.Broken);
124 ChangeState(ConnectionState.Open);
128 public override string ConnectionString {
129 get {
return Settings.ToString(); }
134 get {
return connectionString; }
137 connectionString = value;
146 public override ConnectionState State {
154 public override string DataSource {
156 if (
String.IsNullOrEmpty(dataSource)) {
158 !
String.IsNullOrEmpty(connectionString.
Host)) {
159 dataSource =
String.Format(
"{0}:{1}", connectionString.
Host, connectionString.
Port);
169 public override string ServerVersion {
170 get {
return serverVersion; }
173 public override int ConnectionTimeout {
174 get {
return Settings.QueryTimeout; }
180 return CreateCommand();
188 if (state != ConnectionState.Closed)
189 throw new InvalidOperationException(
"The connection is not closed.");
193 if (state != ConnectionState.Fetching)
194 throw new InvalidOperationException(
"The connection is not fetching data.");
199 if (state != newState)
200 OnStateChange(
new StateChangeEventArgs(state, newState));
208 ChangeState(oldState);
214 return Client.BeginTransaction(isolationLevel);
215 }
catch (Exception ex) {
224 Client.CommitTransaction(commitId);
225 }
catch (Exception ex) {
234 Client.RollbackTransaction(commitId);
235 }
catch (Exception ex) {
236 throw new DeveelDbException(
String.Format(
"Could not ROLLBACK transaction '{0}' on the server.", commitId), ex);
243 return Client.ExecuteQuery(commitId, query);
244 }
catch (Exception ex) {
251 return Client.GetResultPart(resultId, rowIndex, rowCount);
252 }
catch (Exception ex) {
253 throw new DeveelDbException(
String.Format(
"Could not retrieve part of the result '{0}' from the server.", resultId), ex);
259 Client.DisposeResult(resultId);
260 }
catch (Exception ex) {
265 protected override void Dispose(
bool disposing) {
275 base.Dispose(disposing);
Dictionary< string, DeveelDbDataReader > openReaders
DeveelDbConnectionStringBuilder connectionString
A long string in the system.
void ChangeState(ConnectionState newState)
override DbCommand CreateDbCommand()
The response to a command executed via the IDatabaseInterface.ExecuteQuery method in the IDatabaseInt...
The default implementation of a database in a system.
Database(DatabaseSystem system, IDatabaseContext context)
void RollbackTransaction(int commitId)
override void Dispose(bool disposing)
void CommitTransaction(int commitId)
override void ChangeDatabase(string databaseName)
int BeginServerTransaction(IsolationLevel isolationLevel)
QueryResultPart RequestResultPart(int resultId, int rowIndex, int rowCount)
A cache that stores rows retrieved from the server in result set's.
void DisposeResult(int resultId)
override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
IQueryResponse[] ExecuteQuery(int commitId, SqlQuery query)
new DeveelDbTransaction BeginTransaction(IsolationLevel isolationLevel)
new DeveelDbCommand CreateCommand()
DeveelDbConnection(IClientConnector connector, DeveelDbConnectionStringBuilder settings)