18 using System.Collections.Generic;
27 namespace Deveel.Data.Sql.Views {
33 if (transaction == null)
34 throw new ArgumentNullException(
"transaction");
37 viewCache =
new Dictionary<long, ViewInfo>();
47 if (viewTableChanged) {
48 InvalidateViewCache();
49 viewTableChanged =
false;
54 InvalidateViewCache();
66 GC.SuppressFinalize(
this);
80 var schemav = table.GetResolvedColumnName(0);
81 var namev = table.GetResolvedColumnName(1);
84 using (var query =session.CreateQuery()) {
87 t = t.ExhaustiveSelect(query,
92 throw new ArgumentException(
String.Format(
"Multiple view entries for name '{0}' in the system.", viewName));
114 if (viewInfo == null)
115 throw new ArgumentException();
117 DefineView(viewInfo);
121 return ViewExists(objName);
125 return ViewExists(objName);
129 return GetView(objName);
133 throw new NotSupportedException();
137 return DropView(objName);
141 throw new NotImplementedException();
145 if (viewInfo == null)
146 throw new ArgumentNullException(
"viewInfo");
151 var viewName = dataTableInfo.TableName;
153 var viewInfoData = viewInfo.
AsBinary();
156 var rdat = viewTable.NewRow();
157 rdat.SetValue(0, dataTableInfo.SchemaName.Name);
158 rdat.SetValue(1, dataTableInfo.Name);
159 rdat.SetValue(2, query.ToString());
163 var t = FindViewEntry(viewName);
166 if (t.RowCount == 1) {
171 viewTable.AddRow(rdat);
177 viewTableChanged =
true;
182 var e = viewTable.GetEnumerator();
183 while (e.MoveNext()) {
184 int row = e.Current.RowId.RowNumber;
186 var cSchema = viewTable.GetValue(row, 0).Value.ToString();
187 var cName = viewTable.GetValue(row, 1).Value.ToString();
190 viewName.
Name.Equals(cName)) {
193 if (!viewCache.TryGetValue(row, out viewInfo)) {
194 var blob = (
SqlBinary)viewTable.GetValue(row, 3).Value;
196 using (var context = session.CreateQuery()) {
202 viewCache[row] = viewInfo;
206 return new View(viewInfo);
215 return FindViewEntry(viewName).RowCount > 0;
221 var t = FindViewEntry(viewName);
231 viewTableChanged =
true;
245 var e = table.GetEnumerator();
247 while (e.MoveNext()) {
248 var row = e.Current.RowId.RowNumber;
252 if (!viewCache.TryGetValue(row, out viewInfo)) {
253 var binary = (
ISqlBinary)table.GetValue(row, 3).Value;
256 using (var context = session.CreateQuery()) {
261 viewCache[row] = viewInfo;
264 return new View(viewInfo);
270 throw new ArgumentOutOfRangeException(
"offset");
273 #region ViewTableContainer
280 this.viewManager = viewManager;
284 var view = viewManager.GetViewAt(offset);
296 throw new NotSupportedException();
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
View GetView(ObjectName viewName)
IEnumerable< int > AddedRows
void InvalidateViewCache()
bool AlterObject(IObjectInfo objInfo)
Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specif...
bool DropObject(ObjectName objName)
Deletes a database object handled by this manager from the system.
Defines the contract to access the data contained into a table of a database.
static DataObject Binary(SqlBinary binary)
override ITable GetTable(int offset)
Gets the table contained at the given offset within the context.
override string GetTableType(int offset)
Gets the type of the table at the given offset.
A long string in the system.
ViewTableContainer(ViewManager viewManager)
TableInfo(ObjectName tableName)
Constructs the object with the given table name.
The system implementation of a transaction model that handles isolated operations within a database c...
readonly ViewManager viewManager
bool RealObjectExists(ObjectName objName)
Checks if an object really exists in the system.
void Dispose(bool disposing)
void Create()
Initializes the manager into the underlying system.
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Represents a database object, such as a table, a trigger, a type or a column.
An event fired when a database object of the given type is created during the lifetime of a transacti...
void OnCommit(TableCommitInfo obj)
static BinaryType Binary(int maxSize)
static ViewInfo Deserialize(Stream stream)
void RegisterEvent(ITransactionEvent e)
static SqlBinaryExpression Equal(SqlExpression left, SqlExpression right)
View GetViewAt(int offset)
Describes the name of an object within a database.
Exception thrown where various problems occur within the database.
static DataObject String(string s)
ITableContainer CreateInternalTableInfo()
SqlExpressionType
All the possible type of SqlExpression supported
IEnumerable< int > RemovedRows
override TableInfo GetTableInfo(int offset)
Gets the information of the table at the given offset in this container.
ObjectName ResolveName(ObjectName objName, bool ignoreCase)
Normalizes the input object name using the case sensitivity specified.
ViewManager(ITransaction transaction)
void CreateObject(IObjectInfo objInfo)
Create a new object of the ObjectType given the specifications given.
TransactionRegistry Registry
static readonly ObjectName ViewTableName
Provides the constant names of the types of tables in a database system.
void RegisterOnCommit(Action< TableCommitInfo > action)
bool ViewExists(ObjectName viewName)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
A container for any system tables that are generated from information inside the database engine...
bool DropView(ObjectName viewName)
Provides utilities and properties for handling the SYSTEN schema of a database.
DbObjectType ObjectType
Gets the type of objects managed by this instance.
string Name
Gets the name of the object being referenced.
static SqlReferenceExpression Reference(ObjectName objectName)
static StringType String()
ITable FindViewEntry(ObjectName viewName)
void DefineView(ViewInfo viewInfo)
IDbObject GetObject(ObjectName objName)
Gets a database object managed by this manager.
bool ObjectExists(ObjectName objName)
Checks if an object identified by the given name is managed by this instance.
Defines the base class for instances that represent SQL expression tree nodes.
Defines the contract for the business managers of database objects of a given type.
const string Name
The name of the system schema that contains tables referring to system information.
static SqlConstantExpression Constant(object value)
The simplest implementation of a transaction.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Defines the required contract of a SQL BINARY object
Defines the metadata properties of a table existing within a database.
Dictionary< long, ViewInfo > viewCache
SqlQueryExpression QueryExpression