use of CCDD.CcddClassesDataTable.TableModification in project CCDD by nasa.
the class CcddDbTableCommandHandler method buildModificationCommand.
/**
********************************************************************************************
* Build the commands to modify the table
*
* @param tableInfo
* table information
*
* @param modifications
* list of row modification information
*
* @param typeDefn
* table type definition
*
* @param newDataTypeHandler
* data type handler with data type modifications. null (or a reference to the
* current data type handler) if the change does not originate from the data type
* editor
*
* @param tableTree
* CcddTableTreeHandler reference describing the table tree
*
* @param skipInternalTables
* true to not build and execute the commands to update the internal tables. This is
* used during a data type update where only the data type name has changed in order
* to speed up the operation
*
* @return Table row modification command
********************************************************************************************
*/
private String buildModificationCommand(TableInformation tableInfo, List<TableModification> modifications, TypeDefinition typeDefn, CcddDataTypeHandler newDataTypeHandler, CcddTableTreeHandler tableTree, boolean skipInternalTables) {
StringBuilder modCmd = new StringBuilder("");
List<Object[]> tablePathList = null;
// Check that there are modifications
if (!modifications.isEmpty()) {
StringBuilder linksDelCmd = new StringBuilder("");
StringBuilder tlmDelCmd = new StringBuilder("");
// are not due to an update in the data type editor
if (newDataTypeHandler == null) {
// Set the updated data type handler to use the current handler
newDataTypeHandler = dataTypeHandler;
}
// Step through each modification
for (TableModification mod : modifications) {
// Check if this is a prototype table (modifications are made to the table)
if (tableInfo.isPrototype()) {
StringBuilder valuesModCmd = new StringBuilder("");
StringBuilder linksModCmd = new StringBuilder("");
StringBuilder tlmModCmd = new StringBuilder("");
StringBuilder groupsModCmd = new StringBuilder("");
StringBuilder fieldsModCmd = new StringBuilder("");
StringBuilder ordersModCmd = new StringBuilder("");
StringBuilder assnsModCmd = new StringBuilder("");
// Build the update command
modCmd.append("UPDATE " + tableInfo.getProtoVariableName().toLowerCase() + " SET ");
// Step through each changed column
for (int column = 0; column < mod.getRowData().length; column++) {
// Check if the column value changed
if (mod.getOriginalRowData()[column] == null || !mod.getOriginalRowData()[column].equals(mod.getRowData()[column])) {
// Build the command to change the column value
modCmd.append(typeDefn.getColumnNamesDatabase()[column] + " = " + delimitText(mod.getRowData()[column]) + ", ");
}
}
// structure
if (!skipInternalTables && typeDefn.isStructure()) {
// Get the original and current variable names, data types, array sizes,
// and bit lengths
String oldVariableName = mod.getOriginalRowData()[mod.getVariableColumn()].toString();
String newVariableName = mod.getRowData()[mod.getVariableColumn()].toString();
String oldDataType = mod.getOriginalRowData()[mod.getDataTypeColumn()].toString();
String newDataType = mod.getRowData()[mod.getDataTypeColumn()].toString();
String oldArraySize = mod.getOriginalRowData()[mod.getArraySizeColumn()].toString();
String newArraySize = mod.getRowData()[mod.getArraySizeColumn()].toString();
String oldBitLength = mod.getOriginalRowData()[mod.getBitLengthColumn()].toString();
String newBitLength = mod.getRowData()[mod.getBitLengthColumn()].toString();
// Initialize the flag to indicate no rate has changed
boolean rateChanged = false;
// Step through each rate index
for (int rateIndex : mod.getRateColumn()) {
// Get the old and new rate values
String oldRate = mod.getOriginalRowData()[rateIndex].toString();
String newRate = mod.getRowData()[rateIndex].toString();
// Check if the rate changed
if (!oldRate.equals(newRate)) {
// Set the flag to indicate that the rate changed and stop
// searching
rateChanged = true;
break;
}
}
// Set the flags to indicate if the variable name, data type, array size,
// and bit length values have changed
boolean variableChanged = !oldVariableName.equals(newVariableName);
boolean dataTypeChanged = !oldDataType.equals(newDataType);
boolean arraySizeChanged = !oldArraySize.equals(newArraySize);
boolean bitLengthChanged = !oldBitLength.equals(newBitLength);
// of this prototype and their entries in the internal tables
if (variableChanged || dataTypeChanged || arraySizeChanged || bitLengthChanged || rateChanged) {
// has changed
if (variableChanged || dataTypeChanged || arraySizeChanged || bitLengthChanged) {
// Set the flag to force the variable paths and offsets lists to be
// rebuilt
isPathUpdate = true;
}
// structure, and this structure is a root table
if (dataTypeChanged && !newDataTypeHandler.isPrimitive(newDataType) && rootStructures.contains(newDataType)) {
// Get the variable path
String newVariablePath = tableInfo.getTablePath() + "," + newDataType + "." + newVariableName;
// If the structure chosen as the variable's data type is a root
// structure, then any references in the internal tables are
// changed to the structure's new path as a child
valuesModCmd.append("UPDATE " + InternalTable.VALUES.getTableName() + " SET " + ValuesColumn.TABLE_PATH.getColumnName() + " = regexp_replace(" + ValuesColumn.TABLE_PATH.getColumnName() + ", E'^" + newDataType + ",', E'" + newVariablePath + ",'); ");
groupsModCmd.append("UPDATE " + InternalTable.GROUPS.getTableName() + " SET " + GroupsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + GroupsColumn.MEMBERS.getColumnName() + ", E'^" + newDataType + "(,|$)', E'" + newVariablePath + "\\\\1'); ");
fieldsModCmd.append("UPDATE " + InternalTable.FIELDS.getTableName() + " SET " + FieldsColumn.OWNER_NAME.getColumnName() + " = regexp_replace(" + FieldsColumn.OWNER_NAME.getColumnName() + ", E'^" + newDataType + ",', E'" + newVariablePath + ",'); INSERT INTO " + InternalTable.FIELDS.getTableName() + " SELECT regexp_replace(" + FieldsColumn.OWNER_NAME.getColumnName() + ", E'^" + newDataType + "', E'" + newVariablePath + "'), " + FieldsColumn.FIELD_NAME.getColumnName() + ", " + FieldsColumn.FIELD_DESC.getColumnName() + ", " + FieldsColumn.FIELD_SIZE.getColumnName() + ", " + FieldsColumn.FIELD_TYPE.getColumnName() + ", " + FieldsColumn.FIELD_REQUIRED.getColumnName() + ", " + FieldsColumn.FIELD_APPLICABILITY.getColumnName() + ", " + FieldsColumn.FIELD_VALUE.getColumnName() + " FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + FieldsColumn.OWNER_NAME.getColumnName() + " = '" + newDataType + "' AND " + FieldsColumn.FIELD_APPLICABILITY.getColumnName() + " != '" + ApplicabilityType.ROOT_ONLY.getApplicabilityName() + "'; ");
ordersModCmd.append("UPDATE " + InternalTable.ORDERS.getTableName() + " SET " + OrdersColumn.TABLE_PATH.getColumnName() + " = regexp_replace(" + OrdersColumn.TABLE_PATH.getColumnName() + ", E'^" + newDataType + ",', E'" + newVariablePath + ",'); INSERT INTO " + InternalTable.ORDERS.getTableName() + " SELECT " + OrdersColumn.USER_NAME.getColumnName() + ", regexp_replace(" + OrdersColumn.TABLE_PATH.getColumnName() + ", E'^" + newDataType + "', E'" + newVariablePath + "'), " + OrdersColumn.COLUMN_ORDER.getColumnName() + " FROM " + InternalTable.ORDERS.getTableName() + " WHERE " + OrdersColumn.TABLE_PATH.getColumnName() + " = '" + newDataType + "'; ");
String orgPathWithChildren = newDataType + "(," + PATH_IDENT + ")?";
assnsModCmd.append("UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'(?:^" + orgPathWithChildren + "|(" + assnsSeparator + ")" + orgPathWithChildren + ")', E'\\\\2" + newVariablePath + "\\\\1\\\\3', 'ng'); ");
// References in the links and telemetry scheduler to the root
// structure and its children are not automatically amended to
// include the new parent structure path, but are instead removed
deleteLinkPathRef("^" + newDataType + "(?:,|\\\\.|$)", linksDelCmd);
deleteTlmPathRef(newDataType + "(?:,|\\\\.|$)", tlmDelCmd);
}
// doesn't change even if multiple modifications are made to the table
if (tablePathList == null) {
// Create a list of table path arrays that are instances of this
// prototype table
tablePathList = tableTree.getTableTreePathArray(tableInfo.getPrototypeName(), tableTree.getNodeByNodeName(DEFAULT_INSTANCE_NODE_NAME), -1);
// primitive or another structure
if (dataTypeChanged && !dataTypeHandler.isPrimitive(oldDataType)) {
// Add the paths for references to the prototype in non-root
// prototype tables
tablePathList.addAll(tableTree.getTableTreePathArray(tableInfo.getPrototypeName(), tableTree.getNodeByNodeName(DEFAULT_PROTOTYPE_NODE_NAME), -1));
}
}
// Step through each table path found
for (Object[] path : tablePathList) {
boolean isDelLinksAndTlm = false;
// Get the variable name path from the table tree
String tablePath = tableTree.getFullVariablePath(path);
// Append the original/new data type and/or name of the variable
// that's being changed to the variable path. Escape any PostgreSQL
// reserved characters so that the original path can be used in a
// regular expression
String orgVariablePath = tablePath + "," + oldDataType + "." + oldVariableName;
String orgVarPathEsc = CcddUtilities.escapePostgreSQLReservedChars(orgVariablePath);
String newVariablePath = tablePath + "," + newDataType + "." + newVariableName;
// that the array status (is or isn't) remains unchanged
if ((variableChanged || (dataTypeChanged && dataTypeHandler.isPrimitive(oldDataType) && newDataTypeHandler.isPrimitive(newDataType))) && !(arraySizeChanged && (oldArraySize.isEmpty() || newArraySize.isEmpty()))) {
// Create the commands to update the internal tables for
// instances of non-array member variables of the prototype
// table
valuesModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.VALUES.getTableName(), ValuesColumn.TABLE_PATH.getColumnName(), "", "", true));
groupsModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.GROUPS.getTableName(), GroupsColumn.MEMBERS.getColumnName(), "", "", true));
fieldsModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.FIELDS.getTableName(), FieldsColumn.OWNER_NAME.getColumnName(), "", "", true));
ordersModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.ORDERS.getTableName(), OrdersColumn.TABLE_PATH.getColumnName(), "", "", true));
String orgPathWithChildren = orgVarPathEsc + "(," + PATH_IDENT + ")?";
assnsModCmd.append("UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'(?:^" + orgPathWithChildren + "|(" + assnsSeparator + ")" + orgPathWithChildren + ")', E'\\\\2" + newVariablePath + "\\\\1\\\\3', 'ng'); ");
// and telemetry scheduler tables, which is handled elsewhere)
if (!dataTypeChanged && !bitLengthChanged && !rateChanged) {
// Create the command to update the links table for
// instances of variables of the prototype table
linksModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.LINKS.getTableName(), LinksColumn.MEMBER.getColumnName(), "", "", true));
// Since the variable still fits within any message in the
// telemetry scheduler table to which it's assigned just
// change all references to the variable
tlmModCmd.append(updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.TLM_SCHEDULER.getTableName(), TlmSchedulerColumn.MEMBER.getColumnName(), "(.*" + tlmSchSeparator + ")", "\\\\1", true));
} else // The data type, bit length, or rate changed
{
// Set the flag to indicate that references to the variable
// and any children should be removed from the links and
// telemetry scheduler tables
isDelLinksAndTlm = true;
}
}
// Check if the bit length changed, but not the data type or rate
if (bitLengthChanged && !dataTypeChanged && !rateChanged) {
// Append the bit lengths to the variable paths
String orgVarPathEscBit = orgVarPathEsc + (oldBitLength.isEmpty() ? "" : ":" + oldBitLength);
String newVariablePathBit = newVariablePath + (newBitLength.isEmpty() ? "" : ":" + newBitLength);
// Create the command to update the links and telemetry
// scheduler tables for instances of variables of the prototype
// table. If bit-packing changed due to the bit length update
// then the affected variables are subsequently removed from
// the links and telemetry scheduler tables
linksModCmd.append(updateVarNameAndDataType(orgVarPathEscBit, newVariablePathBit, InternalTable.LINKS.getTableName(), LinksColumn.MEMBER.getColumnName(), "", "", true));
tlmModCmd.append(updateVarNameAndDataType(orgVarPathEscBit, newVariablePathBit, InternalTable.TLM_SCHEDULER.getTableName(), TlmSchedulerColumn.MEMBER.getColumnName(), "(.*" + tlmSchSeparator + ")", "\\\\1", true));
}
// primitive or another structure
if (dataTypeChanged && !dataTypeHandler.isPrimitive(oldDataType)) {
// Create the command to delete references to any children of
// the original structure path and change the data type for
// references to the structure itself
valuesModCmd.append("DELETE FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.TABLE_PATH.getColumnName() + " ~ E'^" + orgVarPathEsc + ",'; " + updateVarNameAndDataType(orgVarPathEsc, newVariablePath, InternalTable.VALUES.getTableName(), ValuesColumn.TABLE_PATH.getColumnName(), "", "", false));
// Build a regular expression for locating references to the
// original variable path
String pathMatch = orgVarPathEsc + "(?:,|$)";
// Remove all references to the structure and its children
groupsModCmd.append("DELETE FROM " + InternalTable.GROUPS.getTableName() + " WHERE " + GroupsColumn.MEMBERS.getColumnName() + " ~ E'^" + pathMatch + "'; ");
fieldsModCmd.append("DELETE FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + FieldsColumn.OWNER_NAME.getColumnName() + " ~ E'^" + pathMatch + "'; ");
ordersModCmd.append("DELETE FROM " + InternalTable.ORDERS.getTableName() + " WHERE " + OrdersColumn.TABLE_PATH.getColumnName() + " ~ E'^" + pathMatch + "'; ");
String orgPathWithChildren = orgVarPathEsc + "(?:," + PATH_IDENT + ")?";
assnsModCmd.append("UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'^" + orgPathWithChildren + "', E'', 'ng'); UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'" + assnsSeparator + orgPathWithChildren + "', E'', 'ng'); ");
// handled elsewhere)
if (!rateChanged) {
// Set the flag to indicate that references to the variable
// and any children should be removed from the links and
// telemetry scheduler tables
isDelLinksAndTlm = true;
}
}
// row addition and deletion methods)
if (arraySizeChanged && (oldArraySize.isEmpty() || newArraySize.isEmpty())) {
// Remove all references to the structure's children, but not
// the structure itself
valuesModCmd.append("DELETE FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.TABLE_PATH.getColumnName() + " ~ E'^" + orgVarPathEsc + "(?:,|\\\\[)" + "'; ");
// Build a regular expression for locating references to the
// original variable path and any children
String pathMatch = orgVarPathEsc + "(?:,|\\\\[|$)";
// Remove all references to the structure and its children in
// the internal tables (other than the custom values table)
groupsModCmd.append("DELETE FROM " + InternalTable.GROUPS.getTableName() + " WHERE " + GroupsColumn.MEMBERS.getColumnName() + " ~ E'^" + pathMatch + "'; ");
fieldsModCmd.append("DELETE FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + FieldsColumn.OWNER_NAME.getColumnName() + " ~ E'^" + pathMatch + "'; ");
ordersModCmd.append("DELETE FROM " + InternalTable.ORDERS.getTableName() + " WHERE " + OrdersColumn.TABLE_PATH.getColumnName() + " ~ E'^" + pathMatch + "'; ");
// Check if the variable changed from not an array to an array
if (!newArraySize.isEmpty()) {
// Remove all non-array references to the structure and its
// children in the script associations. If the variable
// changed from an array to not an array then updates to
// the associations are handled by the row deletion method
assnsModCmd.append("UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'^" + orgVarPathEsc + "(?:" + assnsSeparator + "|," + PATH_IDENT + "|$)', E'', 'ng'); ");
}
// handled elsewhere)
if (!rateChanged) {
// Set the flag to indicate that references to the variable
// and any children should be removed from the links and
// telemetry scheduler tables
isDelLinksAndTlm = true;
}
}
// scheduler tables
if (rateChanged || isDelLinksAndTlm) {
// Create the commands to delete the variable from the link and
// telemetry scheduler tables
deleteLinkAndTlmPathRef(oldArraySize, oldVariableName, orgVariablePath, orgVarPathEsc, linksDelCmd, tlmDelCmd);
}
}
}
}
// Check is a command was created to change the associations table
if (assnsModCmd.length() != 0) {
// Clean up any associations that no longer have a table referenced
assnsModCmd.append("UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'^" + assnsSeparator + "', E'', 'ng'); UPDATE " + InternalTable.ASSOCIATIONS.getTableName() + " SET " + AssociationsColumn.MEMBERS.getColumnName() + " = regexp_replace(" + AssociationsColumn.MEMBERS.getColumnName() + ", E'" + assnsSeparator + "$', E'', 'ng'); ");
}
// Remove the trailing comma and space, then add the condition based on the
// row's primary key, and add the commands to update the internal tables
modCmd = CcddUtilities.removeTrailer(modCmd, ", ");
modCmd.append(" WHERE " + typeDefn.getColumnNamesDatabase()[DefaultColumn.PRIMARY_KEY.ordinal()] + " = " + mod.getRowData()[DefaultColumn.PRIMARY_KEY.ordinal()] + "; " + valuesModCmd.toString() + groupsModCmd.toString() + fieldsModCmd.toString() + ordersModCmd.toString() + assnsModCmd.toString() + linksModCmd.toString() + tlmModCmd.toString());
} else // internal tables are to be updated, and this table is a structure
if (!skipInternalTables && typeDefn.isStructure()) {
// Get the variable path, including its name and data type
String variablePath = tableInfo.getTablePath() + "," + mod.getRowData()[mod.getDataTypeColumn()].toString() + "." + mod.getRowData()[mod.getVariableColumn()].toString();
// Step through each changed column
for (int column = 0; column < mod.getRowData().length; column++) {
// Check if the column value changed
if (!mod.getOriginalRowData()[column].equals(mod.getRowData()[column])) {
// Build the command to delete the old value in the custom values table
// (in case it already exists), then insert the (new) value into the
// custom values table
modCmd.append("DELETE FROM " + InternalTable.VALUES.getTableName() + " WHERE " + ValuesColumn.TABLE_PATH.getColumnName() + " = '" + variablePath + "' AND " + ValuesColumn.COLUMN_NAME.getColumnName() + " = '" + typeDefn.getColumnNamesUser()[column] + "';");
// the existing custom value should be removed
if (!mod.getRowData()[column].toString().startsWith(REPLACE_INDICATOR)) {
modCmd.append(" INSERT INTO " + InternalTable.VALUES.getTableName() + " (" + ValuesColumn.TABLE_PATH.getColumnName() + ", " + ValuesColumn.COLUMN_NAME.getColumnName() + ", " + ValuesColumn.VALUE.getColumnName() + ") VALUES ('" + variablePath + "', '" + typeDefn.getColumnNamesUser()[column] + "', '" + mod.getRowData()[column] + "'); ");
}
}
}
// Escape any PostgreSQL reserved characters so that the path can be used in a
// regular expression
String variablePathEsc = CcddUtilities.escapePostgreSQLReservedChars(variablePath);
// Step through each rate index
for (int rateIndex : mod.getRateColumn()) {
// Get the old and new rate values
String oldRate = mod.getOriginalRowData()[rateIndex].toString();
String newRate = mod.getRowData()[rateIndex].toString();
// Check if the rate changed
if (!oldRate.equals(newRate)) {
// Create the commands to delete the variable from the link and
// telemetry scheduler tables
deleteLinkAndTlmPathRef(mod.getRowData()[mod.getArraySizeColumn()].toString(), mod.getRowData()[mod.getVariableColumn()].toString(), variablePath, variablePathEsc, linksDelCmd, tlmDelCmd);
break;
}
}
}
}
// Check if a deletion to the links table exists
if (linksDelCmd.length() != 0) {
// Terminate the links table command and add it to the modification command
modCmd.append(linksDelCmd.toString());
}
// Check if a deletion to the telemetry scheduler table exists
if (tlmDelCmd.length() != 0) {
// Terminate the telemetry scheduler table command and add it to the modification
// command
modCmd.append(tlmDelCmd.toString());
}
}
return modCmd.toString();
}
use of CCDD.CcddClassesDataTable.TableModification in project CCDD by nasa.
the class CcddTableEditorHandler method buildUpdates.
/**
********************************************************************************************
* Compare the current table data to the committed table data and create lists of the changed
* values necessary to update the table in the database to match the current values
********************************************************************************************
*/
protected void buildUpdates() {
// value change)
if (editorDialog != null) {
// Store the description into the table information class so that it can be used to
// compare if a change occurred
tableInfo.setDescription(getDescription());
}
// Store the most recently committed table data and column order into the table information
// class so that it can be used to compare if a change occurred
tableInfo.setData(committedInfo.getData());
tableInfo.setColumnOrder(table.getColumnOrder());
// Remove change information from a previous commit, if any
additions.clear();
modifications.clear();
deletions.clear();
// Create an empty row of data for comparison purposes
Object[] emptyRow = table.getEmptyRow();
// Re-index the rows in case any have been added, moved, or deleted
updateRowIndices();
// Get the number of rows that have been committed to the database for this table
int numCommitted = committedInfo != null ? committedInfo.getData().length : 0;
// Get the table cell values
Object[][] tableData = table.getTableData(true);
// Create storage for the array used to indicate if a row has been modified
boolean[] rowModified = new boolean[committedInfo.getData().length];
// Step through each row in the table
for (int tblRow = 0; tblRow < tableData.length; tblRow++) {
boolean matchFound = false;
// data type columns are present, and the path isn't manually set
if (editorDialog != null && variablePathIndex != -1 && variableNameIndex != -1 && dataTypeIndex != -1 && tableData[tblRow][variablePathIndex].toString().equals(getVariablePath(tableData[tblRow][variableNameIndex].toString(), tableData[tblRow][dataTypeIndex].toString(), true))) {
// Blank the data for this column so that it isn't stored in the database (paths
// not manually entered by the user are constructed on-the-fly for display in the
// table)
tableData[tblRow][variablePathIndex] = "";
}
// Step through each row in the committed version of the table data
for (int comRow = 0; comRow < numCommitted && !matchFound; comRow++) {
// Check if the primary key values match for these rows
if (tableData[tblRow][primaryKeyIndex].equals(committedInfo.getData()[comRow][primaryKeyIndex])) {
// Set the flag indicating this row has a match
matchFound = true;
// Copy the current row's primary key and row index into the empty comparison
// row
emptyRow[primaryKeyIndex] = tableData[tblRow][primaryKeyIndex];
emptyRow[rowIndex] = tableData[tblRow][rowIndex];
// a row deletion instead of a modification)
if (!Arrays.equals(tableData[tblRow], emptyRow)) {
// Set the flag indicating this row has a modification
rowModified[comRow] = true;
// Step through each column in the row
for (int column = 0; column < tableData[tblRow].length; column++) {
// the variable path column
if (!tableData[tblRow][column].equals(committedInfo.getData()[comRow][column])) {
// Store the row modification information and stop searching
modifications.add(new TableModification(tableData[tblRow], committedInfo.getData()[comRow], variableNameIndex, dataTypeIndex, arraySizeIndex, bitLengthIndex, rateIndex));
break;
}
}
}
}
}
// Check if no matching row was found with the current data
if (!matchFound) {
// Store the row addition information
additions.add(new TableModification(tableData[tblRow], variableNameIndex, dataTypeIndex, arraySizeIndex, bitLengthIndex));
}
}
// Step through each row of the committed data
for (int comRow = 0; comRow < numCommitted; comRow++) {
// Check if no matching row was found with the current data
if (!rowModified[comRow]) {
// Store the row deletion information
deletions.add(new TableModification(committedInfo.getData()[comRow], variableNameIndex, dataTypeIndex, arraySizeIndex, bitLengthIndex));
}
}
}
use of CCDD.CcddClassesDataTable.TableModification in project CCDD by nasa.
the class CcddMacroEditorDialog method buildUpdates.
/**
********************************************************************************************
* Compare the current macro table data to the committed data and create lists of the changed
* values necessary to update the table in the database to match the current values
********************************************************************************************
*/
private void buildUpdates() {
// Remove change information from a previous commit, if any
modifications.clear();
// Get the number of rows that have been committed to the database
int numCommitted = committedData.length;
// Get the macro table cell values
String[][] tableData = CcddUtilities.convertObjectToString(macroTable.getTableData(true));
// Step through each row in the macro table
for (int tblRow = 0; tblRow < tableData.length; tblRow++) {
boolean matchFound = false;
// Step through each row in the committed version of the macro table data
for (int comRow = 0; comRow < numCommitted && !matchFound; comRow++) {
// Check if the index values match for these rows
if (tableData[tblRow][MacrosColumn.OID.ordinal()].equals(committedData[comRow][MacrosColumn.OID.ordinal()])) {
// Set the flags indicating this row has a match
matchFound = true;
boolean isChangedColumn = false;
// Step through each column in the row
for (int column = 0; column < tableData[tblRow].length; column++) {
// Check if the current and committed values don't match
if (!tableData[tblRow][column].equals(committedData[comRow][column])) {
// Set the flag to indicate a column value changed and stop searching
isChangedColumn = true;
break;
}
}
// Check if any columns were changed
if (isChangedColumn) {
// Store the row modification information
modifications.add(new TableModification(tableData[tblRow], committedData[comRow]));
}
}
}
}
}
Aggregations