From 348b80c29ae638ddbf7f920e70a9985658b851a7 Mon Sep 17 00:00:00 2001 From: dslaveykov Date: Thu, 22 Nov 2018 11:22:47 +0200 Subject: [PATCH] [Database][BackupRestore] Better handling which table to drop-recreate and which to delete. Also automatically get default schema for user and database --- .../ats/agent/core/ConfigurationParser.java | 11 +- .../database/AbstractEnvironmentHandler.java | 13 ++ .../database/MssqlEnvironmentHandler.java | 81 ++++---- .../database/MysqlEnvironmentHandler.java | 8 +- .../database/OracleEnvironmentHandler.java | 179 ++++++++++-------- .../environment/database/model/DbTable.java | 18 +- 6 files changed, 182 insertions(+), 128 deletions(-) diff --git a/agent/core/src/main/java/com/axway/ats/agent/core/ConfigurationParser.java b/agent/core/src/main/java/com/axway/ats/agent/core/ConfigurationParser.java index 7b90b614b..8ebf3ccd7 100644 --- a/agent/core/src/main/java/com/axway/ats/agent/core/ConfigurationParser.java +++ b/agent/core/src/main/java/com/axway/ats/agent/core/ConfigurationParser.java @@ -50,6 +50,7 @@ import com.axway.ats.core.dbaccess.DbConnection; import com.axway.ats.core.dbaccess.oracle.DbConnOracle; import com.axway.ats.core.utils.IoUtils; +import com.axway.ats.core.utils.StringUtils; import com.axway.ats.environment.AdditionalAction; import com.axway.ats.environment.EnvironmentUnit; import com.axway.ats.environment.database.DatabaseEnvironmentUnit; @@ -361,6 +362,14 @@ private EnvironmentUnit parseDbEnvironment( Node dbEnvironmentNode, if (dbChildNode.getNodeName().equals(TABLE)) { String tableName = dbChildNode.getAttributes().getNamedItem("name").getNodeValue(); + String schemaName = new String(); + String[] tableNames = tableName.split("\\."); + if(!StringUtils.isNullOrEmpty(tableName) && tableNames.length > 1) { + // Note that if the table name contains dot (.), even if the table name is escaped properly, according to the database server, + // we will consider the presence of dot as a sign that the table names is of the format . + schemaName = tableNames[0]; + tableName = tableNames[1]; + } String[] columnsToExclude = {}; if (dbChildNode.getAttributes().getNamedItem("columnsToExclude") != null) { @@ -370,7 +379,7 @@ private EnvironmentUnit parseDbEnvironment( Node dbEnvironmentNode, .split(","); } - DbTable dbTable = new DbTable(tableName, new String(), Arrays.asList(columnsToExclude)); + DbTable dbTable = new DbTable(tableName, schemaName, Arrays.asList(columnsToExclude)); // parse db table 'lock' attribute if (dbChildNode.getAttributes().getNamedItem("lock") != null) { diff --git a/environmentcleanup/src/main/java/com/axway/ats/environment/database/AbstractEnvironmentHandler.java b/environmentcleanup/src/main/java/com/axway/ats/environment/database/AbstractEnvironmentHandler.java index 0332e8bd4..8e3f2c932 100644 --- a/environmentcleanup/src/main/java/com/axway/ats/environment/database/AbstractEnvironmentHandler.java +++ b/environmentcleanup/src/main/java/com/axway/ats/environment/database/AbstractEnvironmentHandler.java @@ -327,6 +327,19 @@ public void setDropTables( boolean dropEntireTable ) { this.dropEntireTable = dropEntireTable; } + + /** + *

Whether to drop table can be specified by either {@link #setDropTables(boolean)} or {@link DbTable#setDropTable(boolean)}

+ * This method here wraps the logic that determines what must be done for a particular table + * */ + protected boolean shouldDropTable( DbTable table ) { + + if (table.isDropTable() == null) { + return dropEntireTable; + } else { + return table.isDropTable(); + } + } protected abstract void writeDeleteStatements( Writer fileWriter ) throws IOException; diff --git a/environmentcleanup/src/main/java/com/axway/ats/environment/database/MssqlEnvironmentHandler.java b/environmentcleanup/src/main/java/com/axway/ats/environment/database/MssqlEnvironmentHandler.java index 3fcde7305..12183cfa2 100644 --- a/environmentcleanup/src/main/java/com/axway/ats/environment/database/MssqlEnvironmentHandler.java +++ b/environmentcleanup/src/main/java/com/axway/ats/environment/database/MssqlEnvironmentHandler.java @@ -32,17 +32,18 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Scanner; import java.util.Map.Entry; +import java.util.Scanner; import org.apache.log4j.Logger; +import com.axway.ats.common.dbaccess.DbQuery; import com.axway.ats.common.systemproperties.AtsSystemProperties; -import com.axway.ats.config.exceptions.NoSuchPropertyException; import com.axway.ats.core.dbaccess.ColumnDescription; import com.axway.ats.core.dbaccess.ConnectionPool; import com.axway.ats.core.dbaccess.DbRecordValue; import com.axway.ats.core.dbaccess.DbRecordValuesList; +import com.axway.ats.core.dbaccess.DbReturnModes; import com.axway.ats.core.dbaccess.DbUtils; import com.axway.ats.core.dbaccess.MssqlColumnDescription; import com.axway.ats.core.dbaccess.exceptions.DbException; @@ -53,21 +54,19 @@ import com.axway.ats.environment.database.exceptions.ColumnHasNoDefaultValueException; import com.axway.ats.environment.database.exceptions.DatabaseEnvironmentCleanupException; import com.axway.ats.environment.database.model.DbTable; -import com.axway.ats.harness.config.CommonConfigurator; class MssqlEnvironmentHandler extends AbstractEnvironmentHandler { - // used to provide a default schema for mssql operations - // in no such property is found, ATS uses 'dbo' as a default schema - public static final String MSSQL_DEFAULT_SCHEMA = "mssql.default.schema"; - - private static final Logger LOG = Logger.getLogger(MssqlEnvironmentHandler.class); - private static final String HEX_PREFIX_STR = "0x"; + private static final Logger LOG = Logger.getLogger(MssqlEnvironmentHandler.class); + private static final String HEX_PREFIX_STR = "0x"; + private String defaultSchema = null; MssqlEnvironmentHandler( DbConnSQLServer dbConnection, MssqlDbProvider dbProvider ) { super(dbConnection, dbProvider); + + defaultSchema = getDefaultSchema(); } @Override @@ -77,7 +76,7 @@ protected List getColumnsToSelect( ColumnHasNoDefaultValueException { String fullTableName = table.getFullTableName(); - + String selectColumnsInfo = "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE, " + "columnproperty(object_id('" + fullTableName @@ -140,7 +139,7 @@ protected void writeTableToFile( + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } - if (this.dropEntireTable) { + if (shouldDropTable(table)) { fileWriter.write(DROP_TABLE_MARKER + fullTableName + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } else if (!this.deleteStatementsInserted) { @@ -231,6 +230,9 @@ protected void writeDeleteStatements( Writer fileWriter ) throws IOException { if (this.includeDeleteStatements) { for (Entry entry : dbTables.entrySet()) { DbTable dbTable = entry.getValue(); + if (shouldDropTable(dbTable)) { + continue; + } String fullTableName = null; if (dbTable != null) { fullTableName = dbTable.getFullTableName(); @@ -289,33 +291,17 @@ private StringBuilder extractValue( } @Override - public void createBackup( String backupFileName ) throws DatabaseEnvironmentCleanupException { - - String defaultSchema = null; - try { - // get the default schema provided by the user - defaultSchema = CommonConfigurator.getInstance().getProperty(MSSQL_DEFAULT_SCHEMA); - if (StringUtils.isNullOrEmpty(defaultSchema)) { - // user had provided an empty string. Consider this an configuration error and use default mssql schema value (dbo) instead - LOG.warn("Provided '" + MSSQL_DEFAULT_SCHEMA - + "' property has empty value. We will use 'dbo' as a default one instead"); - defaultSchema = "dbo"; - } - } catch (NoSuchPropertyException nspe) { - // no user provided default schema found. Fall back to dbo - defaultSchema = "dbo"; - } + public void addTable( DbTable table ) { - // apply that schema to each table that has no schema specified - for (DbTable dbTable : dbTables.values()) { - if (dbTable != null) { // prevent NPE - if (StringUtils.isNullOrEmpty(dbTable.getTableSchema())) { // check if the table DOES NOT have schema already specified - dbTable.setTableSchema(defaultSchema); + if (!StringUtils.isNullOrEmpty(defaultSchema)) { + // apply that schema to each table that has no schema specified + if (table != null) { // prevent NPE + if (StringUtils.isNullOrEmpty(table.getTableSchema())) { // check if the table DOES NOT have schema already specified + table.setTableSchema(defaultSchema); } } } - - super.createBackup(backupFileName); + super.addTable(table); } /** @@ -410,6 +396,33 @@ public void restore( } } + /** + *

Get the default schema for the current user and database.

+ * */ + private String getDefaultSchema() { + + // get user's default schema + String query = "SELECT default_schema_name FROM sys.database_principals WHERE type = 'S' and name = '" + + dbProvider.getDbConnection().getUser() + "'"; + DbRecordValuesList[] defaultSchemaVal = dbProvider.select(new DbQuery(query), + DbReturnModes.ESCAPED_STRING); + if (defaultSchemaVal.length > 0) { + DbRecordValuesList firstVal = defaultSchemaVal[0]; + if (firstVal != null) { + String defaultSchema = (String) firstVal.get("default_schema_name"); + if (!StringUtils.isNullOrEmpty(defaultSchema)) { + LOG.info("Set default schema to '" + defaultSchema + + "'. Tables that do not have schema specified will be assigned to that schema." + + " Tables that do have provided schema will not be affected by that."); + return defaultSchema; + } + } + } + + return null; + + } + private void dropAndRecreateTable( Connection connection, String tableName ) { List generateForeignKeysScripts = new ArrayList(); diff --git a/environmentcleanup/src/main/java/com/axway/ats/environment/database/MysqlEnvironmentHandler.java b/environmentcleanup/src/main/java/com/axway/ats/environment/database/MysqlEnvironmentHandler.java index c75fab572..9ebe5f193 100644 --- a/environmentcleanup/src/main/java/com/axway/ats/environment/database/MysqlEnvironmentHandler.java +++ b/environmentcleanup/src/main/java/com/axway/ats/environment/database/MysqlEnvironmentHandler.java @@ -212,10 +212,12 @@ protected void writeTableToFile( DbTable table, DbRecordValuesList[] records, Writer fileWriter ) throws IOException { - - if (this.dropEntireTable) { + + boolean writeDeleteStatementForCurrTable = true; + if (shouldDropTable(table)) { fileWriter.write(DROP_TABLE_MARKER + table.getTableSchema() + "." + table.getTableName() + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); + writeDeleteStatementForCurrTable = false; } /*else if (!this.deleteStatementsInserted) { writeDeleteStatements(fileWriter); }*/ @@ -227,7 +229,7 @@ protected void writeTableToFile( fileWriter.write("LOCK TABLES `" + table.getTableName() + "` WRITE;" + EOL_MARKER + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } - if (this.includeDeleteStatements) { + if (this.includeDeleteStatements && writeDeleteStatementForCurrTable) { fileWriter.write("DELETE FROM `" + table.getTableName() + "`;" + EOL_MARKER + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } diff --git a/environmentcleanup/src/main/java/com/axway/ats/environment/database/OracleEnvironmentHandler.java b/environmentcleanup/src/main/java/com/axway/ats/environment/database/OracleEnvironmentHandler.java index f6cb1fdcf..b780516b4 100644 --- a/environmentcleanup/src/main/java/com/axway/ats/environment/database/OracleEnvironmentHandler.java +++ b/environmentcleanup/src/main/java/com/axway/ats/environment/database/OracleEnvironmentHandler.java @@ -78,9 +78,9 @@ protected List getColumnsToSelect( try { columnsMetaData = this.dbProvider.select(selectColumnsInfo); } catch (DbException e) { - throw new DbException("Could not get columns for table " + table.getTableName() - + ". You may check if the table exists, if the you are using the right user and it has the right permissions. See more details in the trace.", - e); + throw new DbException("Could not get columns for table " + table.getTableName() + + ". You may check if the table exists, if the you are using the right user and it has the right permissions. See more details in the trace.", + e); } if (columnsMetaData.length == 0) { @@ -121,11 +121,11 @@ protected void writeTableToFile( // TODO : exclusive table locks START - if( this.dropEntireTable ) { - fileWriter.write( DROP_TABLE_MARKER + table.getTableSchema() + "." + table.getTableName() - + AtsSystemProperties.SYSTEM_LINE_SEPARATOR ); - } else if( !this.deleteStatementsInserted ) { - writeDeleteStatements( fileWriter ); + if (shouldDropTable(table)) { + fileWriter.write(DROP_TABLE_MARKER + table.getTableSchema() + "." + table.getTableName() + + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); + } else if (!this.deleteStatementsInserted) { + writeDeleteStatements(fileWriter); } /* @@ -247,17 +247,23 @@ protected void writeTableToFile( @Override protected void writeDeleteStatements( Writer fileWriter ) throws IOException { - if( this.addLocks ) { - for( Entry entry : dbTables.entrySet() ) { + if (this.addLocks) { + for (Entry entry : dbTables.entrySet()) { DbTable dbTable = entry.getValue(); - fileWriter.write( "LOCK TABLE " + dbTable.getTableName() + " IN EXCLUSIVE MODE NOWAIT;" - + EOL_MARKER + AtsSystemProperties.SYSTEM_LINE_SEPARATOR ); + if (shouldDropTable(dbTable)) { + continue; + } + fileWriter.write("LOCK TABLE " + dbTable.getTableName() + " IN EXCLUSIVE MODE NOWAIT;" + + EOL_MARKER + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } } - + if (this.includeDeleteStatements) { for (Entry entry : dbTables.entrySet()) { DbTable dbTable = entry.getValue(); + if (shouldDropTable(dbTable)) { + continue; + } fileWriter.write("DELETE FROM " + dbTable.getTableName() + ";" + EOL_MARKER + AtsSystemProperties.SYSTEM_LINE_SEPARATOR); } @@ -356,16 +362,17 @@ public void restore( String backupFileName ) throws DatabaseEnvironmentCleanupEx while (line != null) { sql.append(line); - if( line.startsWith( DROP_TABLE_MARKER ) ) { - - String table = line.substring( DROP_TABLE_MARKER.length() ).trim(); - String owner = table.substring( 0, table.indexOf( "." ) ); - String simpleTableName = table.substring( table.indexOf( "." ) + 1 ); - dropAndRecreateTable( connection, simpleTableName, owner ); - + if (line.startsWith(DROP_TABLE_MARKER)) { + + String table = line.substring(DROP_TABLE_MARKER.length()).trim(); + String owner = table.substring(0, table.indexOf(".")); + String simpleTableName = table.substring(table.indexOf(".") + 1); + dropAndRecreateTable(connection, simpleTableName, owner); + sql = new StringBuilder(); - - } if (line.endsWith(EOL_MARKER)) { + + } + if (line.endsWith(EOL_MARKER)) { // remove the EOL marker and the trailing semicolon because, strangely, Oracle JDBC driver // does not require it, as opposing to any other, excluding blocks ([DECLARE]BEGIN-END;) @@ -383,7 +390,7 @@ public void restore( String backupFileName ) throws DatabaseEnvironmentCleanupEx } catch (SQLException sqle) { //we have to roll back the transaction and re throw the exception connection.rollback(); - throw new SQLException ("Error invoking restore satement: " + sql.toString(), sqle); + throw new SQLException("Error invoking restore satement: " + sql.toString(), sqle); } finally { try { updateStatement.close(); @@ -412,7 +419,7 @@ public void restore( String backupFileName ) throws DatabaseEnvironmentCleanupEx throw sqle; } - log.info("Completed restore of database backup from file '" + backupFileName + "'"); + log.info("Completed restore of database backup from file '" + backupFileName + "'"); } catch (IOException ioe) { throw new DatabaseEnvironmentCleanupException(ERROR_RESTORING_BACKUP + backupFileName, ioe); @@ -434,86 +441,87 @@ public void restore( String backupFileName ) throws DatabaseEnvironmentCleanupEx } } } - + public void dropAndRecreateTable( Connection connection, String tableName, String owner ) { List generateForeignKeysScripts = new ArrayList(); - Map> foreignKeys = getForeingKeys( owner, tableName, connection ); + Map> foreignKeys = getForeingKeys(owner, tableName, connection); // generate script for restoring the exact table - String generateTableScript = generateTableScript( owner, tableName, connection ); + String generateTableScript = generateTableScript(owner, tableName, connection); - for( Entry> entryKey : foreignKeys.entrySet() ) { + for (Entry> entryKey : foreignKeys.entrySet()) { String parentTableName = entryKey.getKey(); - for( String key : entryKey.getValue() ) { + for (String key : entryKey.getValue()) { // generate scripts for creating all foreign keys - generateForeignKeysScripts.add( generateForeignKeyScript( owner, key, connection ) ); + generateForeignKeysScripts.add(generateForeignKeyScript(owner, key, connection)); // disable the foreign keys - executeUpdate( "ALTER TABLE " + owner + "." + parentTableName + " DISABLE CONSTRAINT " + key, - connection ); + executeUpdate("ALTER TABLE " + owner + "." + parentTableName + " DISABLE CONSTRAINT " + key, + connection); } } // drop the table - executeUpdate( "DROP TABLE " + tableName + " CASCADE CONSTRAINTS PURGE", connection ); + executeUpdate("DROP TABLE " + tableName + " CASCADE CONSTRAINTS PURGE", connection); // create new table - executeUpdate( generateTableScript, connection ); + executeUpdate(generateTableScript, connection); // create all the missing foreign keys - for( String script : generateForeignKeysScripts ) { - executeUpdate( script, connection ); + for (String script : generateForeignKeysScripts) { + executeUpdate(script, connection); } // enable the foreign keys - for( Entry> entryKey : foreignKeys.entrySet() ) { + for (Entry> entryKey : foreignKeys.entrySet()) { String parentTableName = entryKey.getKey(); - for( String key : entryKey.getValue() ) { - executeUpdate( "ALTER TABLE " + owner + "." + parentTableName + " ENABLE CONSTRAINT " + key, - connection ); + for (String key : entryKey.getValue()) { + executeUpdate("ALTER TABLE " + owner + "." + parentTableName + " ENABLE CONSTRAINT " + key, + connection); } } } - + private Map> getForeingKeys( String owner, String tableName, Connection connection ) { String query = "select table_name, constraint_name " - + " from all_constraints " - + " where r_owner = '" + owner + "' " - + " and constraint_type = 'R' " - + " and r_constraint_name in " - + " ( select constraint_name from all_constraints " - + " where constraint_type in ('P', 'U') " - + " and table_name = '" + tableName + "'" - + " and owner = '" + owner + "' )"; - + + " from all_constraints " + + " where r_owner = '" + owner + "' " + + " and constraint_type = 'R' " + + " and r_constraint_name in " + + " ( select constraint_name from all_constraints " + + " where constraint_type in ('P', 'U') " + + " and table_name = '" + tableName + "'" + + " and owner = '" + owner + "' )"; + PreparedStatement stmnt = null; Map> tableForeignKey = new HashMap>(); ResultSet rs = null; try { - stmnt = connection.prepareStatement( query ); + stmnt = connection.prepareStatement(query); rs = stmnt.executeQuery(); - while( rs.next() ) { - String parentTableName = rs.getString( "TABLE_NAME" ); - String fKeyName = rs.getString( "CONSTRAINT_NAME" ); + while (rs.next()) { + String parentTableName = rs.getString("TABLE_NAME"); + String fKeyName = rs.getString("CONSTRAINT_NAME"); - if( tableForeignKey.containsKey( parentTableName ) ) { - tableForeignKey.get( parentTableName ).add( fKeyName ); + if (tableForeignKey.containsKey(parentTableName)) { + tableForeignKey.get(parentTableName).add(fKeyName); } else { List fKeys = new ArrayList(); - fKeys.add( fKeyName ); + fKeys.add(fKeyName); } } return tableForeignKey; - } catch( SQLException e ) { - throw new DbException( - "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + e.getMessage(), e); + } catch (SQLException e) { + throw new DbException( + "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + + e.getMessage(), e); } finally { - DbUtils.closeStatement( stmnt ); + DbUtils.closeStatement(stmnt); } } - + private String generateTableScript( String owner, String tableName, Connection connection ) { String query = "select dbms_metadata.get_ddl('TABLE','" + tableName + "','" + owner + "') from dual"; @@ -522,23 +530,24 @@ private String generateTableScript( String owner, String tableName, Connection c ResultSet rs = null; String createTableScript = new String(); try { - stmnt = connection.prepareStatement( query ); + stmnt = connection.prepareStatement(query); rs = stmnt.executeQuery(); - if( rs.next() ) { - createTableScript = rs.getString( 1 ); + if (rs.next()) { + createTableScript = rs.getString(1); } return createTableScript; - } catch( SQLException e ) { - throw new DbException( - "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + e.getMessage(), e); + } catch (SQLException e) { + throw new DbException( + "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + + e.getMessage(), e); } finally { - DbUtils.closeStatement( stmnt ); + DbUtils.closeStatement(stmnt); } } - + private String generateForeignKeyScript( String owner, String foreignKey, Connection connection ) { - + String query = "select DBMS_METADATA.GET_DDL('REF_CONSTRAINT','" + foreignKey + "','" + owner + "') from dual"; @@ -546,32 +555,34 @@ private String generateForeignKeyScript( String owner, String foreignKey, Connec ResultSet rs = null; String createTableScript = new String(); try { - stmnt = connection.prepareStatement( query ); + stmnt = connection.prepareStatement(query); rs = stmnt.executeQuery(); - if( rs.next() ) { - createTableScript = rs.getString( 1 ); + if (rs.next()) { + createTableScript = rs.getString(1); } return createTableScript; - } catch( SQLException e ) { - throw new DbException( - "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + e.getMessage(), e); + } catch (SQLException e) { + throw new DbException( + "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + + e.getMessage(), e); } finally { - DbUtils.closeStatement( stmnt ); + DbUtils.closeStatement(stmnt); } } - + private void executeUpdate( String query, Connection connection ) throws DbException { PreparedStatement stmnt = null; try { - stmnt = connection.prepareStatement( query ); + stmnt = connection.prepareStatement(query); stmnt.executeUpdate(); - } catch( SQLException e ) { - throw new DbException( - "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + e.getMessage(), e); + } catch (SQLException e) { + throw new DbException( + "SQL errorCode=" + e.getErrorCode() + " sqlState=" + e.getSQLState() + " " + + e.getMessage(), e); } finally { - DbUtils.closeStatement( stmnt ); + DbUtils.closeStatement(stmnt); } } } diff --git a/environmentcleanup/src/main/java/com/axway/ats/environment/database/model/DbTable.java b/environmentcleanup/src/main/java/com/axway/ats/environment/database/model/DbTable.java index c73ac32f9..a4c79126f 100644 --- a/environmentcleanup/src/main/java/com/axway/ats/environment/database/model/DbTable.java +++ b/environmentcleanup/src/main/java/com/axway/ats/environment/database/model/DbTable.java @@ -18,19 +18,24 @@ import java.util.ArrayList; import java.util.List; +import com.axway.ats.common.PublicAtsApi; import com.axway.ats.core.utils.StringUtils; /** * Class representing a single database table - it holds the name * of the table and the columns which to exclude from the backup */ +@PublicAtsApi public class DbTable { private String tableName; private String schema; private List columnsToExclude; private boolean lockTable = true; - private boolean dropTable = false; + /** + * Whether to drop table. If true - > then drop, else if false -> no, else (null) user did not specify it. + * */ + private Boolean dropTable = null; private boolean identityColumnPresent = false; private String autoIncrementResetValue; @@ -67,7 +72,7 @@ public DbTable( String tableName, String schema, List columnsToExclude ) { - this(tableName, schema, columnsToExclude, true, false); + this(tableName, schema, columnsToExclude, true, null); } /** @@ -81,7 +86,7 @@ public DbTable( String tableName, public DbTable( String tableName, String schema, boolean lockTable, - boolean dropTable ) { + Boolean dropTable ) { this(tableName, schema, new ArrayList(), lockTable, dropTable); } @@ -99,7 +104,7 @@ public DbTable( String tableName, String schema, List columnsToExclude, boolean lockTable, - boolean dropTable ) { + Boolean dropTable ) { this.tableName = tableName; this.schema = schema; @@ -180,10 +185,11 @@ public void setLockTable( } /** - * + *

Get whether to drop table

+ *

Note: If not defined, it will be null

* @return if the table will be recreated or not during the restore process */ - public boolean isDropTable() { + public Boolean isDropTable() { return dropTable; }