logOutputTextArea.setText(""); //clean old output
// flag to indicates if the user want clean also the ARCHIVE tables
boolean cleanArchiveTable = cleanArchiveTableSubPanel.getEnableArchiveCleaningCheckBox().isSelected();
DatabaseCleaner databaseCleaner = new DatabaseCleaner();
DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
/* the TOTAL tables to clean */
int tableToClean = databaseTableUtils.getTableCount();
logOutputTextArea.setBorder(BorderFactory.createLineBorder(Color.black)); //reset some error
logOutputTextArea.setText("Database analisys started...\n");
logOutputTextArea.append("Total database tables: "+tableToClean+"\n");
/* ALL the database tables */
List<String> allTables = databaseTableUtils.getTableNamesOrdered();
/* the tables with 'ARCHIVE' engine type */
List<String> archiveTables = databaseTableUtils.getArchiveTables();
//the tables without the Archive type ones
List<String> effectiveTablesToClean = new ArrayList<String>();
long startTime = 0;
long endTime = 0;
logOutputTextArea.append("Checking the presence of tables with unsupported store engine (ie 'ARCHIVE')...\n");
if(!archiveTables.isEmpty()) // found Archive tables
{
if(cleanArchiveTable)
{
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.info("User want clean also the ARCHIVE tables");
logOutputTextArea.append("* ATTENTION * Found "+archiveTables.size()+" tables with 'ARCHIVE' engine: trying to clean them changing engine type... \n");
logOutputTextArea.append("Total tables to clean: "+tableToClean+"\n");
// change the engine type of the ARCHIVE tables
for(int i=0;i<archiveTables.size();i++)
{
databaseTableUtils.changeTableEngine(archiveTables.get(i),"InnoDB");
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.debug("Changed the engine type of table "+archiveTables.get(i)+" to InnoDB");
}
// clean ALL the tables
startTime = System.currentTimeMillis();
databaseCleaner.deleteAll(allTables.toArray(new String[]{}));
endTime = System.currentTimeMillis();
}else{ // User don't want clean Archive tables
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.info("The user DON'T want clean the ARCHIVE tables");
logOutputTextArea.append("* ATTENTION * Found "+archiveTables.size()+" tables with 'ARCHIVE' engine: they will not be cleaned (See Mysql doc) !\n");
logOutputTextArea.append("Total tables cleanable: "+(tableToClean-archiveTables.size())+"\n");
logOutputTextArea.append("Database cleaning started...\n");
// remove tables with a storage engine that don't support the sql 'delete' operation (ie 'ARCHIVE' engine )
for(int i=0;i<allTables.size();i++)
{
if(!archiveTables.contains(allTables.get(i)))
effectiveTablesToClean.add(allTables.get(i));
}
// clean only the NON-ARCHIVE tables
startTime = System.currentTimeMillis();
databaseCleaner.deleteAll(effectiveTablesToClean.toArray(new String[]{}));
endTime = System.currentTimeMillis();
}
}else{
logOutputTextArea.append("No tables found with 'ARCHIVE' engine \n");
logOutputTextArea.append("Total tables cleanable: "+allTables.size()+"\n");
logOutputTextArea.append("Database cleaning started...\n");
startTime = System.currentTimeMillis();
databaseCleaner.deleteAll(allTables.toArray(new String[]{}));
endTime = System.currentTimeMillis();
}
/* Restore the previously modified engine type from InnoDB to ARCHIVE */
if(cleanArchiveTable)