Пример #1
0
        private questStatus getJoinTarget(TablesetColumnId tablesetColumnId, out TablesetTable tablesetTable, out TablesetView tablesetView)
        {
            // Initialize
            questStatus status = null;

            tablesetTable = null;
            tablesetView  = null;


            // Get TablesetColumn
            DbTablesetColumnsMgr dbTablesetColumnsMgr = new DbTablesetColumnsMgr(this.UserSession);
            TablesetColumn       tablesetColumn       = null;

            status = dbTablesetColumnsMgr.Read(tablesetColumnId, out tablesetColumn);
            if (!questStatusDef.IsSuccessOrWarning(status))
            {
                return(status);
            }

            if (tablesetColumn.EntityTypeId == EntityType.Table)
            {
                TablesetTableId     tablesetTableId     = new TablesetTableId(tablesetColumn.TableSetEntityId);
                DbTablesetTablesMgr dbTablesetTablesMgr = new DbTablesetTablesMgr(this.UserSession);
                status = dbTablesetTablesMgr.Read(tablesetTableId, out tablesetTable);
                if (!questStatusDef.IsSuccessOrWarning(status))
                {
                    return(status);
                }
            }
            else if (tablesetColumn.EntityTypeId == EntityType.View)
            {
                TablesetViewId     tablesetViewId     = new TablesetViewId(tablesetColumn.TableSetEntityId);
                DbTablesetViewsMgr dbTablesetViewsMgr = new DbTablesetViewsMgr(this.UserSession);
                status = dbTablesetViewsMgr.Read(tablesetViewId, out tablesetView);
                if (!questStatusDef.IsSuccessOrWarning(status))
                {
                    return(status);
                }
            }
            return(new questStatus(Severity.Success));
        }
Пример #2
0
        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));
        }