DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Sql.Views.ViewManager Class Reference
Inheritance diagram for Deveel.Data.Sql.Views.ViewManager:
Deveel.Data.Sql.IObjectManager

Classes

class  ViewTableContainer
 

Public Member Functions

 ViewManager (ITransaction transaction)
 
void Dispose ()
 
void Create ()
 Initializes the manager into the underlying system. More...
 
ObjectName ResolveName (ObjectName objName, bool ignoreCase)
 Normalizes the input object name using the case sensitivity specified. More...
 
void DefineView (ViewInfo viewInfo)
 
View GetView (ObjectName viewName)
 
bool ViewExists (ObjectName viewName)
 
bool DropView (ObjectName viewName)
 
ITableContainer CreateInternalTableInfo ()
 

Properties

ITransaction Transaction [get, private set]
 
DbObjectType IObjectManager. ObjectType [get]
 
- Properties inherited from Deveel.Data.Sql.IObjectManager
DbObjectType ObjectType [get]
 Gets the type of objects managed by this instance. More...
 

Private Member Functions

void OnCommit (TableCommitInfo obj)
 
void InvalidateViewCache ()
 
void Dispose (bool disposing)
 
ITable FindViewEntry (ObjectName viewName)
 
void IObjectManager. CreateObject (IObjectInfo objInfo)
 Create a new object of the ObjectType given the specifications given. More...
 
bool IObjectManager. RealObjectExists (ObjectName objName)
 Checks if an object really exists in the system. More...
 
bool IObjectManager. ObjectExists (ObjectName objName)
 Checks if an object identified by the given name is managed by this instance. More...
 
IDbObject IObjectManager. GetObject (ObjectName objName)
 Gets a database object managed by this manager. More...
 
bool IObjectManager. AlterObject (IObjectInfo objInfo)
 Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given. More...
 
bool IObjectManager. DropObject (ObjectName objName)
 Deletes a database object handled by this manager from the system. More...
 
View GetViewAt (int offset)
 

Private Attributes

Dictionary< long, ViewInfoviewCache
 
bool viewTableChanged
 

Detailed Description

Definition at line 28 of file ViewManager.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Views.ViewManager.ViewManager ( ITransaction  transaction)
inline

Definition at line 32 of file ViewManager.cs.

