r403 - trunk/echobase-services/src/main/java/fr/ifremer/echobase/services
Author: tchemit Date: 2012-03-23 11:34:52 +0100 (Fri, 23 Mar 2012) New Revision: 403 Url: http://forge.codelutin.com/repositories/revision/echobase/403 Log: improve create embedded application memory footprint Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-03-23 10:34:10 UTC (rev 402) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-03-23 10:34:52 UTC (rev 403) @@ -121,17 +121,29 @@ } catch (Exception eee) { throw new EchoBaseTechnicalException("Could not create h2 embedded database at " + dir, eee); } finally { - try { - rootContext.closeContext(); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException("Could not close h2 embedded database at " + dir, eee); - } + closeContext(rootContext, "Could not close h2 embedded database at " + dir); } EchoBaseIOUtil.compressZipFile(zipFile, dir); return zipFile; } + protected void closeContext(TopiaContext tx, String message) { + try { + tx.closeContext(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(message, eee); + } + } + + protected TopiaContext beginTransaction(TopiaContext tx, String message) { + try { + return tx.beginTransaction(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(message, eee); + } + } + protected int computeNbSteps(EmbeddedApplicationConfiguration model) { int nbSteps = 4; @@ -176,10 +188,20 @@ File exportTempDir = new File(tempDirectory, "exportDb"); exportconfiguration.setWorkingDirectory(exportTempDir); exportconfiguration.setVoyageIds(model.getVoyageIds()); + TopiaContext transaction = serviceContext.getTransaction(); - ExportDbService exportDbService = - serviceContext.newService(ExportDbService.class); - exportDbService.exportPartialDb(exportconfiguration, false); + TopiaContext newTx = beginTransaction( + transaction, + "Could not begin transaction on main db"); + try { + serviceContext.setTransaction(newTx); + ExportDbService exportDbService = + serviceContext.newService(ExportDbService.class); + exportDbService.exportPartialDb(exportconfiguration, false); + } finally { + serviceContext.setTransaction(transaction); + closeContext(newTx, "Could not close transaction on main db"); + } File exportZipFile = exportconfiguration.getExportFile(); if (log.isInfoEnabled()) { log.info("Export zip file = " + exportZipFile);
participants (1)
-
tchemit@users.forge.codelutin.com