@Override public Connection getConnection() { try { return executor.getTransaction().getConnection(); } catch (SQLException e) { throw ExceptionFactory.wrapException("Error getting a new connection. Cause: " + e, e); } }
protected Connection getConnection(Log statementLog) throws SQLException { Connection connection = transaction.getConnection(); if (statementLog.isDebugEnabled()) { return ConnectionLogger.newInstance(connection, statementLog, queryStack); } else { return connection; } }
@Override public Connection getConnection() { try { return executor.getTransaction().getConnection(); } catch (SQLException e) { throw ExceptionFactory.wrapException("Error getting a new connection. Cause: " + e, e); } }
protected Connection getConnection(Log statementLog) throws SQLException { Connection connection = transaction.getConnection(); if (statementLog.isDebugEnabled()) { return ConnectionLogger.newInstance(connection, statementLog, queryStack); } else { return connection; } }
public Connection getConnection() { return executor.getTransaction().getConnection(); }
private Statement prepareStatement(StatementHandler handler) throws SQLException { Statement stmt; Connection connection = transaction.getConnection(); stmt = handler.prepare(connection); handler.parameterize(stmt); return stmt; }
/** * 查询总纪录数 * * @param mappedStatement mapped * @param parameterObject 参数 * @param boundSql boundSql * @param dialect database dialect * @return 总记录数 * @throws java.sql.SQLException sql查询错误 */ public static int getCount( final MappedStatement mappedStatement, final Transaction transaction, final Object parameterObject, final BoundSql boundSql, Dialect dialect) throws SQLException { final String count_sql = dialect.getCountSQL(); logger.debug("Total count SQL [{}] ", count_sql); logger.debug("Total count Parameters: {} ", parameterObject); Connection connection = transaction.getConnection(); PreparedStatement countStmt = connection.prepareStatement(count_sql); DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement,parameterObject,boundSql); handler.setParameters(countStmt); ResultSet rs = countStmt.executeQuery(); int count = 0; if (rs.next()) { count = rs.getInt(1); } logger.debug("Total count: {}", count); return count; }
/** * 查询总纪录数 * * @param mappedStatement mapped * @param parameterObject 参数 * @param boundSql boundSql * @param dialect database dialect * @return 总记录数 * @throws java.sql.SQLException sql查询错误 */ public static int getCount( final MappedStatement mappedStatement, final Transaction transaction, final Object parameterObject, final BoundSql boundSql, Dialect dialect) throws SQLException { final String count_sql = dialect.getCountSQL(); logger.debug("Total count SQL [{}] ", count_sql); logger.debug("Total count Parameters: {} ", parameterObject); Connection connection = transaction.getConnection(); PreparedStatement countStmt = connection.prepareStatement(count_sql); DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement,parameterObject,boundSql); handler.setParameters(countStmt); ResultSet rs = countStmt.executeQuery(); int count = 0; if (rs.next()) { count = rs.getInt(1); } logger.debug("Total count: {}", count); return count; }
public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLException { Configuration configuration = ms.getConfiguration(); StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject, RowBounds.DEFAULT, null); BoundSql boundSql = handler.getBoundSql(); String sql = boundSql.getSql(); Statement stmt; if (currentSql != null && sql.hashCode() == currentSql.hashCode() && sql.length() == currentSql.length()) { int last = statementList.size() - 1; stmt = statementList.get(last); } else { Connection connection = transaction.getConnection(); stmt = handler.prepare(connection); currentSql = sql; statementList.add(stmt); batchResultList.add(new BatchResult(ms, sql, parameterObject)); } handler.parameterize(stmt); handler.batch(stmt); return BATCH_UPDATE_RETURN_VALUE; }
public List doQuery(MappedStatement ms, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException { flushStatements(); Configuration configuration = ms.getConfiguration(); StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject, rowBounds, resultHandler); Connection connection = transaction.getConnection(); Statement stmt = handler.prepare(connection); handler.parameterize(stmt); return handler.query(stmt, resultHandler); }
private Statement prepareStatement(StatementHandler handler) throws SQLException { Statement stmt; BoundSql boundSql = handler.getBoundSql(); String sql = boundSql.getSql(); if (hasStatementFor(sql)) { stmt = getStatement(sql); } else { Connection connection = transaction.getConnection(); stmt = handler.prepare(connection); putStatement(sql, stmt); } handler.parameterize(stmt); return stmt; }
Connection connection = transaction.getConnection();
@Override public Object intercept(Invocation invocation) throws Throwable { Object target = invocation.getTarget(); if (target instanceof Executor) { Executor executor = (Executor) target; MappedStatement statement = (MappedStatement) invocation.getArgs()[0]; Object parameter = invocation.getArgs()[1]; EntityTable table = EntityHelper.getTableByMapper(MapperTemplate.getMapperClassName(statement.getId())); if(table != null && table.isMultiLanguage()){ Object obj = invocation.proceed(); Connection connection = executor.getTransaction().getConnection(); switch (statement.getSqlCommandType()){ case INSERT: insertMultiLanguage(table,parameter,connection); break; case UPDATE: updateMultiLanguage(table,parameter,connection); break; case DELETE: proceedDeleteMultiLanguage(table,parameter,connection); break; } return obj; } } return invocation.proceed(); }