private int getCountRecord(StatementHandler statementHandler,
			MetaObject metaStatementHandler) throws SQLException {

		Configuration conf = (Configuration) metaStatementHandler
				.getValue("delegate.configuration");
		Connection conn = conf.getEnvironment().getDataSource().getConnection();

		BoundSql boundSql = statementHandler.getBoundSql();

		String originalSql = boundSql.getSql().trim();
		String countSql = "select count(0) from (" + originalSql
				+ ") as tmp_count";

		PreparedStatement countStmt = conn.prepareStatement(countSql);
		setParameters(conf, boundSql, countStmt);

		ResultSet rs = countStmt.executeQuery();

		int countRecord = 0;

		if (rs.next()) {
			countRecord = rs.getInt(1);
		}

		rs.close();
		countStmt.close();
		conn.close();

		return countRecord;
	}