DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
UserSessionExtensions.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.Sql;
22 using Deveel.Data.Sql.Tables;
24 
25 namespace Deveel.Data {
26  static class UserSessionExtensions {
27  #region Variables
28 
29  public static bool AutoCommit(this ISession session) {
30  return session.Transaction.AutoCommit();
31  }
32 
33  public static void AutoCommit(this ISession session, bool value) {
34  session.Transaction.AutoCommit(value);
35  }
36 
37  public static void CurrentSchema(this ISession session, string value) {
38  session.Transaction.CurrentSchema(value);
39  }
40 
41  public static string CurrentSchema(this ISession session) {
42  return session.Transaction.CurrentSchema();
43  }
44 
45  public static bool IgnoreIdentifiersCase(this ISession session) {
46  return session.Transaction.IgnoreIdentifiersCase();
47  }
48 
49  public static void IgnoreIdentifiersCase(this ISession session, bool value) {
50  session.Transaction.IgnoreIdentifiersCase(value);
51  }
52 
53  public static QueryParameterStyle ParameterStyle(this ISession session) {
54  return session.Transaction.ParameterStyle();
55  }
56 
57  public static void ParameterStyle(this ISession session, QueryParameterStyle value) {
58  session.Transaction.ParameterStyle(value);
59  }
60 
61  #endregion
62 
63  #region Objects
64 
65  public static IDbObject GetObject(this ISession session, DbObjectType objectType, ObjectName objectName) {
66  return GetObject(session, objectType, objectName, AccessType.ReadWrite);
67  }
68 
69  public static IDbObject GetObject(this ISession session, DbObjectType objectType, ObjectName objectName, AccessType accessType) {
70  var obj = session.Transaction.GetObject(objectType, objectName);
71  if (obj != null)
72  session.Access(obj, accessType);
73 
74  return obj;
75  }
76 
77  public static void CreateObject(this ISession session, IObjectInfo objectInfo) {
78  session.Transaction.CreateObject(objectInfo);
79  }
80 
81  public static void AlterObject(this ISession session, IObjectInfo objectInfo) {
82  session.Transaction.AlterObject(objectInfo);
83  }
84 
85  public static bool ObjectExists(this ISession session, ObjectName objectName) {
86  return session.Transaction.ObjectExists(objectName);
87  }
88 
89  public static bool ObjectExists(this ISession session, DbObjectType objectType, ObjectName objectName) {
90  return session.Transaction.ObjectExists(objectType, objectName);
91  }
92 
93  public static IDbObject FindObject(this ISession session, ObjectName objectName) {
94  return session.Transaction.FindObject(objectName);
95  }
96 
97  public static void DropObject(this ISession session, DbObjectType objectType, ObjectName objectName) {
98  session.Transaction.DropObject(objectType, objectName);
99  }
100 
101  public static ObjectName ResolveObjectName(this ISession session, string name) {
102  return session.ResolveObjectName(new ObjectName(new ObjectName(session.CurrentSchema), name));
103  }
104 
105  public static ObjectName ResolveObjectName(this ISession session, DbObjectType objectType, ObjectName objectName) {
106  return session.Transaction.ResolveObjectName(objectType, objectName);
107  }
108 
109  public static ObjectName ResolveObjectName(this ISession session, ObjectName objectName) {
110  return session.Transaction.ResolveObjectName(objectName);
111  }
112 
113  #endregion
114 
115  #region Tables
116 
117 
118  public static ObjectName ResolveTableName(this ISession session, ObjectName tableName) {
119  return session.Transaction.ResolveTableName(tableName);
120  }
121 
122  public static ITable GetTable(this ISession session, ObjectName tableName) {
123  tableName = session.ResolveTableName(tableName);
124  return session.GetObject(DbObjectType.Table, tableName) as ITable;
125  }
126 
127  public static TableInfo GetTableInfo(this ISession session, ObjectName tableName) {
128  return session.Transaction.GetTableInfo(tableName);
129  }
130 
131  public static string GetTableType(this ISession session, ObjectName tableName) {
132  return session.Transaction.GetTableType(tableName);
133  }
134 
135  public static void CreateTable(this ISession session, TableInfo tableInfo, bool temporary) {
136  session.Transaction.CreateTable(tableInfo, temporary);
137  }
138 
139  #region Constraints
140 
141  public static void AddPrimaryKey(this ISession session, ObjectName tableName, string[] columns, ConstraintDeferrability deferred, string constraintName) {
142  session.Transaction.AddPrimaryKey(tableName, columns, deferred, constraintName);
143  }
144 
145  public static void AddForeignKey(this ISession session, ObjectName table, string[] columns,
146  ObjectName refTable, string[] refColumns,
147  ForeignKeyAction deleteRule, ForeignKeyAction updateRule, ConstraintDeferrability deferred, String constraintName) {
148  session.Transaction.AddForeignKey(table, columns, refTable, refColumns, deleteRule, updateRule, deferred, constraintName);
149  }
150 
151  public static void AddUniqueKey(this ISession session, ObjectName tableName, string[] columns, ConstraintDeferrability deferrability, string constraintName) {
152  session.Transaction.AddUniqueKey(tableName, columns, deferrability, constraintName);
153  }
154 
155  public static void AddCheck(this ISession session, ObjectName tableName, SqlExpression expression, ConstraintDeferrability deferrability,
156  string constraintName) {
157  session.Transaction.AddCheck(tableName, expression, deferrability, constraintName);
158  }
159 
160  public static void DropAllTableConstraints(this ISession session, ObjectName tableName) {
161  session.Transaction.DropAllTableConstraints(tableName);
162  }
163 
164  public static int DropTableConstraint(this ISession session, ObjectName tableName, string constraintName) {
165  return session.Transaction.DropTableConstraint(tableName, constraintName);
166  }
167 
168  public static bool DropTablePrimaryKey(this ISession session, ObjectName tableName, string constraintName) {
169  return session.Transaction.DropTablePrimaryKey(tableName, constraintName);
170  }
171 
172  public static ObjectName[] QueryTablesRelationallyLinkedTo(this ISession session, ObjectName tableName) {
173  return session.Transaction.QueryTablesRelationallyLinkedTo(tableName);
174  }
175 
176  public static ConstraintInfo[] QueryTableCheckExpressions(this ISession session, ObjectName tableName) {
177  return session.Transaction.QueryTableCheckExpressions(tableName);
178  }
179 
180  public static ConstraintInfo QueryTablePrimaryKey(this ISession session, ObjectName tableName) {
181  return session.Transaction.QueryTablePrimaryKey(tableName);
182  }
183 
184  public static ConstraintInfo[] QueryTableUniqueKeys(this ISession session, ObjectName tableName) {
185  return session.Transaction.QueryTableUniqueKeys(tableName);
186  }
187 
188  public static ConstraintInfo[] QueryTableImportedForeignKeys(this ISession session, ObjectName refTableName) {
189  return session.Transaction.QueryTableImportedForeignKeys(refTableName);
190  }
191 
192  public static ConstraintInfo[] QueryTableForeignKeys(this ISession session, ObjectName tableName) {
193  return session.Transaction.QueryTableForeignKeys(tableName);
194  }
195 
196  public static void CheckConstraintViolations(this ISession session, ObjectName tableName) {
197  throw new NotImplementedException();
198  }
199 
200  #endregion
201 
202  #endregion
203 
204  #region Locks
205 
206  public static void Access(this ISession session, IDbObject obj, AccessType accessType) {
207  session.Access(new [] {obj}, accessType);
208  }
209 
210  #endregion
211  }
212 }
static ITable GetTable(this ISession session, ObjectName tableName)
static ObjectName ResolveObjectName(this ISession session, ObjectName objectName)
static void DropObject(this ISession session, DbObjectType objectType, ObjectName objectName)
static void CreateObject(this ISession session, IObjectInfo objectInfo)
static ConstraintInfo QueryTablePrimaryKey(this ISession session, ObjectName tableName)
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
static void AddCheck(this ISession session, ObjectName tableName, SqlExpression expression, ConstraintDeferrability deferrability, string constraintName)
static void AutoCommit(this ISession session, bool value)
static void CurrentSchema(this ISession session, string value)
static string CurrentSchema(this ISession session)
static IDbObject GetObject(this ISession session, DbObjectType objectType, ObjectName objectName, AccessType accessType)
static bool IgnoreIdentifiersCase(this ISession session)
Represents a database object, such as a table, a trigger, a type or a column.
Definition: IDbObject.cs:24
static ObjectName[] QueryTablesRelationallyLinkedTo(this ISession session, ObjectName tableName)
static bool ObjectExists(this ISession session, ObjectName objectName)
static void CreateTable(this ISession session, TableInfo tableInfo, bool temporary)
static ConstraintInfo[] QueryTableUniqueKeys(this ISession session, ObjectName tableName)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
ITransaction Transaction
Gets the instance of ITransaction that handles the transactional operations of this session...
Definition: ISession.cs:46
ConstraintDeferrability
The type of deferrance of a constraint.
static bool AutoCommit(this ISession session)
static string GetTableType(this ISession session, ObjectName tableName)
static void AddForeignKey(this ISession session, ObjectName table, string[] columns, ObjectName refTable, string[] refColumns, ForeignKeyAction deleteRule, ForeignKeyAction updateRule, ConstraintDeferrability deferred, String constraintName)
void Access(IEnumerable< IDbObject > objects, AccessType accessType)
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
static void AlterObject(this ISession session, IObjectInfo objectInfo)
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
static void Access(this ISession session, IDbObject obj, AccessType accessType)
string CurrentSchema
Gets the name of the current schema of this session.
Definition: ISession.cs:34
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
static void ParameterStyle(this ISession session, QueryParameterStyle value)
static IDbObject FindObject(this ISession session, ObjectName objectName)
static TableInfo GetTableInfo(this ISession session, ObjectName tableName)
static ConstraintInfo[] QueryTableCheckExpressions(this ISession session, ObjectName tableName)
static ObjectName ResolveObjectName(this ISession session, string name)
static ObjectName ResolveObjectName(this ISession session, DbObjectType objectType, ObjectName objectName)
static ConstraintInfo[] QueryTableForeignKeys(this ISession session, ObjectName tableName)
static void IgnoreIdentifiersCase(this ISession session, bool value)
static void AddUniqueKey(this ISession session, ObjectName tableName, string[] columns, ConstraintDeferrability deferrability, string constraintName)
static int DropTableConstraint(this ISession session, ObjectName tableName, string constraintName)
Defines the base class for instances that represent SQL expression tree nodes.
static IDbObject GetObject(this ISession session, DbObjectType objectType, ObjectName objectName)
static QueryParameterStyle ParameterStyle(this ISession session)
static bool DropTablePrimaryKey(this ISession session, ObjectName tableName, string constraintName)
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static ObjectName ResolveTableName(this ISession session, ObjectName tableName)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
static ConstraintInfo[] QueryTableImportedForeignKeys(this ISession session, ObjectName refTableName)
static bool ObjectExists(this ISession session, DbObjectType objectType, ObjectName objectName)
static void DropAllTableConstraints(this ISession session, ObjectName tableName)
static void CheckConstraintViolations(this ISession session, ObjectName tableName)
static void AddPrimaryKey(this ISession session, ObjectName tableName, string[] columns, ConstraintDeferrability deferred, string constraintName)