Exemple #1
0
            /// <summary>
            /// returns undo <see cref="Query"/> array corresponding to queries performed on
            /// <paramref name="auditedTableName"/>, where the i'th undo <see cref="Query"/> in result
            /// corresponds the i'th row in <paramref name="auditTableResultSet"/>.
            /// </summary>
            /// <seealso cref="getUndoQuery(ResultSet.Row, string, Dictionary{long, Query.eQueryType})"/>
            /// <param name="auditTableResultSet"></param>
            /// <param name="auditedTableName"></param>
            /// <param name="queryTypeIdToQueryType"></param>
            /// <returns>
            /// undo <see cref="Query"/> array corresponding to queries performed on
            /// <paramref name="auditedTableName"/>, where the i'th undo <see cref="Query"/> in result
            /// corresponds the i'th row in <paramref name="auditTableResultSet"/>
            /// </returns>
            /// <exception cref="UnsupportedAuditQueryTypeException">
            /// <seealso cref="getUndoQuery(ResultSet.Row, string, Dictionary{long, Query.eQueryType})"/>
            /// </exception>
            internal static WriteQuery[] GetAuditTableUndoWriteQueries(
                ResultSet auditTableResultSet,
                string auditedTableName,
                Dictionary <long, Query.eQueryType> queryTypeIdToQueryType)
            {
                WriteQuery[] undoQueries = new WriteQuery[auditTableResultSet.RowCount];

                for (int i = 0; i < auditTableResultSet.RowCount; i++)
                {
                    ResultSet.Row auditTableRow = auditTableResultSet.Rows[i];
                    WriteQuery    undoQuery     = getUndoQuery(
                        auditTableRow,
                        auditedTableName,
                        queryTypeIdToQueryType);

                    undoQueries[i] = undoQuery;
                }

                return(undoQueries);
            }
Exemple #2
0
            /// <summary>
            /// returns undo <see cref="Query"/> corresponding to query performed on
            /// <paramref name="auditedTableName"/>, where <paramref name="auditTableRow"/> contains
            /// the data required to undo a single row in <paramref name="auditedTableName"/>,
            /// which was affected by the query.
            /// </summary>
            /// <param name="auditTableRow"></param>
            /// <param name="auditedTableName"></param>
            /// <param name="queryTypeIdToQueryType"></param>
            /// <returns>
            /// undo <see cref="Query"/> corresponding to query performed on
            /// <paramref name="auditedTableName"/>, where <paramref name="auditTableRow"/> contains
            /// the data required to undo a single row in <paramref name="auditedTableName"/>,
            /// which was affected by the query
            /// </returns>
            /// <exception cref="UnsupportedAuditQueryTypeException">
            /// thrown if <see cref="Query.eQueryType"/> specified in <paramref name="auditTableRow"/>
            /// is not supported for audit
            /// </exception>
            private static WriteQuery getUndoQuery(
                ResultSet.Row auditTableRow,
                string auditedTableName,
                Dictionary <long, Query.eQueryType> queryTypeIdToQueryType)
            {
                WriteQuery undoQuery;

                // type of query that was originally performed on audited table
                long queryTypeId = auditTableRow.GetColumnValue <long>(
                    AuditTableStructure.QUERY_ID_COLUMN_INDEX);

                Query.eQueryType queryType = queryTypeIdToQueryType[queryTypeId];

                // value of _id column of modified row in audit table
                long auditedTableRowId = auditTableRow.GetColumnValue <long>(
                    AuditTableStructure.AUDITED_TABLE_ROW_ID_COLUMN_INDEX);

                // get undo query based on query type
                if (queryType == Query.eQueryType.Insert)
                {
                    undoQuery = new DeleteQuery(
                        auditedTableName,
                        new BasicCondition(
                            new ValuedTableColumn(
                                DatabaseStructure.ID_COLUMN_NAME,
                                auditedTableName,
                                auditedTableRowId),
                            BasicCondition.eOperatorType.Equal
                            )
                        );
                }
                else if (queryType == Query.eQueryType.Update || queryType == Query.eQueryType.Delete)
                {
                    // ValuedColumn of _id column of modified row in audited table
                    ArrayRange <ValuedColumn> auditedTableRowIdArrayRange =
                        new ArrayRange <ValuedColumn>(
                            new ValuedColumn(DatabaseStructure.ID_COLUMN_NAME, auditedTableRowId)
                            );

                    // ValueColumn of columns other than _id of modified row in audited table
                    ArrayRange <ValuedColumn> auditedTableRowValuesArrayRange =
                        new ArrayRange <ValuedColumn>(
                            ValuedColumn.Parse(auditTableRow.ColumnNames, auditTableRow.ColumnValues),
                            AuditTableStructure.AUDITED_TABLE_DATA_COLUMNS_START_INDEX);

                    // unified ValuedColumn list for undo query
                    List <ValuedColumn> queryValuedColumns
                        = ListUtils.ListFromArrayRanges(
                              auditedTableRowIdArrayRange,
                              auditedTableRowValuesArrayRange);

                    if (queryType == Query.eQueryType.Update)
                    {
                        undoQuery = new UpdateQuery(
                            auditedTableName,
                            queryValuedColumns,
                            new BasicCondition(
                                new ValuedTableColumn(
                                    DatabaseStructure.ID_COLUMN_NAME,
                                    auditedTableName,
                                    auditedTableRowId),
                                BasicCondition.eOperatorType.Equal
                                )
                            );
                    }
                    else // queryType == Query.eQueryType.Delete
                    {
                        undoQuery = new InsertQuery(auditedTableName, queryValuedColumns);
                    }
                }
                else
                {
                    throw new UnsupportedAuditQueryTypeException(queryType);
                }

                return(undoQuery);
            }