@Test public void testExecuteQuery() throws SQLException { TGroupConnection conn = null; PreparedStatement stat = null; try { conn = tgds.getConnection(); stat = conn.prepareStatement("select * from xxx where id=?"); stat.setByte(1, (byte) 5); MockDataSource.addPreData("id:1,name:2"); ResultSet result = stat.executeQuery(); Assert.assertEquals(result.next(), true); Assert.assertEquals(result.getLong(1), 1L); Assert.assertEquals(result.getLong(2), 2L); MockDataSource.showTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } if (stat != null) { try { stat.close(); } catch (SQLException e) { } } } } }
public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); ensureResultSetIsEmpty(); boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit(); Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead); if (conn != null) { sql = GroupHintParser.removeTddlGroupHint(sql); return executeQueryOnConnection(conn, sql); } else { GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql); sql = GroupHintParser.removeTddlGroupHint(sql); if (dataSourceIndex == null) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer, retryingTimes, sql, dataSourceIndex); } }
TGroupStatement implements TStatement { public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); ensureResultSetIsEmpty(); boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit(); Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead); if (conn != null) { sql = GroupHintParser.removeTddlGroupHint(sql); return executeQueryOnConnection(conn, sql); } else { GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql); sql = GroupHintParser.removeTddlGroupHint(sql); if (dataSourceIndex == null) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer, retryingTimes, sql, dataSourceIndex); } } }
TGroupStatement implements TStatement { public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); ensureResultSetIsEmpty(); boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit(); Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead); if (conn != null) { sql = GroupHintParser.removeTddlGroupHint(sql); return executeQueryOnConnection(conn, sql); } else { GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql); sql = GroupHintParser.removeTddlGroupHint(sql); if (dataSourceIndex == null) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer, retryingTimes, sql, dataSourceIndex); } } TGroupStatement(TGroupDataSource tGroupDataSource, TGroupConnection tGroupConnection); }
TGroupStatement implements TStatement { public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); ensureResultSetIsEmpty(); boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit(); Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead); if (conn != null) { sql = GroupHintParser.removeTddlGroupHint(sql); return executeQueryOnConnection(conn, sql); } else { GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql); sql = GroupHintParser.removeTddlGroupHint(sql); if (dataSourceIndex == null) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer, retryingTimes, sql, dataSourceIndex); } } TGroupStatement(TGroupDataSource tGroupDataSource, TGroupConnection tGroupConnection); boolean execute(String sql); boolean execute(String sql, int autoGeneratedKeys); boolean execute(String sql, int[] columnIndexes); boolean execute(String sql, String[] columnNames); int executeUpdate(String sql); int executeUpdate(String sql, int autoGeneratedKeys); int executeUpdate(String sql, int[] columnIndexes); int executeUpdate(String sql, String[] columnNames); void addBatch(String sql); void clearBatch(); int[] executeBatch(); void close(); ResultSet executeQuery(String sql); SQLWarning getWarnings(); void clearWarnings(); boolean getMoreResults(); int getQueryTimeout(); void setQueryTimeout(int queryTimeout); ResultSet getResultSet(); int getUpdateCount(); int getResultSetConcurrency(); int getResultSetHoldability(); int getResultSetType(); void setResultSetType(int resultSetType); void setResultSetConcurrency(int resultSetConcurrency); void setResultSetHoldability(int resultSetHoldability); Connection getConnection(); void cancel(); int getFetchDirection(); int getFetchSize(); int getMaxFieldSize(); int getMaxRows(); void setCursorName(String cursorName); void setEscapeProcessing(boolean escapeProcessing); boolean getMoreResults(int current); void setFetchDirection(int fetchDirection); void setFetchSize(int fetchSize); void setMaxFieldSize(int maxFieldSize); void setMaxRows(int maxRows); ResultSet getGeneratedKeys(); boolean isWrapperFor(Class<?> iface); @SuppressWarnings("unchecked") T unwrap(Class<T> iface); boolean isClosed(); void setPoolable(boolean poolable); boolean isPoolable(); @Override void fillMetaData(SqlMetaData sqlMetaData); @Override SqlMetaData getSqlMetaData(); }
TGroupStatement implements TStatement { public ResultSet executeQuery(String sql) throws SQLException { checkClosed(); ensureResultSetIsEmpty(); boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit(); Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead); if (conn != null) { sql = GroupHintParser.removeTddlGroupHint(sql); return executeQueryOnConnection(conn, sql); } else { GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql); sql = GroupHintParser.removeTddlGroupHint(sql); if (dataSourceIndex == null) { dataSourceIndex = ThreadLocalDataSourceIndex.getIndex(); } return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer, retryingTimes, sql, dataSourceIndex); } } TGroupStatement(TGroupDataSource tGroupDataSource, TGroupConnection tGroupConnection); boolean execute(String sql); boolean execute(String sql, int autoGeneratedKeys); boolean execute(String sql, int[] columnIndexes); boolean execute(String sql, String[] columnNames); int executeUpdate(String sql); int executeUpdate(String sql, int autoGeneratedKeys); int executeUpdate(String sql, int[] columnIndexes); int executeUpdate(String sql, String[] columnNames); void addBatch(String sql); void clearBatch(); int[] executeBatch(); void close(); ResultSet executeQuery(String sql); SQLWarning getWarnings(); void clearWarnings(); boolean getMoreResults(); int getQueryTimeout(); void setQueryTimeout(int queryTimeout); ResultSet getResultSet(); int getUpdateCount(); int getResultSetConcurrency(); int getResultSetHoldability(); int getResultSetType(); void setResultSetType(int resultSetType); void setResultSetConcurrency(int resultSetConcurrency); void setResultSetHoldability(int resultSetHoldability); Connection getConnection(); void cancel(); int getFetchDirection(); int getFetchSize(); int getMaxFieldSize(); int getMaxRows(); void setCursorName(String cursorName); void setEscapeProcessing(boolean escapeProcessing); boolean getMoreResults(int current); void setFetchDirection(int fetchDirection); void setFetchSize(int fetchSize); void setMaxFieldSize(int maxFieldSize); void setMaxRows(int maxRows); ResultSet getGeneratedKeys(); boolean isWrapperFor(Class<?> iface); @SuppressWarnings("unchecked") T unwrap(Class<T> iface); boolean isClosed(); void setPoolable(boolean poolable); boolean isPoolable(); @Override void fillMetaData(SqlMetaData sqlMetaData); @Override SqlMetaData getSqlMetaData();  }