public override void RunTransform(DatabaseStructure model) { foreach (TableStructure tbl in model.Tables) { if (RemoveForeignKeys) { tbl._Constraints.RemoveIf(c => c is IForeignKey); } if (RemovePrimaryKeys) { tbl._Constraints.RemoveIf(c => c is IPrimaryKey); } if (RemoveIndexes) { tbl._Constraints.RemoveIf(c => c is IIndex); } if (RemoveUniques) { tbl._Constraints.RemoveIf(c => c is IUnique); } if (RemoveAutoIncrements) { foreach (var c in tbl._Columns) { c.DataType.SetAutoincrement(false); } } } }
public void BuildStructureWithDifferentConnectionNameTest() { // arrange var di = DependencyInjectionFactory.ConfigureDependencyInjection(); var clientConfig = di.GetService <IClientConfig>(); if (!clientConfig.IsAssigned()) { throw new Exception("clientconfig not returned by dependency injection"); } clientConfig.DefaultDatabase = "SchemaDatabaseDevelopment"; var client = new SqlClient(new SqlClientRepository(clientConfig)); IDatabaseStructure target = new DatabaseStructure(client); // act target.BuildStructure(); // assert target.Tables.Should().HaveCount(8); // TestClassGenerator heeft nu 6 tabellen target.Tables.First(x => x.Name == "Test6").PrimaryKey.Should().Be("Test6Id"); }
public virtual void Configure(IType type, IDictionary <string, string> parms, Dialect.Dialect dialect) { IdentifierType = type; bool forceTableUse = PropertiesHelper.GetBoolean(ForceTableParam, parms, false); string sequenceName = DetermineSequenceName(parms, dialect); int initialValue = DetermineInitialValue(parms); int incrementSize = DetermineIncrementSize(parms); string optimizationStrategy = DetermineOptimizationStrategy(parms, incrementSize); incrementSize = DetermineAdjustedIncrementSize(optimizationStrategy, incrementSize); Optimizer = OptimizerFactory.BuildOptimizer( optimizationStrategy, IdentifierType.ReturnedClass, incrementSize, PropertiesHelper.GetInt32(InitialParam, parms, -1)); // Use -1 as default initial value here to signal that it's not set. if (!forceTableUse && RequiresPooledSequence(initialValue, incrementSize, Optimizer) && !dialect.SupportsPooledSequences) { // force the use of a table (overriding whatever the user configured) since the dialect // doesn't support the sequence features we need. forceTableUse = true; Log.Info("Forcing table use for sequence-style generator due to optimizer selection where db does not support pooled sequences."); } DatabaseStructure = BuildDatabaseStructure(type, parms, dialect, forceTableUse, sequenceName, initialValue, incrementSize); DatabaseStructure.Prepare(Optimizer); }
public void NotifyChangeSourceModel(DatabaseStructure model) { if (Source != null) { Source.NotifyChangeModel(model); } }
public void NotifyChangeTargetModel(DatabaseStructure model) { if (Target != null) { Target.NotifyChangeModel(model); } }
public void GetAlterSql(ISqlDumper dmp) { VersionDef current = Version; VersionDef prev = Version.GetVersion(-1); var vardef = new VariantDef(VariantFile); DatabaseStructure curstruct = current.LoadStructure(vardef); DatabaseStructure prevstruct = prev.LoadStructure(vardef); ISqlDialect dialect = curstruct.Dialect ?? Version.Db.Dialect; DbDiffOptions opts = new DbDiffOptions(); //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag); opts.AllowRecreateTable = true; if (prevstruct == null) { dmp.CreateDatabaseObjects(curstruct); } else { dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), null); } current.SetVersionSql(dmp); }
public void NotifyChangeTargetModel(DatabaseStructure model) { foreach (var item in Items) { item.NotifyChangeTargetModel(model); } }
public DbDefConnection(DatabaseStructure db) : base(new DbDefStructureConnectionFactory { Structure = db }) { m_db = db; }
//public DbDefConnection(Func<string> getCurrentFileName) // : base(null) //{ // m_getCurrentFileName = getCurrentFileName; //} //public DbDefConnection() //{ //} public DbDefConnection(IDatabaseStructure db) : base(new DbDefStructureConnectionFactory { Structure = new DatabaseStructure(db) }) { m_db = ((DbDefStructureConnectionFactory)PhysicalFactory).Structure; }
// constructor 3 public DbDefSource(IDatabaseStructure db, ReadOnly flag) { m_readOnlyStructure = new DatabaseStructure(db); m_readOnlyStructure.MarkAllFilled(); m_openedReadOnly = true; m_conn = new DbDefConnection(m_readOnlyStructure); }
public void Reload() { // reload is not neccessary var db = CustomGetStructure(); if (db != null) { m_db = new DatabaseStructure(db); return; } string newfile = GetCurrentFileName(); if (newfile == null) { return; } if (newfile == m_file && new FileInfo(m_file).LastWriteTime <= m_fileTimeStamp) { return; } m_file = newfile; m_db = DatabaseStructure.Load(m_file); m_db.MarkAllFilled(); m_fileTimeStamp = new FileInfo(m_file).LastWriteTime; }
public void GetAlterSql(ISqlDumper dmp) { DumpSubFolder(dmp, "before"); VersionDef current = this; VersionDef prev = current.GetVersion(-1); VersionDb vdb = current.Db; DatabaseStructure curstruct = DatabaseStructure.Load(current.GetFile()); DatabaseStructure prevstruct = null; if (prev != null) { prevstruct = DatabaseStructure.Load(prev.GetFile()); } ISqlDialect dialect = vdb.Dialect; DbDiffOptions opts = new DbDiffOptions(); //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag); opts.AllowRecreateTable = true; if (prevstruct == null) { dmp.CreateDatabaseObjects(curstruct); } else { dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), AddSubFoldersToPlan); } DumpSubFolder(dmp, "after"); current.SetVersionSql(dmp); }
public void When_TableExists_is_executed_and_table_does_notexists_Should_return_false() { // arrange var di = DependencyInjectionFactory.ConfigureDependencyInjection(); var clientConfig = di.GetService <IClientConfig>(); if (!clientConfig.IsAssigned()) { throw new Exception("clientconfig not returned by dependency injection"); } clientConfig.DefaultDatabase = "TestClassGenerator"; var client = new SqlClient(new SqlClientRepository(clientConfig)); IDatabaseStructure target = new DatabaseStructure(client); target.BuildStructure(); // act var tableExists = client.TableExists("Test666"); // assert tableExists.Should().BeFalse(); }
private void RefreshData(bool refreshSource, bool refreshTarget) { if (refreshSource) { m_downloadedSrc = null; m_srcFixedDataLoaded = false; if (m_srcDb != null) { m_srcDb.Connection.Cache.Clear(); } } if (refreshTarget) { m_downloadedDst = null; m_dstFixedDataLoaded = false; if (m_dstDb != null) { m_dstDb.Connection.Cache.Clear(); } } DownloadWhenNeededAndRefresh(); // m_src = null; // m_dst = null; // if (m_srcDb != null && m_dstDb != null) // { // m_downloadedSrc = m_srcDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null); // m_downloadedDst = m_dstDb.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null); // } //} //RefreshNotDownload(); }
public void When_GetTypedCommaFields_executed_on_table_Should_return_a_string_with_all_ColumnNames_concatenated() { // arrange var di = DependencyInjectionFactory.ConfigureDependencyInjection(); var clientConfig = di.GetService <IClientConfig>(); if (!clientConfig.IsAssigned()) { throw new Exception("clientconfig not returned by dependency injection"); } clientConfig.DefaultDatabase = "SchemaDatabaseDevelopment"; var client = new SqlClient(new SqlClientRepository(clientConfig)); IDatabaseStructure target = new DatabaseStructure(client); target.BuildStructure(); var table = target.Tables.First(x => x.Name == "Test5"); var columnNameList = new List <string> { "naam", "Omschrijving" }; // act var columnString = table.ColumnDataItems.GetFieldNamesAsParameters(columnNameList); // assert columnString.Should().Be("string naam, string omschrijving"); }
public override void RunTransform(DatabaseStructure model) { ProcessItem("table", model.Tables.Clear); foreach (string type in model.SpecificObjects.Keys) { ProcessItem(type, ((SpecificObjectCollection)model.SpecificObjects[type]).Clear); } }
public DatabaseStructure LoadStructure() { var dbs = DatabaseStructure.Load(Version.GetFile()); var mod = new VariantDef(VariantFile); mod.RunTransform(dbs); return(dbs); }
private DatabaseStructure GetReadOnlyStructure() { if (m_readOnlyStructure == null) { m_readOnlyStructure = new DatabaseStructure(m_conn.CustomGetStructure()); } return(m_readOnlyStructure); }
public void RunTransform(DatabaseStructure dbs) { foreach (var addon in ModelTransforms) { var mt = addon.Instance as IDbModelTransform; mt.RunTransform(dbs); } }
private void ReloadTargetModel() { var dbmem = new DatabaseStructureMembers { TableList = true }; m_dstModel = new DatabaseStructure(m_target.InvokeLoadStructure(dbmem, null)); }
public void ConvertByteToClass_ClassRerurn() { //arrange FileEmulator tmp = CreateFileEmulator(); //act DatabaseStructure expected_structure = new DatabaseStructure(tmp.bytes_array.ToArray()); //assert Assert.AreEqual(JsonConvert.SerializeObject(expected_structure), JsonConvert.SerializeObject(tmp.class_data)); }
private void LoadFromJob(JobConnection jobconn, DataSynJobCommand cmd) { m_datasyn = cmd.DataSyn; m_source = cmd.Source; m_target = cmd.Target; m_jobconn = jobconn; m_cmd = cmd; m_srcModel = null; m_dstModel = null; DownloadWhenNeededAndRefresh(); }
public static DatabaseStructure LoadStructure(this VersionDef verdef, VariantDef vardef) { if (verdef == null) { return(null); } var model = DatabaseStructure.Load(verdef.GetFile()); vardef.RunTransform(model); return(model); }
private void ReloadSourceModel() { var dbmem = new DatabaseStructureMembers { TableList = true }; dbmem.SpecificObjectOverride["view"] = new SpecificObjectMembers { ObjectList = true }; m_srcModel = new DatabaseStructure(m_source.InvokeLoadStructure(dbmem, null)); }
//public ITableSource CreateTable(ITableStructure table) //{ // Reload(); // ITableSource res = new TableDefSource(this, m_db.AddTable(MangleTable(table))); // m_db.SortTables(); // SaveToFile(); // return res; //} public void AlterDatabase(IDatabaseStructure src, IDatabaseStructure dst, DbDiffOptions opts) { Reload(); if (!SupportsMultipleSchema()) { var tmp = new DatabaseStructure(dst); tmp.RunNameTransformation(new SetSchemaNameTransformation(null)); dst = tmp; } m_conn.DbStruct.AlterDatabase(src, dst, opts, this); SaveToFile(); }
public void ChangedProps() { Cursor last = Cursor.Current; Cursor.Current = Cursors.WaitCursor; foreach (var ver in Versions) { DatabaseStructure dbs = DatabaseStructure.Load(ver.GetFile()); dbs.SetProps(m_props); dbs.Save(ver.GetFile()); } Cursor.Current = last; }
private void DownloadFixedData(IDatabaseSource db, DatabaseStructure dbs, IDatabaseStructure pattern) { foreach (var tbl in pattern.Tables) { if (tbl.FixedData == null) { continue; } if (dbs.Tables.GetIndex(tbl.FullName) < 0) { continue; } var t2 = (TableStructure)dbs.Tables[tbl.FullName]; var pk1 = tbl.FindConstraint <IPrimaryKey>(); var pk2 = t2.FindConstraint <IPrimaryKey>(); if (pk1 == null || pk2 == null) { continue; } if (pk1.Columns.Count != pk2.Columns.Count) { continue; } using (DbCommand cmd = db.Connection.SystemConnection.CreateCommand()) { StringWriter sw = new StringWriter(); ISqlDumper dmp = db.Dialect.CreateDumper(sw); dmp.Put("^select * ^from %f ^where 0=1", t2); foreach (var row in tbl.FixedData.Rows) { dmp.Put(" ^or ( "); for (int i = 0; i < pk1.Columns.Count; i++) { if (i > 0) { dmp.Put(" ^and "); } dmp.Put(" %s = %v ", pk1.Columns[i].ColumnName, row.GetValue(tbl.Columns.GetIndex(pk1.Columns[i].ColumnName))); } dmp.Put(" ) "); } cmd.CommandText = sw.ToString(); using (var reader = db.GetAnyDDA().AdaptReader(cmd.ExecuteReader())) { t2.FixedData = new InMemoryTable(t2, reader); } } } }
private void sswapToolStripMenuItem_Click(object sender, EventArgs e) { var t1 = m_srcDb; m_srcDb = m_dstDb; m_dstDb = t1; var t2 = m_downloadedSrc; m_downloadedSrc = m_downloadedDst; m_downloadedDst = t2; RefreshNotDownload(); UpdateTitles(); }
private void SetNewTargetDb(IDatabaseSource newdb) { if (m_dstDb != null) { Async.SafeClose(m_dstDb.Connection); } m_dstDb = newdb; if (m_dstDb != null) { m_dstDb.ChangeConnection(ConnPack); } m_downloadedDst = null; DownloadWhenNeededAndRefresh(); }
public virtual Task <object> GenerateAsync(ISessionImplementor session, object obj, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <object>(cancellationToken)); } try { return(Optimizer.GenerateAsync(DatabaseStructure.BuildCallback(session), cancellationToken)); } catch (System.Exception ex) { return(Task.FromException <object>(ex)); } }