ShardingSpherePreparedStatement extends AbstractPreparedStatementAdapter { @Override public ResultSet executeQuery() throws SQLException { ResultSet result; try { clearPrevious(); executionContext = createExecutionContext(); List<QueryResult> queryResults; if (ExecutorConstant.MANAGED_RESOURCE) { Collection<InputGroup<StatementExecuteUnit>> inputGroups = getInputGroups(); cacheStatements(inputGroups); reply(); queryResults = preparedStatementExecutor.executeQuery(inputGroups); } else { queryResults = rawExecutor.executeQuery(getRawInputGroups(), new RawSQLExecutorCallback()); } MergedResult mergedResult = mergeQuery(queryResults); result = new ShardingSphereResultSet(statements.stream().map(this::getResultSet).collect(Collectors.toList()), mergedResult, this, executionContext); } finally { clearBatch(); } currentResultSet = result; return result; } ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql);  ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency);  ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int autoGeneratedKeys);  ShardingSpherePreparedStatement(
            final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability); private  ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql,
                                            final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability, final boolean returnGeneratedKeys); @Override ResultSet executeQuery(); @Override int executeUpdate(); @Override boolean execute(); @Override ResultSet getResultSet(); @Override ResultSet getGeneratedKeys(); @Override void addBatch(); @Override int[] executeBatch(); @Override void clearBatch(); @SuppressWarnings("MagicConstant") @Override int getResultSetType(); @SuppressWarnings("MagicConstant") @Override int getResultSetConcurrency(); @Override int getResultSetHoldability(); @Override boolean isAccumulate(); @Override Collection<PreparedStatement> getRoutedStatements();  }
@Test public void assertExecuteSelectAutoTableGetResultSet() throws SQLException { Collection<Integer> result = Lists.newArrayList(1001, 1100, 1101); try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(SELECT_AUTO_SQL)) { preparedStatement.setInt(1, 1001); int count = 0; try (ResultSet resultSet = preparedStatement.executeQuery()) { while (resultSet.next()) { result.contains(resultSet.getInt(2)); count++; } } assertThat(result.size(), is(count)); } }
@Test public void assertInitPreparedStatementExecutorWithReplayMethod() throws SQLException { try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(SELECT_SQL_WITH_PARAMETER_MARKER)) { preparedStatement.setQueryTimeout(1); preparedStatement.setInt(1, 11); preparedStatement.setInt(2, 11); preparedStatement.executeQuery(); assertThat(preparedStatement.getQueryTimeout(), is(1)); } }
@Test(expected = SQLException.class) public void assertQueryWithNull() throws SQLException { try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(null)) { preparedStatement.executeQuery(); } }
@Test(expected = SQLException.class) public void assertQueryWithEmptyString() throws SQLException { try (PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement("")) { preparedStatement.executeQuery(); } }