use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseDumper method finalizeDumpFile.
private void finalizeDumpFile(String filename, String dataSourceName, String backupSubFolder, File tempFile) throws ApsSystemException {
try {
StringBuilder dirName = new StringBuilder(this.getLocalBackupsFolder());
if (null != backupSubFolder) {
dirName.append(backupSubFolder).append(File.separator);
}
dirName.append(dataSourceName).append(File.separator);
InputStream is = new FileInputStream(new File(tempFile.getAbsolutePath()));
this.save(filename, dirName.toString(), is);
} catch (ApsSystemException | IOException t) {
_logger.error("Error saving dump file '{}'", tempFile.getName(), t);
throw new ApsSystemException("Error saving dump file '" + tempFile.getName() + "'", t);
} finally {
if (null != tempFile) {
tempFile.delete();
}
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseDumper method dumpTableData.
protected void dumpTableData(String tableName, String dataSourceName, DataSource dataSource, DataSourceDumpReport report, String backupSubFolder) throws ApsSystemException {
String filename = tableName + ".sql";
File tempFile = null;
FileWriter fileWriter = null;
BufferedWriter bufferWriter = null;
try {
tempFile = this.createEmptyTempFile(filename);
fileWriter = new FileWriter(tempFile.getAbsolutePath());
bufferWriter = new BufferedWriter(fileWriter);
TableDumpReport tableDumpReport = TableDataUtils.dumpTable(bufferWriter, dataSource, tableName);
report.addTableReport(dataSourceName, tableDumpReport);
} catch (IOException t) {
_logger.error("Error dumping table '{}' - datasource '{}'", tableName, dataSourceName, t);
throw new ApsSystemException("Error dumping table '" + tableName + "' - datasource '" + dataSourceName + "'", t);
} finally {
try {
if (null != bufferWriter) {
bufferWriter.close();
}
if (null != fileWriter) {
fileWriter.close();
}
} catch (IOException t2) {
_logger.error("Error closing FileWriter and BufferedWriter of file '{}'", filename, t2);
throw new ApsSystemException("Error closing FileWriter and BufferedWriter", t2);
}
}
this.finalizeDumpFile(filename, dataSourceName, backupSubFolder, tempFile);
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseDumper method save.
protected void save(String filename, String folder, InputStream is) throws ApsSystemException {
try {
IStorageManager storageManager = this.getStorageManager();
String path = folder + filename;
storageManager.saveFile(path, true, is);
} catch (Throwable t) {
_logger.error("Error saving backup '{}'", filename, t);
throw new ApsSystemException("Error saving backup '" + filename + "'", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseManager method readFile.
private String readFile(Resource resource) throws Throwable {
if (resource == null) {
return null;
}
InputStream is = null;
String text = null;
try {
is = resource.getInputStream();
if (null == is) {
return null;
}
text = FileTextReader.getText(is, "UTF-8");
} catch (Throwable t) {
logger.error("Error reading resource", t);
throw new ApsSystemException("Error reading resource", t);
} finally {
if (null != is) {
is.close();
}
}
return text;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseManager method restoreDefaultDump.
private void restoreDefaultDump() throws ApsSystemException {
try {
String[] dataSourceNames = this.extractBeanNames(DataSource.class);
Map<String, Resource> defaultDump = this.getDefaultSqlDump();
if (null == defaultDump || defaultDump.isEmpty()) {
return;
}
for (String dataSourceName : dataSourceNames) {
DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
Resource resource = defaultDump.get(dataSourceName);
String script = this.readFile(resource);
if (null != script && script.trim().length() > 0) {
this.getDatabaseRestorer().initOracleSchema(dataSource);
TableDataUtils.valueDatabase(script, dataSourceName, dataSource, null);
}
}
} catch (Throwable t) {
logger.error("Error restoring default Dump", t);
throw new ApsSystemException("Error restoring default Dump", t);
}
}
Aggregations