/**
 * Copyright (C) 2011 LShift Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.lshift.hibernate.migrations;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

abstract public class TraceableMigrationElement implements MigrationElement {

  static Logger log = LoggerFactory.getLogger(TraceableMigrationElement.class);

  private List<String> statements = new ArrayList<String>();

  protected void logStatement(String s) {
    statements.add(s);
  }

  protected PreparedStatement prepareAndLog(Connection conn, String sql) throws SQLException {
    // TODO Should demote this to TRACE level
    log.debug("Preparing statement: " + sql);
    logStatement(sql);
    return conn.prepareStatement(sql);
  }

  protected void prepareAndLogAndExecute(Connection conn, String sql) throws SQLException {
    PreparedStatement stmt = prepareAndLog(conn, sql);
    stmt.execute();
    stmt.close();
  }

  @Override
  public List<String> getStatements() {
    return statements;
  }
}

@@ -1238,63 +1238,17 @@
     
-// TODO Should demote this to TRACE level%0A    log.debug
+log.trace
 (%22Pr
@@ -1431,24 +1431,25 @@
 Exception %7B%0A
+%0A
     Prepared

Add tracing to migration steps