@@ -48,10 +48,7 @@ public ArrowFlightMetaImpl(final AvaticaConnection connection) {
4848
4949 @ Override
5050 public void closeStatement (final StatementHandle statementHandle ) {
51- AvaticaStatement statement = connection .statementMap .get (statementHandle .id );
52- if (statement instanceof ArrowFlightPreparedStatement ) {
53- ((ArrowFlightPreparedStatement ) statement ).closePreparedResources ();
54- }
51+ getMetaStatement (statementHandle ).closeStatement ();
5552 }
5653
5754 @ Override
@@ -64,8 +61,7 @@ public ExecuteResult execute(
6461 final StatementHandle statementHandle ,
6562 final List <TypedValue > typedValues ,
6663 final long maxRowCount ) {
67- return getPreparedStatementInstance (statementHandle )
68- .executeWithTypedValues (statementHandle , typedValues , maxRowCount );
64+ return getMetaStatement (statementHandle ).execute (statementHandle , typedValues , maxRowCount );
6965 }
7066
7167 @ Override
@@ -80,8 +76,7 @@ public ExecuteResult execute(
8076 public ExecuteBatchResult executeBatch (
8177 final StatementHandle statementHandle , final List <List <TypedValue >> parameterValuesList )
8278 throws IllegalStateException {
83- return getPreparedStatementInstance (statementHandle )
84- .executeBatchWithTypedValues (statementHandle , parameterValuesList );
79+ return getMetaStatement (statementHandle ).executeBatch (statementHandle , parameterValuesList );
8580 }
8681
8782 @ Override
@@ -96,31 +91,16 @@ public Frame fetch(
9691 String .format ("%s does not use frames." , this ), AvaticaConnection .HELPER .unsupported ());
9792 }
9893
99- ArrowFlightPreparedStatement createPreparedStatement (
100- final String query ,
101- final int resultSetType ,
102- final int resultSetConcurrency ,
103- final int resultSetHoldability )
104- throws SQLException {
105- return ArrowFlightPreparedStatement .builder ((ArrowFlightConnection ) connection )
106- .withQuery (query )
107- .withGeneratedHandle ()
108- .withResultSetType (resultSetType )
109- .withResultSetConcurrency (resultSetConcurrency )
110- .withResultSetHoldability (resultSetHoldability )
111- .build ();
112- }
113-
11494 @ Override
11595 public StatementHandle prepare (
11696 final ConnectionHandle connectionHandle , final String query , final long maxRowCount ) {
11797 try {
118- return createPreparedStatement (
119- query ,
120- ResultSet . TYPE_FORWARD_ONLY ,
121- ResultSet . CONCUR_READ_ONLY ,
122- connection . getHoldability ())
123- .handle ;
98+ // This is the Avatica entry point used by Connection.prepareStatement(String).
99+ ArrowFlightPreparedStatement stmt =
100+ ( ArrowFlightPreparedStatement )
101+ connection . prepareStatement (
102+ query , ResultSet . TYPE_FORWARD_ONLY , ResultSet . CONCUR_READ_ONLY );
103+ return stmt .handle ;
124104 } catch (SQLException e ) {
125105 throw new RuntimeException (e );
126106 }
@@ -133,6 +113,7 @@ public ExecuteResult prepareAndExecute(
133113 final long maxRowCount ,
134114 final PrepareCallback prepareCallback )
135115 throws NoSuchStatementException {
116+ // This is the Avatica entry point used by Statement.execute(String).
136117 return prepareAndExecute (
137118 statementHandle , query , maxRowCount , -1 /* Not used */ , prepareCallback );
138119 }
@@ -146,20 +127,9 @@ public ExecuteResult prepareAndExecute(
146127 final PrepareCallback callback )
147128 throws NoSuchStatementException {
148129 try {
149- final AvaticaStatement statement = connection .statementMap .get (handle .id );
150- if (!(statement instanceof ArrowFlightStatement )
151- && !(statement instanceof ArrowFlightPreparedStatement )) {
152- throw new IllegalStateException ("Prepared statement not found: " + handle );
153- }
154- if (statement instanceof ArrowFlightPreparedStatement ) {
155- ((ArrowFlightPreparedStatement ) statement ).closePreparedResources ();
156- }
157- final ArrowFlightPreparedStatement preparedStatement =
158- ArrowFlightPreparedStatement .builder ((ArrowFlightConnection ) connection )
159- .withQuery (query )
160- .withExistingStatement (statement )
161- .build ();
162- return preparedStatement .prepareAndExecute (callback );
130+ // This is the Avatica entry point used by Statement.execute(String).
131+ return getMetaStatement (handle )
132+ .prepareAndExecute (query , maxRowCount , maxRowsInFirstFrame , callback );
163133 } catch (SQLTimeoutException e ) {
164134 // So far AvaticaStatement(executeInternal) only handles NoSuchStatement and
165135 // Runtime
@@ -216,30 +186,37 @@ void setDefaultConnectionProperties() {
216186 .setTransactionIsolation (Connection .TRANSACTION_NONE );
217187 }
218188
219- private ArrowFlightPreparedStatement getPreparedStatementInstance (
220- StatementHandle statementHandle ) {
189+ private ArrowFlightMetaStatement getMetaStatement (StatementHandle statementHandle ) {
221190 AvaticaStatement statement = connection .statementMap .get (statementHandle .id );
222- if (!( statement instanceof ArrowFlightPreparedStatement ) ) {
223- throw new IllegalStateException ( "Prepared statement not found: " + statementHandle ) ;
191+ if (statement instanceof ArrowFlightMetaStatement ) {
192+ return ( ArrowFlightMetaStatement ) statement ;
224193 }
225- return ( ArrowFlightPreparedStatement ) statement ;
194+ throw new IllegalStateException ( "Statement not found: " + statementHandle ) ;
226195 }
227196
228- ArrowFlightPreparedStatement getPreparedStatementInstanceOrNull (StatementHandle statementHandle ) {
229- AvaticaStatement statement = connection .statementMap .get (statementHandle .id );
230- if (statement instanceof ArrowFlightPreparedStatement ) {
231- return (ArrowFlightPreparedStatement ) statement ;
232- }
233- return null ;
197+ public static Signature buildDefaultSignature () {
198+ return buildSignature (null , StatementType .SELECT );
234199 }
235200
236- public static Signature buildDefaultSignature ( ) {
237- return buildSignature (null , null , null );
201+ public static Signature buildSignature ( final String sql , final StatementType type ) {
202+ return buildSignature (sql , null , null , type );
238203 }
239204
240205 /** Builds an Avatica signature from Arrow result and parameter schemas. */
241206 public static Signature buildSignature (
242207 final String sql , final Schema resultSetSchema , final Schema parameterSchema ) {
208+ StatementType statementType =
209+ resultSetSchema == null || resultSetSchema .getFields ().isEmpty ()
210+ ? StatementType .IS_DML
211+ : StatementType .SELECT ;
212+ return buildSignature (sql , resultSetSchema , parameterSchema , statementType );
213+ }
214+
215+ private static Signature buildSignature (
216+ final String sql ,
217+ final Schema resultSetSchema ,
218+ final Schema parameterSchema ,
219+ final StatementType statementType ) {
243220 List <ColumnMetaData > columnMetaData =
244221 resultSetSchema == null
245222 ? new ArrayList <>()
@@ -248,10 +225,6 @@ public static Signature buildSignature(
248225 parameterSchema == null
249226 ? new ArrayList <>()
250227 : ConvertUtils .convertArrowFieldsToAvaticaParameters (parameterSchema .getFields ());
251- StatementType statementType =
252- resultSetSchema == null || resultSetSchema .getFields ().isEmpty ()
253- ? StatementType .IS_DML
254- : StatementType .SELECT ;
255228 return new Signature (
256229 columnMetaData ,
257230 sql ,
0 commit comments