Java Code Examples for org.apache.ibatis.logging.Log#isDebugEnabled()

The following examples show how to use org.apache.ibatis.logging.Log#isDebugEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLHelper.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
/**
     * 查询总纪录数
     * @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);
            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();
            }
        }
    }
 
Example 2
Source File: BaseExecutor.java    From mybaties with Apache License 2.0 5 votes vote down vote up
protected Connection getConnection(Log statementLog) throws SQLException {
  Connection connection = transaction.getConnection();
  if (statementLog.isDebugEnabled()) {
    //如果需要打印Connection的日志,返回一个ConnectionLogger(代理模式, AOP思想)
    return ConnectionLogger.newInstance(connection, statementLog, queryStack);
  } else {
    return connection;
  }
}
 
Example 3
Source File: BindingLogPlugin32.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void debug(Log statementLogger, String msg) {
    if (statementLogger.isDebugEnabled()) {
        statementLogger.debug(msg);
    } else {
        pLogger.debug(msg);
    }
}
 
Example 4
Source File: BaseExecutor.java    From mybatis with Apache License 2.0 5 votes vote down vote up
protected Connection getConnection(Log statementLog) throws SQLException {
  Connection connection = transaction.getConnection();
  if (statementLog.isDebugEnabled()) {
    //如果需要打印Connection的日志,返回一个ConnectionLogger(代理模式, AOP思想)
    return ConnectionLogger.newInstance(connection, statementLog, queryStack);
  } else {
    return connection;
  }
}
 
Example 5
Source File: BindingLogPlugin32.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public boolean isDebugEnable(Log statementLogger) {
    return statementLogger.isDebugEnabled() || pLogger.isDebugEnabled();
}