private static bool Exists(this OracleConnection connection, DbName objectName) { using (var command = connection.CreateCommand()) { if (objectName.Owner == null) { command.CommandText = "select 1 from user_objects where object_name = upper(:name)"; command.Parameters.Add("name", objectName.Name); } else { command.CommandText = "select 1 from all_objects where owner = upper(:owner) and object_name = upper(:name)"; command.Parameters.Add("owner", objectName.Owner); command.Parameters.Add("name", objectName.Name); } return(command.ExecuteScalar() != null); } }
private static bool CreateIfNotExists(this OracleConnection connection, DbName tableName, Func <DbName, string[]> ddl) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } if (connection.Exists(tableName)) { return(false); } try { using (var command = connection.CreateCommand()) { foreach (var sql in ddl(tableName)) { command.CommandText = sql; command.ExecuteNonQuery(); } } } catch { // We might fail if another process created the same objects concurrently if (connection.Exists(tableName)) { return(false); } // Otherwise propagate the error throw; } return(true); }
/// <summary>Create objects supporting DataBus.</summary> public static bool CreateRebusDataBus(this OracleConnection connection, DbName tableName) => connection.CreateIfNotExists(tableName, DDL.dataBus);
/// <summary>Create objects supporting Sagas Snapshots.</summary> public static bool CreateRebusSagaSnapshot(this OracleConnection connection, DbName tableName) => connection.CreateIfNotExists(tableName, DDL.sagaSnapshot);
/// <summary>Create objects supporting Sagas.</summary> public static bool CreateRebusSaga(this OracleConnection connection, DbName dataTableName, DbName indexTableName) { return(connection.CreateIfNotExists(dataTableName, DDL.sagaData) | connection.CreateIfNotExists(indexTableName, DDL.sagaIndex)); }
/// <summary>Create objects supporting Subscriptions.</summary> public static bool CreateRebusSubscription(this OracleConnection connection, DbName tableName) => connection.CreateIfNotExists(tableName, DDL.subscription);
/// <summary>Create objects supporting Timeouts.</summary> public static bool CreateRebusTimeout(this OracleConnection connection, DbName tableName) => connection.CreateIfNotExists(tableName, DDL.timeout);