18 using System.Collections.Generic;
19 using System.Globalization;
35 namespace Deveel.Data.Transactions {
41 if (transaction.ReadOnly())
49 foreach (var manager
in managers) {
75 return transaction.GetObjectManagers()
76 .Select(manager => manager.GetObject(objName))
77 .FirstOrDefault(obj => obj != null);
81 var manager = transaction.GetObjectManager(objType);
85 return manager.GetObject(objName);
89 return transaction.GetObjectManagers()
90 .Any(manager => manager.ObjectExists(objName));
94 var manager = transaction.GetObjectManager(objType);
98 return manager.ObjectExists(objName);
102 var manager = transaction.GetObjectManager(objType);
106 return manager.RealObjectExists(objName);
111 throw new ArgumentNullException(
"objInfo");
113 var manager = transaction.GetObjectManager(objInfo.
ObjectType);
115 throw new InvalidOperationException(
String.Format(
"Could not find any manager for object type '{0}' configured for the system.", objInfo.
ObjectType));
118 throw new ArgumentException(
119 String.Format(
"Could not create an object of type '{0}' with the manager '{1}' (supported '{2}' type)",
120 objInfo.
ObjectType, manager.GetType().FullName, manager.ObjectType));
122 manager.CreateObject(objInfo);
127 throw new ArgumentNullException(
"objInfo");
129 var manager = transaction.GetObjectManager(objInfo.
ObjectType);
131 throw new InvalidOperationException();
134 throw new ArgumentException();
136 return manager.AlterObject(objInfo);
140 var manager = transaction.GetObjectManager(objType);
144 return manager.DropObject(objName);
148 if (
String.IsNullOrEmpty(objectName))
149 throw new ArgumentNullException(
"objectName");
151 if (
String.IsNullOrEmpty(schemaName))
152 schemaName = transaction.CurrentSchema();
157 if (
String.Compare(objectName,
"OLD", StringComparison.OrdinalIgnoreCase) == 0)
159 if (
String.Compare(objectName,
"NEW", StringComparison.OrdinalIgnoreCase) == 0)
164 foreach (var manager in transaction.GetObjectManagers()) {
165 if (manager.ObjectExists(objName)) {
167 throw new ArgumentException(
String.Format(
"The name '{0}' is an ambiguous match.", objectName));
180 return transaction.ResolveObjectName(transaction.CurrentSchema(), objectName);
184 var manager = transaction.GetObjectManager(objectType);
188 return manager.ResolveName(objectName, transaction.IgnoreIdentifiersCase());
192 var ignoreCase = transaction.IgnoreIdentifiersCase();
194 return transaction.GetObjectManagers()
195 .Select(manager => manager.ResolveName(objectName, ignoreCase))
196 .FirstOrDefault(resolved => resolved != null);
204 transaction.CreateObject(schemaInfo);
209 transaction.CreateSystem();
212 var culture = CultureInfo.CurrentCulture.Name;
214 schemaInfo.Culture = culture;
216 transaction.CreateSchema(schemaInfo);
225 var name = tableName.
Name;
227 if (
String.Compare(name,
"OLD", StringComparison.OrdinalIgnoreCase) == 0)
229 if (
String.Compare(name,
"NEW", StringComparison.OrdinalIgnoreCase) == 0)
236 if (tableName == null)
239 if (tableName.
Parent == null)
243 var name = tableName.
Name;
245 if (
String.Compare(name,
"OLD", StringComparison.OrdinalIgnoreCase) == 0)
247 if (
String.Compare(name,
"NEW", StringComparison.OrdinalIgnoreCase) == 0)
250 return transaction.ResolveObjectName(
DbObjectType.Table, tableName);
254 return transaction.ObjectExists(
DbObjectType.Table, ResolveReservedTableName(tableName));
258 return transaction.RealObjectExists(
DbObjectType.Table, objName);
272 tableName = ResolveReservedTableName(tableName);
275 if (tableStateHandler != null) {
279 return tableStateHandler.TableState.NewDataTable;
286 return transaction.GetTableManager().GetVisibleTables();
290 transaction.GetTableManager().RemoveVisibleTable(table);
294 transaction.GetTableManager().UpdateVisibleTable(tableSource, indexSet);
298 return transaction.GetTableManager().GetIndexSetForTable(tableSource);
307 if (tableManager == null)
308 throw new InvalidOperationException(
"No table manager was found.");
310 return tableManager.GetTableInfo(tableName);
314 var tableManager = transaction.GetTableManager();
315 if (tableManager == null)
316 throw new InvalidOperationException(
"No table manager was found.");
318 return tableManager.GetTableType(tableName);
322 CreateTable(transaction, tableInfo,
false);
326 var tableManager = transaction.GetTableManager();
328 tableManager.CreateTemporaryTable(tableInfo);
330 tableManager.CreateTable(tableInfo);
347 transaction.AlterObject(tableInfo);
351 return transaction.DropObject(
DbObjectType.Table, tableName);
370 transaction.AssertNotReadOnly();
372 var tableManager = transaction.GetTableManager();
373 if (tableManager == null)
374 throw new InvalidOperationException();
376 return tableManager.SetUniqueId(tableName, value);
388 transaction.AssertNotReadOnly();
390 var tableManager = transaction.GetTableManager();
391 if (tableManager == null)
392 throw new InvalidOperationException();
394 return tableManager.NextUniqueId(tableName);
402 return transaction.
Context.CurrentSchema();
406 transaction.
Context.CurrentSchema(value);
410 return transaction.
Context.IgnoreIdentifiersCase();
414 transaction.
Context.IgnoreIdentifiersCase(value);
418 return transaction.
Context.AutoCommit();
422 transaction.
Context.AutoCommit(value);
426 return transaction.
Context.ParameterStyle();
430 transaction.
Context.ParameterStyle(value);
434 return transaction.
Context.ReadOnly();
438 transaction.
Context.ReadOnly(value);
442 return transaction.
Context.ErrorOnDirtySelect();
446 transaction.
Context.ErrorOnDirtySelect(value);
454 transaction.CreateObject(sequenceInfo);
462 transaction.DropSequence(tableName);
466 return transaction.DropObject(
DbObjectType.Sequence, sequenceName);
474 var tables = tableNames.Select(transaction.GetTable).OfType<
ILockable>();
475 return transaction.
Database.
Locker.Lock(tables.ToArray(), accessType, mode);
480 if (lockable == null)
static bool AutoCommit(this ITransaction transaction)
static bool DropTable(this ITransaction transaction, ObjectName tableName)
static bool RealObjectExists(this ITransaction transaction, DbObjectType objType, ObjectName objName)
static void CreateSystemSchema(this ITransaction transaction)
static IDbObject FindObject(this ITransaction transaction, ObjectName objName)
Defines the contract to access the data contained into a table of a database.
static void CreateTable(this ITransaction transaction, TableInfo tableInfo)
static void ErrorOnDirtySelect(this ITransaction transaction, bool value)
static bool ErrorOnDirtySelect(this ITransaction transaction)
A long string in the system.
void Create()
Initializes the manager into the underlying system.
static IObjectManager GetObjectManager(this ITransaction transaction, DbObjectType objectType)
static ObjectName ResolveTableName(this ITransaction transaction, ObjectName tableName)
static IEnumerable< IObjectManager > GetObjectManagers(this ITransaction transaction)
LockingMode
The mode applied to a lock over a resource during a transaction.
static void CreateNativeSequence(this ITransaction transaction, ObjectName tableName)
Provides some convenience extension methods to ITransaction instances.
Locker Locker
Gets the objects that is used to lock database objects between transactions.
static void CreateSystem(this ITransaction transaction)
Represents a database object, such as a table, a trigger, a type or a column.
static string GetTableType(this ITransaction transaction, ObjectName tableName)
Describes the name of an object within a database.
static TableInfo GetTableInfo(this ITransaction transaction, ObjectName tableName)
IDatabase Database
Gets the database this transaction belongs to.
static bool ObjectExists(this ITransaction transaction, DbObjectType objType, ObjectName objName)
static bool ReadOnly(this ITransaction transaction)
static void AlterTable(this ITransaction transaction, TableInfo tableInfo)
Alters the table with the given name within this transaction to the specified table definition...
override bool Equals(object obj)
static void RemoveNativeSequence(this ITransaction transaction, ObjectName tableName)
static bool DropSequence(this ITransaction transaction, ObjectName sequenceName)
static void CreateSequence(this ITransaction transaction, SequenceInfo sequenceInfo)
static void CurrentSchema(this ITransaction transaction, string value)
static ObjectName ResolveObjectName(this ITransaction transaction, DbObjectType objectType, ObjectName objectName)
Provides the meta information about a ISequence configuring its operative behavior.
static ObjectName ResolveObjectName(this ITransaction transaction, ObjectName objectName)
static void RemoveVisibleTable(this ITransaction transaction, TableSource table)
static void ReadOnly(this ITransaction transaction, bool value)
static IDbObject GetObject(this ITransaction transaction, DbObjectType objType, ObjectName objName)
static TriggerManager GetTriggerManager(this ITransaction transaction)
static SequenceInfo Native(ObjectName tableName)
Creates an object that describes a native sequence for the table having the specified name...
new ITransactionContext Context
static ObjectName ResolveObjectName(this ITransaction transaction, string objectName)
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
Provides utilities and properties for handling the SYSTEN schema of a database.
static void AutoCommit(this ITransaction transaction, bool value)
static ObjectName ResolveObjectName(this ITransaction transaction, string schemaName, string objectName)
An object that access to a set of indexes.
static void CreateObject(this ITransaction transaction, IObjectInfo objInfo)
static ObjectName ResolveReservedTableName(ObjectName tableName)
static void CreateTable(this ITransaction transaction, TableInfo tableInfo, bool temporary)
static bool ObjectExists(this ITransaction transaction, ObjectName objName)
static QueryParameterStyle ParameterStyle(this ITransaction transaction)
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
static void IgnoreIdentifiersCase(this ITransaction transaction, bool value)
static TableManager GetTableManager(this ITransaction transaction)
static ITable GetTable(this ITransaction transaction, ObjectName tableName)
Tries to get an object with the given name formed as table.
string Name
Gets the name of the object being referenced.
ITable OldDataTable
The tUserContextTable object that represents the OLD table, if set.
static bool AlterObject(this ITransaction transaction, IObjectInfo objInfo)
static void AssertNotReadOnly(this ITransaction transaction)
static bool TableExists(this ITransaction transaction, ObjectName tableName)
static IIndexSet GetIndexSetForTable(this ITransaction transaction, TableSource tableSource)
static SqlNumber NextTableId(this ITransaction transaction, ObjectName tableName)
Gets the next value of a table native sequence.
static IMutableTable GetMutableTable(this ITransaction transaction, ObjectName tableName)
Defines the contract for the business managers of database objects of a given type.
static readonly ObjectName OldTriggerTableName
const string Name
The name of the system schema that contains tables referring to system information.
OldNewTableState TableState
Gets an object that olds the state before and after a table event.
The simplest implementation of a transaction.
static LockHandle LockTables(this ITransaction transaction, IEnumerable< ObjectName > tableNames, AccessType accessType, LockingMode mode)
static IEnumerable< ITableSource > GetVisibleTables(this ITransaction transaction)
DbObjectType
The kind of objects that can be handled by a database system and its managers
static void ParameterStyle(this ITransaction transaction, QueryParameterStyle value)
static void UpdateVisibleTable(this ITransaction transaction, TableSource tableSource, IIndexSet indexSet)
Describes the properties of a schema in a database system.
Defines the metadata properties of a table existing within a database.
static bool RealTableExists(this ITransaction transaction, ObjectName objName)
static bool IsTableLocked(this ITransaction transaction, ITable table)
static bool IgnoreIdentifiersCase(this ITransaction transaction)
static SqlNumber SetTableId(this ITransaction transaction, ObjectName tableName, SqlNumber value)
Sets the current value of a table native sequence.
static void CreateSchema(this ITransaction transaction, SchemaInfo schemaInfo)
An interface that defines contracts to alter the contents of a table.
static bool DropObject(this ITransaction transaction, DbObjectType objType, ObjectName objName)
static string CurrentSchema(this ITransaction transaction)
static readonly ObjectName NewTriggerTableName