// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/impl/CloseUtil.java
// public class CloseUtil {
// 
//     private CloseUtil() {
//     }
// 
//     public static void close(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(Statement statement) {
//         try {
//             if (statement != null) {
//                 statement.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(Connection conn) {
//         try {
//             if (conn != null) {
//                 conn.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(ResultSet rs) {
//         try {
//             if (rs != null) {
//                 rs.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
// }


import org.jsoftware.dbpatch.impl.CloseUtil;
import org.jsoftware.dbpatch.impl.PatchStatement;
import java.sql.*;
package org.jsoftware.dbpatch.config.dialect;



/**
 * Oracle Dialect
 *
 * @author szalik
 */
public class OracleDialect extends DefaultDialect {
    private static final long serialVersionUID = -8744726190040823430L;


    public PatchExecutionResult executeStatement(Connection c, PatchStatement ps) {
        if (ps.getCode().toLowerCase().startsWith("set ")) {
            PatchExecutionResultImpl resultImpl = new PatchExecutionResultImpl(ps);
            resultImpl.setSqlWarning(new SQLWarning("dbPatch do not allow executing SET statements"));
            return resultImpl;
        }
        String sql = ps.getCode();
        if (sql.toLowerCase().startsWith("execute ")) {
            sql = sql.substring(8);
            sql = "{ call " + sql + " }";
            PatchExecutionResultImpl result = new PatchExecutionResultImpl(ps);
            try {
                c.clearWarnings();
                CallableStatement p = c.prepareCall(sql);
                p.execute();
                p.close();
                result.setSqlWarning(c.getWarnings());
            } catch (SQLException e) {
                result.setCause(e);
            }
            return result;
        }
// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/impl/CloseUtil.java
// public class CloseUtil {
// 
//     private CloseUtil() {
//     }
// 
//     public static void close(Closeable closeable) {
//         try {
//             if (closeable != null) {
//                 closeable.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(Statement statement) {
//         try {
//             if (statement != null) {
//                 statement.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(Connection conn) {
//         try {
//             if (conn != null) {
//                 conn.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
//     public static void close(ResultSet rs) {
//         try {
//             if (rs != null) {
//                 rs.close();
//             }
//         } catch (Exception e) {	/* findBugs ok */ }
//     }
// 
// }


// Path: dbpatch-core/src/main/java/org/jsoftware/dbpatch/config/dialect/OracleDialect.java
import org.jsoftware.dbpatch.impl.CloseUtil;
import org.jsoftware.dbpatch.impl.PatchStatement;
import java.sql.*;

package org.jsoftware.dbpatch.config.dialect;



/**
 * Oracle Dialect
 *
 * @author szalik
 */
public class OracleDialect extends DefaultDialect {
    private static final long serialVersionUID = -8744726190040823430L;


    public PatchExecutionResult executeStatement(Connection c, PatchStatement ps) {
        if (ps.getCode().toLowerCase().startsWith("set ")) {
            PatchExecutionResultImpl resultImpl = new PatchExecutionResultImpl(ps);
            resultImpl.setSqlWarning(new SQLWarning("dbPatch do not allow executing SET statements"));
            return resultImpl;
        }
        String sql = ps.getCode();
        if (sql.toLowerCase().startsWith("execute ")) {
            sql = sql.substring(8);
            sql = "{ call " + sql + " }";
            PatchExecutionResultImpl result = new PatchExecutionResultImpl(ps);
            try {
                c.clearWarnings();
                CallableStatement p = c.prepareCall(sql);
                p.execute();
                p.close();
                result.setSqlWarning(c.getWarnings());
            } catch (SQLException e) {
                result.setCause(e);
            }
            return result;
        }
        return super.executeStatement(c, ps);