public questStatus ReadTablesetConfiguration(TablesetId tablesetId, out TablesetConfiguration tablesetConfiguration) { // Initialize questStatus status = null; tablesetConfiguration = null; // Read tableset configuration status = _dbTablesetMgr.ReadTablesetConfiguration(tablesetId, out tablesetConfiguration); if (!questStatusDef.IsSuccess(status)) { return(status); } // Read database entities DatabaseId databaseId = new DatabaseId(tablesetConfiguration.Database.Id); DatabaseEntities databaseEntities = null; DatabaseMgr databaseMgr = new DatabaseMgr(this.UserSession); status = databaseMgr.ReadDatabaseEntities(databaseId, out databaseEntities); if (!questStatusDef.IsSuccess(status)) { return(status); } // Sort out what's assigned and not assigned to the tableset. List <Table> nonAssignedTableList = new List <Table>(); List <View> nonAssignedViewList = new List <View>(); foreach (Table table in databaseEntities.TableList) { TablesetTable tablesetTable = tablesetConfiguration.TablesetTables.Find(delegate(TablesetTable ts) { return(ts.Schema == table.Schema && ts.Name == table.Name); }); if (tablesetTable == null) { nonAssignedTableList.Add(table); } } tablesetConfiguration.DBTableList = nonAssignedTableList; // Load database views and columns into configuration NOT assigned to tableset. foreach (View view in databaseEntities.ViewList) { TablesetView tablesetView = tablesetConfiguration.TablesetViews.Find(delegate(TablesetView tv) { return(tv.Schema == view.Schema && tv.Name == view.Name); }); if (tablesetView == null) { nonAssignedViewList.Add(view); } } tablesetConfiguration.DBViewList = nonAssignedViewList; return(new questStatus(Severity.Success)); }
//TablesetConfigurationViewModel #endregion #region Public Methods /*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region CRUD //---------------------------------------------------------------------------------------------------------------------------------- // CRUD //---------------------------------------------------------------------------------------------------------------------------------- public questStatus GetDatabaseEntities(DatabaseId databaseId, out List <BootstrapTreenodeViewModel> dbTableNodeList, out List <BootstrapTreenodeViewModel> dbViewNodeList) { // Initialize questStatus status = null; dbTableNodeList = null; dbViewNodeList = null; // Read database entities DatabaseEntities databaseEntities = null; DatabaseMgr databaseMgr = new DatabaseMgr(this.UserSession); status = databaseMgr.ReadDatabaseEntities(databaseId, out databaseEntities); if (!questStatusDef.IsSuccess(status)) { return(status); } // Transfer model // Tables dbTableNodeList = new List <BootstrapTreenodeViewModel>(); foreach (Table dbTable in databaseEntities.TableList) { BootstrapTreenodeViewModel bootstrapTreenodeViewModel = null; status = FormatBootstrapTreeviewNode(dbTable, out bootstrapTreenodeViewModel); if (!questStatusDef.IsSuccess(status)) { return(status); } dbTableNodeList.Add(bootstrapTreenodeViewModel); } // Views dbViewNodeList = new List <BootstrapTreenodeViewModel>(); foreach (View dbView in databaseEntities.ViewList) { BootstrapTreenodeViewModel bootstrapTreenodeViewModel = null; status = FormatBootstrapTreeviewNode(dbView, out bootstrapTreenodeViewModel); if (!questStatusDef.IsSuccess(status)) { return(status); } dbViewNodeList.Add(bootstrapTreenodeViewModel); } return(new questStatus(Severity.Success)); }
public questStatus SaveTablesetConfiguration(TablesetConfiguration tablesetConfiguration, out TablesetId tablesetId) { // Initialize questStatus status = null; tablesetId = null; DbMgrTransaction trans = null; bool bFiltersRemoved = false; questStatus status2 = null; try { // BEGIN TRANSACTION status = BeginTransaction("SaveTablesetConfiguration" + Guid.NewGuid().ToString(), out trans); if (!questStatusDef.IsSuccess(status)) { return(status); } /* * Update tableset info. */ // Read the tableset TablesetsMgr tablesetsMgr = new TablesetsMgr(this.UserSession); TablesetId _tablesetId = new TablesetId(tablesetConfiguration.Tableset.Id); Tableset _tableset = null; status = tablesetsMgr.Read(trans, _tablesetId, out _tableset); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } /* * Remove all tableset entities. */ status = ClearTablesetEntities(trans, _tablesetId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } // TESTING ONLY: COMMIT TRANSACTION bool bKlugie = false; if (bKlugie) { status = CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } } /* * Get database entites. */ DatabaseId databaseId = new DatabaseId(tablesetConfiguration.Database.Id); DatabaseMgr databaseMgr = new DatabaseMgr(this.UserSession); DatabaseEntities databaseEntities = null; status = databaseMgr.ReadDatabaseEntities(databaseId, out databaseEntities); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } #region Save tableset info. /* * Save tableset info. */ DbTablesetColumnsMgr dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this.UserSession); // Save table info. DbTablesetTablesMgr dbTablesetTablesMgr = new DbTablesetTablesMgr(this.UserSession); List <TablesetTable> tablesetTableList = new List <TablesetTable>(); foreach (TablesetTable tablesetTable in tablesetConfiguration.TablesetTables) { Table _table = databaseEntities.TableList.Find(delegate(Table t) { return(t.Schema == tablesetTable.Schema && t.Name == tablesetTable.Name); }); if (_table == null) { RollbackTransaction(trans); return(new questStatus(Severity.Error, String.Format("ERROR: tableset table [{0}].[{1}] not found in database metainfo. Try refreshing database schema info", tablesetTable.Schema, tablesetTable.Name))); } tablesetTable.TablesetId = _tableset.Id; tablesetTable.Table = _table; tablesetTableList.Add(tablesetTable); // Create tableset table. TablesetTableId tablesetTableId = null; status = dbTablesetTablesMgr.Create(trans, tablesetTable, out tablesetTableId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } foreach (Column column in _table.ColumnList) { Column _column = _table.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); }); if (_column == null) { RollbackTransaction(trans); return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in table [{1}].[{2}] in database metainfo. Try refreshing database schema info", column.Name, _table.Schema, _table.Name))); } TablesetColumn tablesetColumn = new TablesetColumn(); tablesetColumn.EntityTypeId = EntityType.Table; tablesetColumn.TableSetEntityId = tablesetTableId.Id; tablesetColumn.Name = column.Name; TablesetColumnId tablesetColumnId = null; status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } } } // Save view info. DbTablesetViewsMgr dbTablesetViewsMgr = new DbTablesetViewsMgr(this.UserSession); List <TablesetView> tablesetViewList = new List <TablesetView>(); foreach (TablesetView tablesetView in tablesetConfiguration.TablesetViews) { View _view = databaseEntities.ViewList.Find(delegate(View v) { return(v.Schema == tablesetView.Schema && v.Name == tablesetView.Name); }); if (_view == null) { RollbackTransaction(trans); return(new questStatus(Severity.Error, String.Format("ERROR: tableset view [{0}].[{1}] not found in database metainfo. Try refreshing database schema info", tablesetView.Schema, tablesetView.Name))); } tablesetView.TablesetId = _tableset.Id; tablesetView.View = _view; tablesetViewList.Add(tablesetView); // Create tableset view. TablesetViewId tablesetViewId = null; status = dbTablesetViewsMgr.Create(trans, tablesetView, out tablesetViewId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } foreach (Column column in _view.ColumnList) { Column _column = _view.ColumnList.Find(delegate(Column c) { return(c.Name == column.Name); }); if (_column == null) { RollbackTransaction(trans); return(new questStatus(Severity.Error, String.Format("ERROR: column [{0}] not found in view [{1}].[{2}] in database metainfo. Try refreshing database schema info", column.Name, _view.Schema, _view.Name))); } TablesetColumn tablesetColumn = new TablesetColumn(); tablesetColumn.EntityTypeId = EntityType.View; tablesetColumn.TableSetEntityId = tablesetViewId.Id; tablesetColumn.Name = column.Name; TablesetColumnId tablesetColumnId = null; status = dbTablesetColumnsMgr.Create(trans, tablesetColumn, out tablesetColumnId); if (!questStatusDef.IsSuccess(status)) { RollbackTransaction(trans); return(status); } } } #endregion // Update tableset. bFiltersRemoved = false; _tableset.DatabaseId = tablesetConfiguration.Database.Id; status2 = tablesetsMgr.Update(trans, _tableset); if (!questStatusDef.IsSuccess(status2)) { if (questStatusDef.IsWarning(status2)) { bFiltersRemoved = true; } else { RollbackTransaction(trans); return(status); } } // COMMIT TRANSACTION status = CommitTransaction(trans); if (!questStatusDef.IsSuccess(status)) { return(status); } // Return the tableset id tablesetId = new TablesetId(tablesetConfiguration.Tableset.Id); } catch (System.Exception ex) { if (trans != null) { RollbackTransaction(trans); } return(new questStatus(Severity.Fatal, String.Format("EXCEPTION: {0}.{1}: {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.InnerException != null ? ex.InnerException.Message : ex.Message))); } if (bFiltersRemoved) { return(status2); } return(new questStatus(Severity.Success)); }