DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Session Class Reference

This is a session that is constructed around a given user and a transaction, to the given database. More...

Inheritance diagram for Deveel.Data.Session:
Deveel.Data.ISession Deveel.Data.Diagnostics.IEventSource

Public Member Functions

 Session (ITransaction transaction, User user)
 Constructs the session for the given user and transaction to the given database. More...
 
void Dispose ()
 
void Access (IEnumerable< IDbObject > objects, AccessType accessType)
 
void Exit (IEnumerable< IDbObject > objects, AccessType accessType)
 
void Lock (IEnumerable< IDbObject > objects, AccessType accessType, LockingMode mode)
 
void Commit ()
 Commits the latest changes made by the user in the session. More...
 
void Rollback ()
 Rolls-back all the modifications made by the user in this session More...
 
IQuery CreateQuery ()
 

Properties

string CurrentSchema [get]
 
DateTimeOffset LastCommandTime [get, private set]
 
DateTimeOffset StartedOn [get, private set]
 
ISessionContext Context [get, private set]
 
User User [get, private set]
 
IEventSource IEventSource. ParentSource [get]
 
IContext IEventSource. Context [get]
 
IEnumerable< KeyValuePair< string, object > > IEventSource. Metadata [get]
 
ITransaction Transaction [get, private set]
 
IDatabase Database [get]
 
- Properties inherited from Deveel.Data.ISession
string CurrentSchema [get]
 Gets the name of the current schema of this session. More...
 
DateTimeOffset StartedOn [get]
 
DateTimeOffset LastCommandTime [get]
 
User User [get]
 
ITransaction Transaction [get]
 Gets the instance of ITransaction that handles the transactional operations of this session. More...
 
new ISessionContext Context [get]
 
- Properties inherited from Deveel.Data.Diagnostics.IEventSource
IContext Context [get]
 
IEventSource ParentSource [get]
 Gets an optional parent source. More...
 
IEnumerable< KeyValuePair< string, object > > Metadata [get]
 Gets the list of metadata associated to the source. More...
 

Private Member Functions

 ~Session ()
 
IEnumerable< KeyValuePair< string, object > > GetMetadata ()
 
void AssertNotDisposed ()
 
void CheckAccess (ILockable[] lockables, AccessType accessType)
 
void ReleaseLocks ()
 
void OnCommand ()
 
void DisposeTransaction ()
 
void Dispose (bool disposing)
 

Private Attributes

List< LockHandlelockHandles
 
bool disposed
 

Detailed Description

This is a session that is constructed around a given user and a transaction, to the given database.

Definition at line 32 of file Session.cs.

Constructor & Destructor Documentation

Deveel.Data.Session.Session ( ITransaction  transaction,
User  user 
)
inline

Constructs the session for the given user and transaction to the given database.

Parameters
transactionA transaction that handles the commands issued by the user during the session.
user
See also
ITransaction

Definition at line 44 of file Session.cs.

44  {
45  if (transaction == null)
46  throw new ArgumentNullException("transaction");
47 
48  if (user == null)
49  throw new ArgumentNullException("user");
50 
51  if (user.IsSystem || user.IsPublic)
52  throw new ArgumentException(String.Format("Cannot open a session for user '{0}'.", user.Name));
53 
54  Transaction = transaction;
55  Context = transaction.Context.CreateSessionContext();
56 
57  transaction.Database.Sessions.Add(this);
58 
59  User = user;
60  StartedOn = DateTimeOffset.UtcNow;
61  }
A long string in the system.
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
bool IsSystem
Gets a boolean value indicating if this user represents the SYSTEM special user.
Definition: User.cs:64
IDatabase Database
Gets the database this transaction belongs to.
Definition: ITransaction.cs:48
DateTimeOffset StartedOn
Definition: Session.cs:78
bool IsPublic
Gets a boolean value indicating if this user represents the PUBLIC special user.
Definition: User.cs:72
bool Add(ISession session)
ISessionContext Context
Definition: Session.cs:80
new ITransactionContext Context
Definition: ITransaction.cs:31
ActiveSessionList Sessions
Gets a list of all the open sessions to the database.
Definition: IDatabase.cs:65
Provides the information for a user in a database system
Definition: User.cs:27
string Name
Gets the name that uniquely identify a user within a database system.
Definition: User.cs:57
Deveel.Data.Session.~Session ( )
inlineprivate

Definition at line 63 of file Session.cs.

63  {
64  Dispose(false);
65  }

Member Function Documentation

