Author: tchemit Date: 2013-12-17 02:53:04 +0100 (Tue, 17 Dec 2013) New Revision: 919 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/919 Log: change migration callback Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallback.java trunk/echobase-services/src/main/resources/postgis-structure.sql Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallback.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallback.java 2013-12-17 01:45:38 UTC (rev 918) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/workingDb/MigrationCallback.java 2013-12-17 01:53:04 UTC (rev 919) @@ -25,10 +25,19 @@ import fr.ifremer.echobase.entities.EchoBaseDAOHelper; import fr.ifremer.echobase.persistence.migration.EchoBaseMigrationCallBackResolver; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.jdbc.Work; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG; +import org.nuiton.util.StringUtil; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.List; /** @@ -39,6 +48,9 @@ */ public class MigrationCallback extends TopiaMigrationCallbackByClassNG { + /** Logger. */ + private static final Log log = LogFactory.getLog(MigrationCallback.class); + public MigrationCallback() { super(EchoBaseMigrationCallBackResolver.newResolver( fr.ifremer.echobase.persistence.migration.workingDb.MigrationCallBackForVersion.class)); @@ -53,4 +65,62 @@ public boolean askUser(Version version, List<Version> versions) { return true; } + + @Override + public void executeSQL(TopiaContext tx, final boolean showSql, final boolean showProgression, final String... sqls) throws TopiaException { + if (log.isInfoEnabled()) { + + log.info(String.format("Will execute %1$s requests...", sqls.length)); + } + if (showSql) { + StringBuilder buffer = new StringBuilder(); + for (String s : sqls) { + buffer.append(s).append("\n"); + } + log.info("SQL TO EXECUTE :\n" + + "--------------------------------------------------------------------------------\n" + + "--------------------------------------------------------------------------------\n" + + buffer.toString() + + "--------------------------------------------------------------------------------\n" + + "--------------------------------------------------------------------------------\n" + ); + } + tx.getHibernateSession().doWork(new Work() { + + @Override + public void execute(Connection connection) throws SQLException { + int index = 0; + int max = sqls.length; + for (String sql : sqls) { + index++; + long t0 = System.nanoTime(); + if (log.isInfoEnabled()) { + String message = ""; + + if (showProgression) { + message = String.format("Executing request [%1$-4s/%2$-4s]", index, max); + } + if (showSql) { + message += "\n" + sql; + } + if (showProgression || showSql) { + + log.info(message); + } + } + PreparedStatement sta = connection.prepareStatement(sql); + try { + sta.execute(); + } finally { + sta.close(); + } + if (log.isDebugEnabled()) { + String message; + message = String.format("Request [%1$-4s/%2$-4s] executed in %3$s.", index, max, StringUtil.convertTime(System.nanoTime() - t0)); + log.debug(message); + } + } + } + }); + } } Modified: trunk/echobase-services/src/main/resources/postgis-structure.sql =================================================================== --- trunk/echobase-services/src/main/resources/postgis-structure.sql 2013-12-17 01:45:38 UTC (rev 918) +++ trunk/echobase-services/src/main/resources/postgis-structure.sql 2013-12-17 01:53:04 UTC (rev 919) @@ -1214,8 +1214,8 @@ -- Compute all data --- SELECT echobase_compute_all_cell_spatial_data(); --- SELECT echobase_compute_all_operation_spatial_data(); +SELECT echobase_compute_all_cell_spatial_data(); +SELECT echobase_compute_all_operation_spatial_data(); -- Add an update query as the migration service will execute this script and can't finish with a query instruction (see PreparedStatement#executeUpdate) -- UPDATE echobase_operation_spatial SET lastUpdateDate = now() WHERE operationid IS NULL; \ No newline at end of file