Example usage for org.apache.ibatis.logging Log debug

List of usage examples for org.apache.ibatis.logging Log debug

Introduction

In this page you can find the example usage for org.apache.ibatis.logging Log debug.

Prototype

void debug(String s);

Source Link

Usage

From source file:com.eryansky.common.orm.mybatis.interceptor.SQLHelper.java

License:Apache License

/**
 * /*  w  w  w . j  a v a2  s.co m*/
 * @param sql             SQL?
 * @param connection      ?
 * @param mappedStatement mapped
 * @param parameterObject ?
 * @param boundSql        boundSql
 * @return 
 * @throws java.sql.SQLException sql
 */
public static int getCount(final String sql, final Connection connection, final MappedStatement mappedStatement,
        final Object parameterObject, final BoundSql boundSql, Log log) throws SQLException {
    final String countSql = "select count(1) from (" + sql + ") tmp_count";
    //        final String countSql = "select count(1) " + removeSelect(removeOrders(sql));
    Connection conn = connection;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("COUNT SQL: " + StringUtils.replaceEach(countSql, new String[] { "\n", "\t" },
                    new String[] { " ", " " }));
        }
        if (conn == null) {
            conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();
        }
        ps = conn.prepareStatement(countSql);
        BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
                boundSql.getParameterMappings(), parameterObject);
        SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);
        rs = ps.executeQuery();
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        return count;
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:com.funtl.framework.smoke.core.commons.persistence.interceptor.SQLHelper.java

License:Apache License

/**
 * /*from  w  w w .  j a  v  a  2s .  co m*/
 *
 * @param sql             SQL?
 * @param connection      ?
 * @param mappedStatement mapped
 * @param parameterObject ?
 * @param boundSql        boundSql
 * @return 
 * @throws SQLException sql
 */
public static int getCount(final String sql, final Connection connection, final MappedStatement mappedStatement,
        final Object parameterObject, final BoundSql boundSql, Log log) throws SQLException {
    String dbName = Global.getConfig("jdbc.type");
    final String countSql;
    if ("oracle".equals(dbName)) {
        countSql = "select count(1) from (" + sql + ") tmp_count";
    } else {
        countSql = "select count(1) from (" + removeOrders(sql) + ") tmp_count";
        //           countSql = "select count(1) " + removeSelect(removeOrders(sql));
    }
    Connection conn = connection;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("COUNT SQL: " + StringUtils.replaceEach(countSql, new String[] { "\n", "\t" },
                    new String[] { " ", " " }));
        }
        if (conn == null) {
            conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();
        }
        ps = conn.prepareStatement(countSql);
        BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
                boundSql.getParameterMappings(), parameterObject);
        //MyBatis foreach ? start
        if (Reflections.getFieldValue(boundSql, "metaParameters") != null) {
            MetaObject mo = (MetaObject) Reflections.getFieldValue(boundSql, "metaParameters");
            Reflections.setFieldValue(countBS, "metaParameters", mo);
        }
        //MyBatis foreach ? end
        SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);
        rs = ps.executeQuery();
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        return count;
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:com.navercorp.pinpoint.web.dao.ibatis.BindingLogPlugin32.java

License:Apache License

public void debug(Log statementLogger, String msg) {
    if (statementLogger.isDebugEnabled()) {
        statementLogger.debug(msg);
    } else {//from  www .  j  av a 2  s .  c o  m
        pLogger.debug(msg);
    }
}

From source file:com.sjtu.icare.common.persistence.interceptor.SQLHelper.java

License:Open Source License

/**
 * //from  w w w .j av a2  s  .  c  om
 * @param sql             SQL?
 * @param connection      ?
 * @param mappedStatement mapped
 * @param parameterObject ?
 * @param boundSql        boundSql
 * @return 
 * @throws SQLException sql
 */
public static int getCount(final String sql, final Connection connection, final MappedStatement mappedStatement,
        final Object parameterObject, final BoundSql boundSql, Log log) throws SQLException {
    //        final String countSql = "select count(1) from (" + sql + ") tmp_count";
    final String countSql = "select count(1) " + removeSelect(removeOrders(sql));
    Connection conn = connection;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("COUNT SQL: " + StringUtils.replaceEach(countSql, new String[] { "\n", "\t" },
                    new String[] { " ", " " }));
        }
        if (conn == null) {
            conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();
        }
        ps = conn.prepareStatement(countSql);
        BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
                boundSql.getParameterMappings(), parameterObject);
        //?metaParameters..
        MetaObject countBsObject = SystemMetaObject.forObject(countBS);
        MetaObject boundSqlObject = SystemMetaObject.forObject(boundSql);
        countBsObject.setValue("metaParameters", boundSqlObject.getValue("metaParameters"));

        SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);
        rs = ps.executeQuery();
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        return count;
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:com.springD.framework.persistence.interceptor.SQLHelper.java

License:Open Source License

/**
 * /*w ww .j  a v  a 2s  .  c  o m*/
 * @param sql             SQL?
 * @param connection      ?
 * @param mappedStatement mapped
 * @param parameterObject ?
 * @param boundSql        boundSql
 * @return 
 * @throws SQLException sql
 */
public static int getCount(final String sql, final Connection connection, final MappedStatement mappedStatement,
        final Object parameterObject, final BoundSql boundSql, Log log) throws SQLException {
    String tmpSql = sql.replaceAll("(?i)order by.+\\z", "");
    String countSql = "select count(1) from (" + tmpSql + ") tmp_count";
    //        final String countSql = "select count(1) " + removeSelect(removeOrders(sql));
    Connection conn = connection;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("COUNT SQL: " + org.apache.commons.lang3.StringUtils.replaceEach(countSql,
                    new String[] { "\n", "\t" }, new String[] { " ", " " }));
        }
        if (conn == null) {
            conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();
        }
        ps = conn.prepareStatement(countSql);
        BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
                boundSql.getParameterMappings(), parameterObject);
        SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);
        rs = ps.executeQuery();
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        return count;
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (ps != null) {
            ps.close();
        }
        if (conn != null) {
            conn.close();
        }
    }
}