void Deveel.Data.Session.Access ( IEnumerable< IDbObject objects,
AccessType  accessType 
)
inline

Implements Deveel.Data.ISession.

Definition at line 111 of file Session.cs.

111  {
112  if (Database == null)
113  return;
114 
115  lock (Database) {
116  var lockables = objects.OfType<ILockable>().ToArray();
117  if (lockables.Length == 0)
118  return;
119 
120  CheckAccess(lockables, accessType);
121 
122  var isolation = Transaction.Isolation;
123 
124  LockHandle handle;
125 
126  if (isolation == IsolationLevel.Serializable) {
127  handle = Database.Locker.Lock(lockables, AccessType.ReadWrite, LockingMode.Exclusive);
128  } else {
129  throw new NotImplementedException(string.Format("The locking for isolation '{0}' is not implemented yet.", isolation));
130  }
131 
132  if (handle != null) {
133  if (lockHandles == null)
134  lockHandles = new List<LockHandle>();
135 
136  lockHandles.Add(handle);
137  }
138  }
139  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
LockingMode
The mode applied to a lock over a resource during a transaction.
Definition: LockingMode.cs:24
Locker Locker
Gets the objects that is used to lock database objects between transactions.
Definition: IDatabase.cs:74
List< LockHandle > lockHandles
Definition: Session.cs:33
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
IDatabase Database
Definition: Session.cs:192
void CheckAccess(ILockable[] lockables, AccessType accessType)
Definition: Session.cs:166
void Deveel.Data.Session.AssertNotDisposed ( )
inlineprivate

Definition at line 106 of file Session.cs.

106  {
107  if (disposed)
108  throw new ObjectDisposedException("Session");
109  }
void Deveel.Data.Session.CheckAccess ( ILockable[]  lockables,
AccessType  accessType 
)
inlineprivate

Definition at line 166 of file Session.cs.

166  {
167  if (lockHandles == null || lockables == null)
168  return;
169 
170  foreach (var handle in lockHandles) {
171  foreach (var lockable in lockables) {
172  if (handle.IsHandled(lockable))
173  handle.CheckAccess(lockable, accessType);
174  }
175  }
176  }
List< LockHandle > lockHandles
Definition: Session.cs:33
void Deveel.Data.Session.Commit ( )
inline

Commits the latest changes made by the user in the session.

See also
ITransaction

Implements Deveel.Data.ISession.

Definition at line 200 of file Session.cs.

200  {
202 
203  if (Transaction != null) {
204  try {
206  } finally {
207  OnCommand();
209  }
210  }
211  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void Commit()
Commits all write operation done during the lifetime of this transaction and invalidates it...
Definition: Transaction.cs:179
void DisposeTransaction()
Definition: Session.cs:226
void AssertNotDisposed()
Definition: Session.cs:106
IQuery Deveel.Data.Session.CreateQuery ( )
inline

Implements Deveel.Data.ISession.

Definition at line 235 of file Session.cs.

235  {
236  return new Query(this);
237  }
void Deveel.Data.Session.Dispose ( )
inline

Definition at line 67 of file Session.cs.

67  {
68  Dispose(true);
69  GC.SuppressFinalize(this);
70  }
void Deveel.Data.Session.Dispose ( bool  disposing)
inlineprivate

Definition at line 239 of file Session.cs.

239  {
240  if (!disposed) {
241  if (disposing) {
242  try {
243  Rollback();
244  } catch (Exception) {
245  // TODO: Notify the underlying system
246  }
247  }
248 
249  lockHandles = null;
250  disposed = true;
251  }
252  }
void Rollback()
Rolls-back all the modifications made by the user in this session
Definition: Session.cs:213
List< LockHandle > lockHandles
Definition: Session.cs:33
void Deveel.Data.Session.DisposeTransaction ( )
inlineprivate

Definition at line 226 of file Session.cs.

226  {
227  ReleaseLocks();
228 
229  if (Database != null)
230  Database.Sessions.Remove(this);
231 
232  Transaction = null;
233  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void ReleaseLocks()
Definition: Session.cs:178
IDatabase Database
Definition: Session.cs:192
ActiveSessionList Sessions
Gets a list of all the open sessions to the database.
Definition: IDatabase.cs:65
void Remove(ISession session)
void Deveel.Data.Session.Exit ( IEnumerable< IDbObject objects,
AccessType  accessType 
)
inline

Implements Deveel.Data.ISession.

Definition at line 141 of file Session.cs.

141  {
142  // Only SERIALIZABLE isolation is supported, that means locks for read and write
143  // are acquired on access and released only at the end of the session/transaction
144  throw new NotImplementedException("The Exit mechanism is not implemented");
145  }
IEnumerable<KeyValuePair<string, object> > Deveel.Data.Session.GetMetadata ( )
inlineprivate

Definition at line 96 of file Session.cs.

96  {
97  return new Dictionary<string, object> {
101  };
102  }
DateTimeOffset StartedOn
Definition: Session.cs:78
DateTimeOffset LastCommandTime
Definition: Session.cs:76
Provides the information for a user in a database system
Definition: User.cs:27
string Name
Gets the name that uniquely identify a user within a database system.
Definition: User.cs:57
void Deveel.Data.Session.Lock ( IEnumerable< IDbObject objects,
AccessType  accessType,
LockingMode  mode 
)
inline

Implements Deveel.Data.ISession.

Definition at line 147 of file Session.cs.

147  {
148  lock (Database) {
149  var lockables = objects.OfType<ILockable>().ToArray();
150  if (lockables.Length == 0)
151  return;
152 
153  // Before we can lock the objects, we must wait for them
154  // to be available...
155  CheckAccess(lockables, accessType);
156 
157  var handle = Database.Locker.Lock(lockables, accessType, mode);
158 
159  if (lockHandles == null)
160  lockHandles = new List<LockHandle>();
161 
162  lockHandles.Add(handle);
163  }
164  }
Locker Locker
Gets the objects that is used to lock database objects between transactions.
Definition: IDatabase.cs:74
List< LockHandle > lockHandles
Definition: Session.cs:33
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
IDatabase Database
Definition: Session.cs:192
void CheckAccess(ILockable[] lockables, AccessType accessType)
Definition: Session.cs:166
void Deveel.Data.Session.OnCommand ( )
inlineprivate

Definition at line 196 of file Session.cs.

196  {
197  LastCommandTime = DateTimeOffset.UtcNow;
198  }
DateTimeOffset LastCommandTime
Definition: Session.cs:76
void Deveel.Data.Session.ReleaseLocks ( )
inlineprivate

Definition at line 178 of file Session.cs.

178  {
179  if (Database == null)
180  return;
181 
182  lock (Database) {
183  if (lockHandles != null) {
184  foreach (var handle in lockHandles) {
185  if (handle != null)
186  handle.Release();
187  }
188  }
189  }
190  }
List< LockHandle > lockHandles
Definition: Session.cs:33
IDatabase Database
Definition: Session.cs:192
void Deveel.Data.Session.Rollback ( )
inline

Rolls-back all the modifications made by the user in this session

<seealse cref="ITransaction">

Implements Deveel.Data.ISession.

Definition at line 213 of file Session.cs.

213  {
215 
216  if (Transaction != null) {
217  try {
219  } finally {
220  OnCommand();
222  }
223  }
224  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void Rollback()
Rollback any write operations done during the lifetime of this transaction and invalidates it...
Definition: Transaction.cs:239
void DisposeTransaction()
Definition: Session.cs:226
void AssertNotDisposed()
Definition: Session.cs:106

Member Data Documentation

bool Deveel.Data.Session.disposed
private

Definition at line 34 of file Session.cs.

List<LockHandle> Deveel.Data.Session.lockHandles
private

Definition at line 33 of file Session.cs.

Property Documentation

ISessionContext Deveel.Data.Session.Context
getprivate set

Definition at line 80 of file Session.cs.

IContext IEventSource. Deveel.Data.Session.Context
getprivate

Definition at line 88 of file Session.cs.

string Deveel.Data.Session.CurrentSchema
get

Definition at line 72 of file Session.cs.

IDatabase Deveel.Data.Session.Database
get

Definition at line 192 of file Session.cs.

DateTimeOffset Deveel.Data.Session.LastCommandTime
getprivate set

Definition at line 76 of file Session.cs.

IEnumerable<KeyValuePair<string, object> > IEventSource. Deveel.Data.Session.Metadata
getprivate

Definition at line 92 of file Session.cs.

IEventSource IEventSource. Deveel.Data.Session.ParentSource
getprivate

Definition at line 84 of file Session.cs.

DateTimeOffset Deveel.Data.Session.StartedOn
getprivate set

Definition at line 78 of file Session.cs.

ITransaction Deveel.Data.Session.Transaction
getprivate set

Definition at line 104 of file Session.cs.

User Deveel.Data.Session.User
getprivate set

Definition at line 82 of file Session.cs.


The documentation for this class was generated from the following file: