// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/AbstractPatch.java
// public abstract class AbstractPatch implements Serializable {
//     private static final long serialVersionUID = 4178101927323891639L;
//     private String name;
//     private int statementCount = -1;
//     private File file;
// 
//     public enum DbState {
//         COMMITTED, IN_PROGRESS, NOT_AVAILABLE
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public int getStatementCount() {
//         return statementCount;
//     }
// 
//     public void setStatementCount(int statementCount) {
//         this.statementCount = statementCount;
//     }
// 
//     public File getFile() {
//         return file;
//     }
// 
//     public void setFile(File file) {
//         this.file = file;
//     }
// 
//     public abstract void setDbDate(Date dbDate);
// 
//     public abstract void setDbState(DbState dbState);
// 
//     public abstract Date getDbDate();
// 
//     public abstract DbState getDbState();
// 
//     public abstract boolean canApply();
// 
//     public String toString() {
//         return super.toString() + "-" + name;
//     }
// 
//     public static String normalizeName(String name) {
//         String nameLC = name.toLowerCase();
//         while (nameLC.endsWith(".sql") || nameLC.endsWith(".undo") || nameLC.endsWith(".rollback")) {
//             int dot = nameLC.lastIndexOf('.');
//             nameLC = nameLC.substring(0, dot);
//         }
//         return name.substring(0, nameLC.length());
//     }
// 
// }
// 
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/RollbackPatch.java
// public class RollbackPatch extends AbstractPatch {
//     private final Patch patch;
//     private final File originalPatchFile;
//     private boolean missing;
// 
//     public RollbackPatch(Patch patch) {
//         super.setName(patch.getName());
//         this.originalPatchFile = patch.getFile();
//         this.missing = true;
//         this.patch = patch;
//     }
// 
//     public RollbackPatch(Patch patch, File rollbackFile, int rollbackStatementsCount) {
//         this(patch);
//         super.setFile(rollbackFile);
//         super.setStatementCount(rollbackStatementsCount);
//         this.missing = false;
//     }
// 
// 
//     public void setFile(File file) {
//         throw new AssertionError("DO NOT USE IT! It shouldn't be invoked.");
//     }
// 
//     @Override
//     public void setDbDate(Date dbDate) {
//         patch.setDbDate(dbDate);
//     }
// 
//     @Override
//     public void setDbState(DbState dbState) {
//         patch.setDbState(dbState);
//     }
// 
//     @Override
//     public Date getDbDate() {
//         return patch.getDbDate();
//     }
// 
//     @Override
//     public DbState getDbState() {
//         return patch.getDbState();
//     }
// 
//     public File getOriginalPatchFile() {
//         return originalPatchFile;
//     }
// 
//     public boolean isMissing() {
//         return missing;
//     }
// 
// 
//     public boolean canApply() {
//         return !isMissing() && getStatementCount() > 0 && getDbState() == DbState.COMMITTED;
//     }
// }
// 
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/dialect/PatchExecutionResult.java
// public interface PatchExecutionResult {
// 
//     /**
//      * @return false if Patch was executed with errors
//      */
//     boolean isFailure();
// 
//     /**
//      * @return SQLWarning if any during patch execution
//      */
//     SQLWarning getSqlWarnings();
// 
//     /**
//      * @return Fatal error during patch execution
//      */
//     SQLException getCause();
// 
//     PatchStatement getPatchStatement();
// 
//     int getDmlCount();
// 
//     DML_TYPE getDmlType();
// }


import org.jsoftware.dbpatch.config.AbstractPatch;
import org.jsoftware.dbpatch.config.Patch;
import org.jsoftware.dbpatch.config.RollbackPatch;
import org.jsoftware.dbpatch.config.dialect.PatchExecutionResult;
import org.jsoftware.dbpatch.impl.PatchStatement;
import java.sql.Connection;
import java.sql.SQLException;
package org.jsoftware.dbpatch.impl.extension;



public interface Extension {

    /**
     * @param connection connection
     * Before patching procedure starts
     */
    void beforePatching(Connection connection);

    /**
     * @param connection connection
     * After patching process ends
     */
    void afterPatching(Connection connection);

    /**
     * @param connection connection
     * @param patch patch to apply
     * Before the patch is executed
     */
    void beforePatch(Connection connection, Patch patch);

    /**
     * After the patch is executed
     * @param connection connection
     * @param patch patch to apply
     * @param ex execution exception - null if successful execution
     * @throws SQLException sql problem
     */
    void afterPatch(Connection connection, Patch patch, Exception ex) throws SQLException;

    /**
     * Before patch's statement is executed
     * @param connection connection
     * @param patch patch
     * @param statement sql statement
     */
    void beforePatchStatement(Connection connection, AbstractPatch patch, PatchStatement statement);

    /**
     * After patch's statement is executed
     * @param connection connection
     * @param patch patch
     * @param result patching result
     */
    void afterPatchStatement(Connection connection, AbstractPatch patch, PatchExecutionResult result);

    /**
     * Before the patch rollback is executed
     * @param connection connection
     * @param patch patch to rollback
     */
    void beforeRollbackPatch(Connection connection, RollbackPatch patch);

    /**
     * After the patch rollback is executed
     * @param connection connection
     * @param patch patch that was rollbacked
     * @param ex exception if an error occurred
     * @throws SQLException sql problem
     */
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/AbstractPatch.java
// public abstract class AbstractPatch implements Serializable {
//     private static final long serialVersionUID = 4178101927323891639L;
//     private String name;
//     private int statementCount = -1;
//     private File file;
// 
//     public enum DbState {
//         COMMITTED, IN_PROGRESS, NOT_AVAILABLE
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public int getStatementCount() {
//         return statementCount;
//     }
// 
//     public void setStatementCount(int statementCount) {
//         this.statementCount = statementCount;
//     }
// 
//     public File getFile() {
//         return file;
//     }
// 
//     public void setFile(File file) {
//         this.file = file;
//     }
// 
//     public abstract void setDbDate(Date dbDate);
// 
//     public abstract void setDbState(DbState dbState);
// 
//     public abstract Date getDbDate();
// 
//     public abstract DbState getDbState();
// 
//     public abstract boolean canApply();
// 
//     public String toString() {
//         return super.toString() + "-" + name;
//     }
// 
//     public static String normalizeName(String name) {
//         String nameLC = name.toLowerCase();
//         while (nameLC.endsWith(".sql") || nameLC.endsWith(".undo") || nameLC.endsWith(".rollback")) {
//             int dot = nameLC.lastIndexOf('.');
//             nameLC = nameLC.substring(0, dot);
//         }
//         return name.substring(0, nameLC.length());
//     }
// 
// }
// 
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/RollbackPatch.java
// public class RollbackPatch extends AbstractPatch {
//     private final Patch patch;
//     private final File originalPatchFile;
//     private boolean missing;
// 
//     public RollbackPatch(Patch patch) {
//         super.setName(patch.getName());
//         this.originalPatchFile = patch.getFile();
//         this.missing = true;
//         this.patch = patch;
//     }
// 
//     public RollbackPatch(Patch patch, File rollbackFile, int rollbackStatementsCount) {
//         this(patch);
//         super.setFile(rollbackFile);
//         super.setStatementCount(rollbackStatementsCount);
//         this.missing = false;
//     }
// 
// 
//     public void setFile(File file) {
//         throw new AssertionError("DO NOT USE IT! It shouldn't be invoked.");
//     }
// 
//     @Override
//     public void setDbDate(Date dbDate) {
//         patch.setDbDate(dbDate);
//     }
// 
//     @Override
//     public void setDbState(DbState dbState) {
//         patch.setDbState(dbState);
//     }
// 
//     @Override
//     public Date getDbDate() {
//         return patch.getDbDate();
//     }
// 
//     @Override
//     public DbState getDbState() {
//         return patch.getDbState();
//     }
// 
//     public File getOriginalPatchFile() {
//         return originalPatchFile;
//     }
// 
//     public boolean isMissing() {
//         return missing;
//     }
// 
// 
//     public boolean canApply() {
//         return !isMissing() && getStatementCount() > 0 && getDbState() == DbState.COMMITTED;
//     }
// }
// 
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/dialect/PatchExecutionResult.java
// public interface PatchExecutionResult {
// 
//     /**
//      * @return false if Patch was executed with errors
//      */
//     boolean isFailure();
// 
//     /**
//      * @return SQLWarning if any during patch execution
//      */
//     SQLWarning getSqlWarnings();
// 
//     /**
//      * @return Fatal error during patch execution
//      */
//     SQLException getCause();
// 
//     PatchStatement getPatchStatement();
// 
//     int getDmlCount();
// 
//     DML_TYPE getDmlType();
// }


// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/impl/extension/Extension.java
import org.jsoftware.dbpatch.config.AbstractPatch;
import org.jsoftware.dbpatch.config.Patch;
import org.jsoftware.dbpatch.config.RollbackPatch;
import org.jsoftware.dbpatch.config.dialect.PatchExecutionResult;
import org.jsoftware.dbpatch.impl.PatchStatement;
import java.sql.Connection;
import java.sql.SQLException;

package org.jsoftware.dbpatch.impl.extension;



public interface Extension {

    /**
     * @param connection connection
     * Before patching procedure starts
     */
    void beforePatching(Connection connection);

    /**
     * @param connection connection
     * After patching process ends
     */
    void afterPatching(Connection connection);

    /**
     * @param connection connection
     * @param patch patch to apply
     * Before the patch is executed
     */
    void beforePatch(Connection connection, Patch patch);

    /**
     * After the patch is executed
     * @param connection connection
     * @param patch patch to apply
     * @param ex execution exception - null if successful execution
     * @throws SQLException sql problem
     */
    void afterPatch(Connection connection, Patch patch, Exception ex) throws SQLException;

    /**
     * Before patch's statement is executed
     * @param connection connection
     * @param patch patch
     * @param statement sql statement
     */
    void beforePatchStatement(Connection connection, AbstractPatch patch, PatchStatement statement);

    /**
     * After patch's statement is executed
     * @param connection connection
     * @param patch patch
     * @param result patching result
     */
    void afterPatchStatement(Connection connection, AbstractPatch patch, PatchExecutionResult result);

    /**
     * Before the patch rollback is executed
     * @param connection connection
     * @param patch patch to rollback
     */
    void beforeRollbackPatch(Connection connection, RollbackPatch patch);

    /**
     * After the patch rollback is executed
     * @param connection connection
     * @param patch patch that was rollbacked
     * @param ex exception if an error occurred
     * @throws SQLException sql problem
     */
    void afterRollbackPatch(Connection connection, RollbackPatch patch, Exception ex) throws SQLException;