DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemSession.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 
20 using Deveel.Data.Diagnostics;
21 using Deveel.Data.Security;
22 using Deveel.Data.Services;
23 using Deveel.Data.Sql;
24 using Deveel.Data.Store;
26 
27 namespace Deveel.Data {
29  public SystemSession(ITransaction transaction)
30  : this(transaction, transaction.CurrentSchema()) {
31  }
32 
33  public SystemSession(ITransaction transaction, string currentSchema) {
34  if (String.IsNullOrEmpty(currentSchema))
35  throw new ArgumentNullException("currentSchema");
36 
37  CurrentSchema =currentSchema;
38  Transaction = transaction;
39  Context = transaction.Context.CreateSessionContext();
40  StartedOn = DateTimeOffset.UtcNow;
41  }
42 
43  public void Dispose() {
44  Transaction = null;
45  }
46 
47  public string CurrentSchema { get; private set; }
48 
49  public DateTimeOffset StartedOn { get; private set; }
50 
51  public DateTimeOffset? LastCommandTime {
52  get { return null; }
53  }
54 
55  public User User {
56  get { return User.System; }
57  }
58 
59  public ITransaction Transaction { get; private set; }
60 
61  public ISessionContext Context { get; private set; }
62 
63  IEnumerable<KeyValuePair<string, object>> IEventSource.Metadata {
64  get { return GetMetaData(); }
65  }
66 
68  get { return Transaction; }
69  }
70 
72  get { return Context; }
73  }
74 
75  private IEnumerable<KeyValuePair<string, object>> GetMetaData() {
76  return new Dictionary<string, object> {
77  { "session.user", User.SystemName }
78  };
79  }
80 
81  public ILargeObject CreateLargeObject(long size, bool compressed) {
82  throw new NotSupportedException();
83  }
84 
86  throw new NotSupportedException();
87  }
88 
89  public void Access(IEnumerable<IDbObject> objects, AccessType accessType) {
90  // A system session bypasses any lock
91  }
92 
93  public void Exit(IEnumerable<IDbObject> objects, AccessType accessType) {
94  // A system session does not hold any lock
95  }
96 
97  public void Lock(IEnumerable<IDbObject> objects, AccessType accessType, LockingMode mode) {
98  // A system session does not hold any lock
99  }
100 
101  public void Commit() {
103  }
104 
105  public void Rollback() {
107  }
108 
109  public IQuery CreateQuery() {
110  return new Query(this);
111  }
112  }
113 }
void Access(IEnumerable< IDbObject > objects, AccessType accessType)
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
Defines a referenced object that can be accessed on a multi-phase level.
Definition: ILargeObject.cs:35
ILargeObject CreateLargeObject(long size, bool compressed)
LockingMode
The mode applied to a lock over a resource during a transaction.
Definition: LockingMode.cs:24
void Commit()
Commits all write operation done during the lifetime of this transaction and invalidates it...
Definition: Transaction.cs:179
IEnumerable< KeyValuePair< string, object > > GetMetaData()
void Exit(IEnumerable< IDbObject > objects, AccessType accessType)
ILargeObject GetLargeObject(ObjectId objId)
void Commit()
Commits the latest changes made by the user in the session.
IEventSource ParentSource
Gets an optional parent source.
Definition: IEventSource.cs:49
void Rollback()
Rollback any write operations done during the lifetime of this transaction and invalidates it...
Definition: Transaction.cs:239
IEnumerable< KeyValuePair< string, object > > Metadata
Gets the list of metadata associated to the source.
Definition: IEventSource.cs:57
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
static readonly User System
Definition: User.cs:28
void Lock(IEnumerable< IDbObject > objects, AccessType accessType, LockingMode mode)
new ITransactionContext Context
Definition: ITransaction.cs:31
A unique identifier of an object within a database system, that is composed by a reference to the sto...
Definition: ObjectId.cs:31
SystemSession(ITransaction transaction)
The simplest implementation of a transaction.
Definition: ITransaction.cs:30
void Rollback()
Rolls-back all the modifications made by the user in this session
Provides the information for a user in a database system
Definition: User.cs:27
SystemSession(ITransaction transaction, string currentSchema)
const string SystemName
The name of the SYSTEM special user.
Definition: User.cs:52
Represents the origin of system events, providing a mechanism to fill the metadata before dispatching...
Definition: IEventSource.cs:40