32  {
33  if (transaction == null)
34  throw new ArgumentNullException("transaction");
35 
36  Transaction = transaction;
37  viewCache = new Dictionary<long, ViewInfo>();
38 
39  transaction.RegisterOnCommit(OnCommit);
40  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
void OnCommit(TableCommitInfo obj)
Definition: ViewManager.cs:42
void RegisterOnCommit(Action< TableCommitInfo > action)
Dictionary< long, ViewInfo > viewCache
Definition: ViewManager.cs:29

Member Function Documentation

bool IObjectManager. Deveel.Data.Sql.Views.ViewManager.AlterObject ( IObjectInfo  objInfo)
inlineprivate

Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given.

Parameters
objInfoThe object specification used to alter an existing object.
Returns
Returns true an object was identified and successfully altered, or false if none database object was found for the unique name given.
Exceptions
ArgumentNullExceptionIf the given objInfo object is null.
ArgumentExceptionIf the type of the object specified (IObjectInfo.ObjectType) is different than the type of objects handled by this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 132 of file ViewManager.cs.

132  {
133  throw new NotSupportedException();
134  }
void Deveel.Data.Sql.Views.ViewManager.Create ( )
inline

Initializes the manager into the underlying system.

Typically this method generates the tables required to manage the features relative to the objects.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 100 of file ViewManager.cs.

100  {
101  var tableInfo = new TableInfo(SystemSchema.ViewTableName);
102  tableInfo.AddColumn("schema", PrimitiveTypes.String());
103  tableInfo.AddColumn("name", PrimitiveTypes.String());
104  tableInfo.AddColumn("query", PrimitiveTypes.String());
105  tableInfo.AddColumn("plan", PrimitiveTypes.Binary());
106 
107  // TODO: Columns...
108 
109  Transaction.CreateTable(tableInfo);
110  }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
static BinaryType Binary(int maxSize)
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
ITableContainer Deveel.Data.Sql.Views.ViewManager.CreateInternalTableInfo ( )
inline

Definition at line 236 of file ViewManager.cs.

236  {
237  return new ViewTableContainer(this);
238  }
void IObjectManager. Deveel.Data.Sql.Views.ViewManager.CreateObject ( IObjectInfo  objInfo)
inlineprivate

Create a new object of the ObjectType given the specifications given.

Parameters
objInfoThe object specifications used to create a new object.
Exceptions
ArgumentNullExceptionIf the given objInfo is null.
ArgumentExceptionIf the object type of the specification (IObjectInfo.ObjectType) is different than the ObjectType of this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 112 of file ViewManager.cs.

112  {
113  var viewInfo = objInfo as ViewInfo;
114  if (viewInfo == null)
115  throw new ArgumentException();
116 
117  DefineView(viewInfo);
118  }
void DefineView(ViewInfo viewInfo)
Definition: ViewManager.cs:144
void Deveel.Data.Sql.Views.ViewManager.DefineView ( ViewInfo  viewInfo)
inline

Definition at line 144 of file ViewManager.cs.

144  {
145  if (viewInfo == null)
146  throw new ArgumentNullException("viewInfo");
147 
148  var dataTableInfo = viewInfo.TableInfo;
149  var viewTable = Transaction.GetMutableTable(SystemSchema.ViewTableName);
150 
151  var viewName = dataTableInfo.TableName;
152  var query = viewInfo.QueryExpression;
153  var viewInfoData = viewInfo.AsBinary();
154 
155  // Create the view record
156  var rdat = viewTable.NewRow();
157  rdat.SetValue(0, dataTableInfo.SchemaName.Name);
158  rdat.SetValue(1, dataTableInfo.Name);
159  rdat.SetValue(2, query.ToString());
160  rdat.SetValue(3, DataObject.Binary(viewInfoData));
161 
162  // Find the entry from the view that equals this name
163  var t = FindViewEntry(viewName);
164 
165  // Delete the entry if it already exists.
166  if (t.RowCount == 1) {
167  viewTable.Delete(t);
168  }
169 
170  // Insert the new view entry in the system view table
171  viewTable.AddRow(rdat);
172 
173  // Notify that this database object has been successfully created.
175 
176  // Change to the view table
177  viewTableChanged = true;
178  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
An event fired when a database object of the given type is created during the lifetime of a transacti...
ITable FindViewEntry(ObjectName viewName)
Definition: ViewManager.cs:77
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
void Deveel.Data.Sql.Views.ViewManager.Dispose ( )
inline

Definition at line 64 of file ViewManager.cs.

64  {
65  Dispose(true);
66  GC.SuppressFinalize(this);
67  }
void Deveel.Data.Sql.Views.ViewManager.Dispose ( bool  disposing)
inlineprivate

Definition at line 69 of file ViewManager.cs.

69  {
70  Transaction = null;
71  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
bool IObjectManager. Deveel.Data.Sql.Views.ViewManager.DropObject ( ObjectName  objName)
inlineprivate

Deletes a database object handled by this manager from the system.

Parameters
objNameThe unique name of the object to be deleted.
Returns
Returns true if a database object was found with the given unique name and successfully deleted from the system, or false if none object was found.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 136 of file ViewManager.cs.

136  {
137  return DropView(objName);
138  }
bool DropView(ObjectName viewName)
Definition: ViewManager.cs:218
bool Deveel.Data.Sql.Views.ViewManager.DropView ( ObjectName  viewName)
inline

Definition at line 218 of file ViewManager.cs.

218  {
219  var table = Transaction.GetMutableTable(SystemSchema.ViewTableName);
220 
221  var t = FindViewEntry(viewName);
222 
223  if (t.RowCount == 0)
224  return false;
225 
226  table.Delete(t);
227 
228  // Notify that this database object has been successfully dropped.
230 
231  viewTableChanged = true;
232 
233  return true;
234  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ITable FindViewEntry(ObjectName viewName)
Definition: ViewManager.cs:77
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
ITable Deveel.Data.Sql.Views.ViewManager.FindViewEntry ( ObjectName  viewName)
inlineprivate

Definition at line 77 of file ViewManager.cs.

77  {
78  var table = Transaction.GetTable(SystemSchema.ViewTableName);
79 
80  var schemav = table.GetResolvedColumnName(0);
81  var namev = table.GetResolvedColumnName(1);
82 
83  using (var session = new SystemSession(Transaction, SystemSchema.Name)) {
84  using (var query =session.CreateQuery()) {
85  var t = table.SimpleSelect(query, namev, SqlExpressionType.Equal,
86  SqlExpression.Constant(DataObject.String(viewName.Name)));
87  t = t.ExhaustiveSelect(query,
88  SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(viewName.ParentName)));
89 
90  // This should be at most 1 row in size
91  if (t.RowCount > 1)
92  throw new ArgumentException(String.Format("Multiple view entries for name '{0}' in the system.", viewName));
93 
94  // Return the entries found.
95  return t;
96  }
97  }
98  }
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
static SqlBinaryExpression Equal(SqlExpression left, SqlExpression right)
SqlExpressionType
All the possible type of SqlExpression supported
static SqlReferenceExpression Reference(ObjectName objectName)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
IDbObject IObjectManager. Deveel.Data.Sql.Views.ViewManager.GetObject ( ObjectName  objName)
inlineprivate

Gets a database object managed by this manager.

Parameters
objNameThe name that uniquely identifies the object to get.
Returns
Returns a IDbObject instance that is identified by the given unique name, or null if this manager was not able to map any object to the name specified.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 128 of file ViewManager.cs.

128  {
129  return GetView(objName);
130  }
View GetView(ObjectName viewName)
Definition: ViewManager.cs:180
View Deveel.Data.Sql.Views.ViewManager.GetView ( ObjectName  viewName)
inline

Definition at line 180 of file ViewManager.cs.

180  {
181  var viewTable = Transaction.GetTable(SystemSchema.ViewTableName);
182  var e = viewTable.GetEnumerator();
183  while (e.MoveNext()) {
184  int row = e.Current.RowId.RowNumber;
185 
186  var cSchema = viewTable.GetValue(row, 0).Value.ToString();
187  var cName = viewTable.GetValue(row, 1).Value.ToString();
188 
189  if (viewName.ParentName.Equals(cSchema) &&
190  viewName.Name.Equals(cName)) {
191 
192  ViewInfo viewInfo;
193  if (!viewCache.TryGetValue(row, out viewInfo)) {
194  var blob = (SqlBinary)viewTable.GetValue(row, 3).Value;
195  using (var session = new SystemSession(Transaction, SystemSchema.Name)) {
196  using (var context = session.CreateQuery()) {
197 
198  viewInfo = ViewInfo.Deserialize(blob.GetInput());
199  }
200  }
201 
202  viewCache[row] = viewInfo;
203 
204  }
205 
206  return new View(viewInfo);
207  }
208 
209  }
210 
211  return null;
212  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
A VIEW object obtained by a source query.
Dictionary< long, ViewInfo > viewCache
Definition: ViewManager.cs:29
View Deveel.Data.Sql.Views.ViewManager.GetViewAt ( int  offset)
inlineprivate

Definition at line 240 of file ViewManager.cs.

240  {
241  var table = Transaction.GetTable(SystemSchema.ViewTableName);
242  if (table == null)
243  throw new DatabaseSystemException(String.Format("System table '{0}' was not defined.", SystemSchema.ViewTableName));
244 
245  var e = table.GetEnumerator();
246  int i = 0;
247  while (e.MoveNext()) {
248  var row = e.Current.RowId.RowNumber;
249 
250  if (i == offset) {
251  ViewInfo viewInfo;
252  if (!viewCache.TryGetValue(row, out viewInfo)) {
253  var binary = (ISqlBinary)table.GetValue(row, 3).Value;
254 
255  using (var session = new SystemSession(Transaction, SystemSchema.Name)) {
256  using (var context = session.CreateQuery()) {
257  viewInfo = ViewInfo.Deserialize(binary.GetInput());
258  }
259  }
260 
261  viewCache[row] = viewInfo;
262  }
263 
264  return new View(viewInfo);
265  }
266 
267  ++i;
268  }
269 
270  throw new ArgumentOutOfRangeException("offset");
271  }
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
A VIEW object obtained by a source query.
Defines the required contract of a SQL BINARY object
Definition: ISqlBinary.cs:25
Dictionary< long, ViewInfo > viewCache
Definition: ViewManager.cs:29
void Deveel.Data.Sql.Views.ViewManager.InvalidateViewCache ( )
inlineprivate

Definition at line 58 of file ViewManager.cs.

58  {
59  viewCache.Clear();
60  }
Dictionary< long, ViewInfo > viewCache
Definition: ViewManager.cs:29
bool IObjectManager. Deveel.Data.Sql.Views.ViewManager.ObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object identified by the given name is managed by this instance.

Parameters
objNameThe name that uniquely identifies the object.
Returns

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 124 of file ViewManager.cs.

124  {
125  return ViewExists(objName);
126  }
bool ViewExists(ObjectName viewName)
Definition: ViewManager.cs:214
void Deveel.Data.Sql.Views.ViewManager.OnCommit ( TableCommitInfo  obj)
inlineprivate

Definition at line 42 of file ViewManager.cs.

42  {
43  if (!obj.TableName.Equals(SystemSchema.ViewTableName))
44  return;
45 
46  // If there were changed then invalidate the cache
47  if (viewTableChanged) {
49  viewTableChanged = false;
50  } else if ((obj.AddedRows != null && obj.AddedRows.Any()) ||
51  (obj.RemovedRows != null && obj.RemovedRows.Any())) {
52  // Otherwise, if there were committed added or removed changes also
53  // invalidate the cache,
55  }
56  }
bool IObjectManager. Deveel.Data.Sql.Views.ViewManager.RealObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object really exists in the system.

Parameters
objNameThe unique name of the object to check.
Returns
Returns true if an object with the given name concretely exists in the system, or false otherwise.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 120 of file ViewManager.cs.

120  {
121  return ViewExists(objName);
122  }
bool ViewExists(ObjectName viewName)
Definition: ViewManager.cs:214
ObjectName Deveel.Data.Sql.Views.ViewManager.ResolveName ( ObjectName  objName,
bool  ignoreCase 
)
inline

Normalizes the input object name using the case sensitivity specified.

Parameters
objNameThe input object name, that can be partial or complete, to be normalized to the real name of an object.
ignoreCaseThe case sensitivity specification used to compare the input name with the names of the existing objects handled by this manager.
Returns
Returns the fully normalized ObjectName that is the real name of an object matching the input name, or null if the input name was not possible to be resolved.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 140 of file ViewManager.cs.

140  {
141  throw new NotImplementedException();
142  }
bool Deveel.Data.Sql.Views.ViewManager.ViewExists ( ObjectName  viewName)
inline

Definition at line 214 of file ViewManager.cs.

214  {
215  return FindViewEntry(viewName).RowCount > 0;
216  }
int RowCount
Gets the total number of rows in the table.
Definition: ITable.cs:52
ITable FindViewEntry(ObjectName viewName)
Definition: ViewManager.cs:77

Member Data Documentation

Dictionary<long, ViewInfo> Deveel.Data.Sql.Views.ViewManager.viewCache
private

Definition at line 29 of file ViewManager.cs.

bool Deveel.Data.Sql.Views.ViewManager.viewTableChanged
private

Definition at line 30 of file ViewManager.cs.

Property Documentation

DbObjectType IObjectManager. Deveel.Data.Sql.Views.ViewManager.ObjectType
getprivate

Definition at line 73 of file ViewManager.cs.

ITransaction Deveel.Data.Sql.Views.ViewManager.Transaction
getprivate set

Definition at line 62 of file ViewManager.cs.


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