use of org.motechproject.mds.exception.entity.DataMigrationFailedException in project motech by motech.
the class ComboboxDataMigrationHelper method migrateDataToSingleSelectTable.
private void migrateDataToSingleSelectTable(String dstTable, String field) throws DataMigrationFailedException {
String srcTable = dstTable + "_" + field.toUpperCase();
String mdsDataBase = mdsConfig.getDataDatabaseName();
try {
if (!sqlDBManager.hasColumn(mdsDataBase, dstTable, field)) {
LOGGER.info(String.format("Adding column %s to table %s.", field, dstTable));
executeQuery(prepareAddColumnQuery(dstTable, field));
}
LOGGER.info(String.format("Migrating data from table %s to table %s.", srcTable, dstTable));
executeQuery(prepareMigrationToSingleSelectQuery(srcTable, dstTable, field));
} catch (JDOException | SQLException e) {
throw new DataMigrationFailedException(String.format("Error while migrating data to from %s to %s.", srcTable, dstTable), e);
}
}
use of org.motechproject.mds.exception.entity.DataMigrationFailedException in project motech by motech.
the class ComboboxDataMigrationHelper method migrateDataToMultiSelectTable.
private void migrateDataToMultiSelectTable(String srcTable, String field) throws DataMigrationFailedException {
String dstTable = srcTable + "_" + field.toUpperCase();
try {
LOGGER.info(String.format("Creating table %s if it doesn't exists.", dstTable));
executeQuery(prepareCreateTableQuery(dstTable, field));
LOGGER.info(String.format("Clearing table %s.", dstTable));
executeQuery(prepareClearTableQuery(dstTable));
LOGGER.info(String.format("Migrating data from table %s to table %s.", srcTable, dstTable));
executeQuery(prepareMigrationToMultiSelectQuery(srcTable, dstTable, field));
LOGGER.info(String.format("Dropping column %s in table %s.", field, srcTable));
executeQuery(prepareDropColumnQuery(srcTable, field));
} catch (JDOException e) {
throw new DataMigrationFailedException(String.format("Error migrating single-select data from %s to %s.", srcTable, dstTable), e);
}
}
Aggregations