protected void upgrade() throws Exception { LogFactory.getLog(DataServiceUpgradeFrom1pt5.class).debug("UPGRADING DATA FROM 1.5"); try { validateUpgrade(); updateDataLibraries(); upgradeStyle(); upgradeWsdls(); addInstanceCountResourceProperty(); setCurrentExtensionVersion(); getStatus().setStatus(StatusBase.UPGRADE_OK); } catch (UpgradeException ex) { getStatus().addDescriptionLine(ex.getMessage()); getStatus().setStatus(StatusBase.UPGRADE_FAIL); throw ex; } }
public DynamicDatabase upgradeSchema(final SourceMappings newConfig, final boolean keepData) throws DatabaseException { final DynamicDatabase newDatabase = new DynamicDatabase(newConfig); Logger.debuggerPrint("Starting upgrade task at " + new Date(System.currentTimeMillis())); try { schema.runUpgrade( newDatabase.schema, new UpgradeTask() { @Override public void execute(@NotNull DatabaseUpgradeAccess dbAccess) throws DatabaseException, SourceMappingNotFoundException, TableNotInDatabaseException { // add new tables for (TrendDataTable newDataTable : newDatabase.dataTables) { String tableName = newDataTable.getTableSchema().getName(); // set enabled // if (keepData != newConfig.isEnabled(tableName)) // metaDataTable.setEnabled(DynamicDatabase.this, tableName, // keepData); if (!dataTables.contains(newDataTable)) { Logger.debuggerPrint("Attempting to add table " + tableName); String displayName = newConfig.getDisplayNameFromTableName(tableName); String displayPath = newConfig.getDisplayPathFromTableName(tableName); String source = newConfig.getSourceFromTableName(tableName); short type = newConfig.getTypeFromTableName(tableName); boolean enabled = newConfig.getIsEnabled(tableName); if (source == null) { Logger.debuggerPrint( "Source (" + source + " ) does not exists for table " + tableName + " at " + displayPath); throw new DatabaseException("Source does not exist for table: " + tableName); } dbAccess.addTable(new TrendDataTable(schema, tableName, type).getTableSchema()); metaDataTable.insertRow( DynamicDatabase.this, source, displayName, displayPath, tableName, type, enabled); Logger.debuggerPrint("Table added successfully"); } } // drop old tables no longer needed for (TrendDataTable oldDataTable : dataTables) { if (!newDatabase.dataTables.contains(oldDataTable)) { // get the source to delete the row in the metadata table String tableName = oldDataTable.getTableSchema().getName(); Logger.debuggerPrint("Attempting to remove table " + tableName); Query q = buildSelect(DynamicDatabase.this.metaDataTable.referencePath) .where(DynamicDatabase.this.metaDataTable.tableName.eq(tableName)); Logger.debuggerPrint("Executing select statement " + q.toString()); Result r = dbAccess.execute(q); String source = null; if (r.next()) source = r.get(DynamicDatabase.this.metaDataTable.referencePath); if (source != null) { metaDataTable.setEnabled(DynamicDatabase.this, tableName, false); if (!keepData) { Logger.debuggerPrint("Attempting to drop table " + tableName); dbAccess.dropTable(oldDataTable.getTableSchema()); metaDataTable.deleteRow(DynamicDatabase.this, source); Logger.debuggerPrint("Table dropped successfully"); } } } } } }); } catch (UpgradeException e) { Logger.debuggerPrint( "UpgradeException caught...\n\n" + e.getMessage() + "\n\n" + e.getStackTrace().toString()); throw new DatabaseException("Error adding/removing tables to match new schema", e); } return newDatabase; }