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 
19 using Deveel.Data;
20 using Deveel.Data.Sql.Tables;
21 
22 namespace Deveel.Data.Sql.Query {
23  static class UserSessionExtensions {
24  public static ITableQueryInfo GetTableQueryInfo(this ISession session, ObjectName tableName, ObjectName alias) {
25  var tableInfo = session.GetTableInfo(tableName);
26  if (alias != null) {
27  tableInfo = tableInfo.Alias(alias);
28  }
29 
30  return new TableQueryInfo(session, tableInfo, tableName, alias);
31  }
32 
33  public static IQueryPlanNode CreateQueryPlan(this ISession session, ObjectName tableName, ObjectName aliasedName) {
34  string tableType = session.GetTableType(tableName);
35  if (tableType.Equals(TableTypes.View))
36  return new FetchViewNode(tableName, aliasedName);
37 
38  return new FetchTableNode(tableName, aliasedName);
39  }
40 
41  #region TableQueryInfo
42 
44  public TableQueryInfo(ISession session, TableInfo tableInfo, ObjectName tableName, ObjectName aliasName) {
45  Session = session;
46  TableInfo = tableInfo;
47  TableName = tableName;
48  AliasName = aliasName;
49  }
50 
51  public ISession Session { get; private set; }
52 
53  public TableInfo TableInfo { get; private set; }
54 
55  public ObjectName TableName { get; set; }
56 
57  public ObjectName AliasName { get; set; }
58 
59  public IQueryPlanNode QueryPlanNode {
60  get { return Session.CreateQueryPlan(TableName, AliasName); }
61  }
62  }
63 
64  #endregion
65 
66  }
67 }
const string View
Definition: TableTypes.cs:27
Describes the name of an object within a database.
Definition: ObjectName.cs:44
A node element of a query plan tree. /summary>
This is a session that is constructed around a given user and a transaction, to the given database...
Definition: Session.cs:32
static IQueryPlanNode CreateQueryPlan(this ISession session, ObjectName tableName, ObjectName aliasedName)
An isolated session to a given database for a given user, encapsulating the transaction for operation...
Definition: ISession.cs:30
Provides the constant names of the types of tables in a database system.
Definition: TableTypes.cs:24
static ITableQueryInfo GetTableQueryInfo(this ISession session, ObjectName tableName, ObjectName alias)
TableQueryInfo(ISession session, TableInfo tableInfo, ObjectName tableName, ObjectName aliasName)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
The node for fetching a table from the current transaction.