public int CheckOutAndGetSeed(IStructureSchema structureSchema, int numOfIds) { using(var dbClient = new SqlDbClient(_connectionInfo, false)) { return dbClient.GetIdentity(structureSchema.Hash, numOfIds); } }
public override void InitializeExisting() { using (var client = new SqlDbClient(ConnectionInfo, false)) { if (!client.DatabaseExists(Name)) throw new SisoDbException(ExceptionMessages.SqlDatabase_InitializeExisting_DbDoesNotExist.Inject(Name)); client.CreateSysTables(Name); } }
public SqlDbSchemaUpserter(SqlDbClient dbClient) { _dbClient = dbClient; _structuresDbSchemaBuilder = new SqlDbStructuresSchemaBuilder(_dbClient.SqlStrings); _indexesDbSchemaBuilder = new SqlDbIndexesSchemaBuilder(_dbClient.SqlStrings, _dbClient.ProviderType); _uniquesDbSchemaBuilder = new SqlDbUniquesSchemaBuilder(_dbClient.SqlStrings); _indexesDbSchemaSynchronizer = new SqlDbIndexesSchemaSynchronizer(_dbClient); _uniquesDbSchemaSynchronizer = new SqlDbUniquesSchemaSynchronizer(_dbClient); }
internal SqlDbIndexesSchemaSynchronizer(SqlDbClient dbClient) { _dbClient = dbClient; _sqlStrings = dbClient.SqlStrings; _dataTypeTranslator = new SqlDbDataTypeTranslator(); //TODO: IoC or Factory _columnGenerator = dbClient.ProviderType == StorageProviders.Sql2008 ? (ISqlDbColumnGenerator)new SqlDbColumnGenerator() : new AzureDbColumnGenerator(); }
public void ForServerConnection_WhenServerExists_ConnectionIsAgainstMaster() { var connectionInfo = new SisoConnectionInfo(LocalConstants.ConnectionStringNameForTemp); var db = new SqlDatabase(connectionInfo); using (var dbClient = new SqlDbClient(db.ServerConnectionInfo, false)) { Assert.AreEqual("master", dbClient.DbName); } }
public void ForDatabaseConnection_WhenDatabaseExists_ConnectionIsAgainstSpecifiedDb() { DbHelper.EnsureDbExists(LocalConstants.TempDbName); var connectionInfo = new SisoConnectionInfo(LocalConstants.ConnectionStringNameForTemp); var db = new SqlDatabase(connectionInfo); using (var dbClient = new SqlDbClient(db.ConnectionInfo, false)) { Assert.AreEqual("SisoDb.IntegrationTests.Temp", dbClient.DbName); } }
public static void DeleteScript(int scriptId) { var dbc = new SqlDbClient(ConnString); dbc.GetNonQuery(cmd => { cmd.CommandText = "sp_deleteScript"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@scriptId", scriptId)); }); }
public static IEnumerable <Script> GetScripts() { var dbc = new SqlDbClient(ConnString); return(dbc.GetQuery(cmd => { cmd.CommandText = "sp_getScripts"; cmd.CommandType = CommandType.StoredProcedure; }) .AsEnumerable() .Select(s => new Script(s))); }
public static int AddScript(Script s) { var dbc = new SqlDbClient(ConnString); return(dbc.GetScalar <int>(cmd => { cmd.CommandText = "sp_AddScript"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@name", s.Name)); cmd.Parameters.Add(new SqlParameter("@description", s.Description)); cmd.Parameters.Add(new SqlParameter("@searchPattern", s.SearchPattern)); cmd.Parameters.Add(new SqlParameter("@replacePattern", s.ReplacePattern)); })); }
public static Script GetScript(int scriptId) { var dbc = new SqlDbClient(ConnString); return(dbc.GetQuery(cmd => { cmd.CommandText = "sp_getScript"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@scriptId", scriptId)); }) .AsEnumerable() .Select(s => new Script(s)) .FirstOrDefault()); }
public void Upsert_WhenNoSetExists_TablesAreCreated() { using(var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false)) { var upserter = new SqlDbSchemaUpserter(dbClient); upserter.Upsert(_structureSchema); } var structureTableExists = DbHelper.TableExists(_structureTableName); var indexesTableExists = DbHelper.TableExists(_indexesTableName); Assert.IsTrue(structureTableExists); Assert.IsTrue(indexesTableExists); }
public TransactionsServiceShould() { testSqlClient = new TestSqlDbClient("TestDatabase", "admin", "1234"); sqlClient = new SqlDbClient("TestDatabase", "admin", "1234"); transactionsService = new TransactionsService(sqlClient); testSqlClient.CreateTestDatabase(); testSqlClient.CreateTestTransactionTable(); testSqlClient.CreateTestAccountsTable(); testSqlClient.InsertTestTransactions(); testSqlClient.InsertTestAccounts(); }
public static void UpdateScript(int id, Script s) { var dbc = new SqlDbClient(ConnString); dbc.GetNonQuery(cmd => { cmd.CommandText = "sp_updateScript"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@scriptId", id)); cmd.Parameters.Add(new SqlParameter("@name", s.Name)); cmd.Parameters.Add(new SqlParameter("@description", s.Description)); cmd.Parameters.Add(new SqlParameter("@searchPattern", s.SearchPattern)); cmd.Parameters.Add(new SqlParameter("@replacePattern", s.ReplacePattern)); }); }
public void Synhronize_WhenTableIsMissingColumn_ColumnIsAdded() { CreateStructureSet(); var hashForColumn = SisoDbEnvironment.MemberNameGenerator.Generate("IndexableMember2"); DbHelper.DropColumns(_indexesTableName, hashForColumn); using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false)) { var synhronizer = new SqlDbIndexesSchemaSynchronizer(dbClient); synhronizer.Synchronize(_structureSchema); } var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForColumn); Assert.IsTrue(columnExists); }
public void Synhronize_WhenTableHasObsoleteColumn_ColumnIsDropped() { CreateStructureSet(); var hashForObsoleteColumn = SisoDbEnvironment.HashService.GenerateHash("ExtraColumn"); var obsoleteColumnDefinition = string.Format("[{0}] [int] sparse null", hashForObsoleteColumn); DbHelper.AddColumns(_indexesTableName, obsoleteColumnDefinition); using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false)) { var synhronizer = new SqlDbIndexesSchemaSynchronizer(dbClient); synhronizer.Synchronize(_structureSchema); } var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForObsoleteColumn); Assert.IsFalse(columnExists); }
public void UpsertStructureSet(IStructureSchema structureSchema) { lock (_upsertedSchemas) { if (_upsertedSchemas.Contains(structureSchema.Name)) return; using (var dbClient = new SqlDbClient(_connectionInfo, false)) { var upserter = new SqlDbSchemaUpserter(dbClient); upserter.Upsert(structureSchema); } _upsertedSchemas.Add(structureSchema.Name); } }
public void DropStructureSet(IStructureSchema structureSchema) { lock (_upsertedSchemas) { _upsertedSchemas.Remove(structureSchema.Name); var sql = _sqlStrings.GetSql("DropStructureTables").Inject( structureSchema.GetIndexesTableName(), structureSchema.GetStructureTableName()); using (var client = new SqlDbClient(_connectionInfo, false)) { client.ExecuteNonQuery(CommandType.Text, sql, new QueryParameter("entityHash", structureSchema.Hash)); } } }
public void Upsert_WhenDbHasOneObsoleteMember_ColumnIsDroppedFromIndexesTable() { var hashForObsoleteColumn = SisoDbEnvironment.MemberNameGenerator.Generate("ExtraColumn"); using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false)) { var upserter = new SqlDbSchemaUpserter(dbClient); upserter.Upsert(_structureSchema); var obsoleteColumnDefinition = string.Format("[{0}] [int] sparse null", hashForObsoleteColumn); DbHelper.AddColumns(_indexesTableName, obsoleteColumnDefinition); upserter.Upsert(_structureSchema); } var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForObsoleteColumn); Assert.IsFalse(columnExists); }
public void Upsert_WhenClassHasOneNewMember_ColumnIsAddedToIndexesTable() { var hashForColumn = SisoDbEnvironment.MemberNameGenerator.Generate("IndexableMember2"); using (var dbClient = new SqlDbClient(_sqlDb.ConnectionInfo, false)) { var upserter = new SqlDbSchemaUpserter(dbClient); upserter.Upsert(_structureSchema); DbHelper.DropColumns(_indexesTableName, hashForColumn); upserter.Upsert(_structureSchema); } var columnExists = DbHelper.ColumnsExist(_indexesTableName, hashForColumn); Assert.IsTrue(columnExists); }
public TransactionsService(SqlDbClient sqlDbClient) { client = sqlDbClient; }
internal SqlDbUniquesSchemaSynchronizer(SqlDbClient dbClient) { _dbClient = dbClient; _sqlStrings = dbClient.SqlStrings; }
internal SqlBulkInserter(SqlDbClient dbClient) { _dbClient = dbClient; _elementsBatcher = new ElementBatcher(1000); }