/** * Execute group. * * @param sqlExecuteGroups SQL execute groups * @param callback SQL execute callback * @param <T> class type of return value * @return execute result * @throws SQLException SQL exception */ public <T> List<T> executeGroup(final Collection<ShardingExecuteGroup<? extends StatementExecuteUnit>> sqlExecuteGroups, final SQLExecuteCallback<T> callback) throws SQLException { return executeGroup(sqlExecuteGroups, null, callback); }
@SuppressWarnings("unchecked") protected final <T> List<T> executeCallback(final SQLExecuteCallback<T> executeCallback) throws SQLException { return sqlExecuteTemplate.executeGroup((Collection) executeGroups, executeCallback); }
@SuppressWarnings("unchecked") @Override public ExecuteResponse execute(final SQLRouteResult routeResult) throws SQLException { boolean isReturnGeneratedKeys = routeResult.getSqlStatement() instanceof InsertStatement; boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); Collection<ShardingExecuteGroup<StatementExecuteUnit>> sqlExecuteGroups = sqlExecutePrepareTemplate.getExecuteUnitGroups(routeResult.getRouteUnits(), new ProxyJDBCExecutePrepareCallback(isReturnGeneratedKeys)); SQLExecuteCallback<ExecuteResponseUnit> firstProxySQLExecuteCallback = new FirstProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys); SQLExecuteCallback<ExecuteResponseUnit> proxySQLExecuteCallback = new ProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys); Collection<ExecuteResponseUnit> executeResponseUnits = sqlExecuteTemplate.executeGroup((Collection) sqlExecuteGroups, firstProxySQLExecuteCallback, proxySQLExecuteCallback); ExecuteResponseUnit firstExecuteResponseUnit = executeResponseUnits.iterator().next(); return firstExecuteResponseUnit instanceof ExecuteQueryResponseUnit ? getExecuteQueryResponse(((ExecuteQueryResponseUnit) firstExecuteResponseUnit).getQueryResponsePackets(), executeResponseUnits) : new ExecuteUpdateResponse(executeResponseUnits); }
@SuppressWarnings("unchecked") @Override public ExecuteResponse execute(final SQLRouteResult routeResult) throws SQLException { boolean isReturnGeneratedKeys = routeResult.getSqlStatement() instanceof InsertStatement; boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); Collection<ShardingExecuteGroup<StatementExecuteUnit>> sqlExecuteGroups = sqlExecutePrepareTemplate.getExecuteUnitGroups(routeResult.getRouteUnits(), new ProxyJDBCExecutePrepareCallback(isReturnGeneratedKeys)); SQLExecuteCallback<ExecuteResponseUnit> firstProxySQLExecuteCallback = new FirstProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys); SQLExecuteCallback<ExecuteResponseUnit> proxySQLExecuteCallback = new ProxyJDBCExecuteCallback(isExceptionThrown, isReturnGeneratedKeys); Collection<ExecuteResponseUnit> executeResponseUnits = sqlExecuteTemplate.executeGroup((Collection) sqlExecuteGroups, firstProxySQLExecuteCallback, proxySQLExecuteCallback); ExecuteResponseUnit firstExecuteResponseUnit = executeResponseUnits.iterator().next(); return firstExecuteResponseUnit instanceof ExecuteQueryResponseUnit ? getExecuteQueryResponse(((ExecuteQueryResponseUnit) firstExecuteResponseUnit).getPostgreSQLQueryResponsePackets(), executeResponseUnits) : new ExecuteUpdateResponse(executeResponseUnits); }