r509 - trunk/echobase-services/src/main/java/fr/ifremer/echobase/services
Author: tchemit Date: 2012-04-10 10:26:30 +0200 (Tue, 10 Apr 2012) New Revision: 509 Url: http://forge.codelutin.com/repositories/revision/echobase/509 Log: rollback transaction if something was wrong 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-04-06 20:36:22 UTC (rev 508) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-04-10 08:26:30 UTC (rev 509) @@ -95,9 +95,10 @@ TopiaContext rootContext = new EchoBaseTopiaRootContextFactory().newEmbeddedDatabase(dir); + TopiaContext topiaContext = null; try { - TopiaContext topiaContext = rootContext.beginTransaction(); + topiaContext = rootContext.beginTransaction(); model.incrementsProgression(); @@ -118,6 +119,9 @@ } catch (Exception eee) { + rollbackTransaction( + topiaContext, + "Could not rollback h2 embedded database at " + dir); throw new EchoBaseTechnicalException( "Could not create h2 embedded database at " + dir, eee); } finally { @@ -151,6 +155,18 @@ } } + protected void rollbackTransaction(TopiaContext tx, String message) { + try { + if (tx!=null) { + tx.rollbackTransaction(); + } + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error(message, eee); + } + } + } + protected int computeNbSteps(EmbeddedApplicationConfiguration model) { int nbSteps = 4; @@ -205,6 +221,16 @@ ExportDbService exportDbService = serviceContext.newService(ExportDbService.class); exportDbService.exportPartialDb(exportconfiguration, false); + } catch (IOException eee) { + rollbackTransaction( + newTx, + "Could not rollback transaction on db"); + throw eee; + } catch (RuntimeException eee) { + rollbackTransaction( + newTx, + "Could not rollback transaction on db"); + throw eee; } finally { serviceContext.setTransaction(transaction); closeContext(newTx, "Could not close transaction on main db");
participants (1)
-
tchemit@users.forge.codelutin.com