@@ -610,11 +610,7 @@ public final IRubyObject connection(final ThreadContext context, final IRubyObje
610
610
return convertJavaToRuby ( connection .unwrap (Connection .class ) );
611
611
}
612
612
}
613
- catch (AbstractMethodError e ) {
614
- debugStackTrace (context , e );
615
- warn (context , "driver/pool connection does not support unwrapping: " + e );
616
- }
617
- catch (SQLException e ) {
613
+ catch (AbstractMethodError | SQLException e ) {
618
614
debugStackTrace (context , e );
619
615
warn (context , "driver/pool connection does not support unwrapping: " + e );
620
616
}
@@ -860,27 +856,25 @@ private static String[] createStatementPk(IRubyObject pk) {
860
856
*/
861
857
@ JRubyMethod (name = "execute_insert_pk" , required = 2 )
862
858
public IRubyObject execute_insert_pk (final ThreadContext context , final IRubyObject sql , final IRubyObject pk ) {
863
- return withConnection (context , new Callable <IRubyObject >() {
864
- public IRubyObject call (final Connection connection ) throws SQLException {
865
- Statement statement = null ;
866
- final String query = sqlString (sql );
867
- try {
868
-
869
- statement = createStatement (context , connection );
859
+ return withConnection (context , connection -> {
860
+ Statement statement = null ;
861
+ final String query = sqlString (sql );
862
+ try {
870
863
871
- if (pk == context .nil || pk == context .fals || !supportsGeneratedKeys (connection )) {
872
- statement .executeUpdate (query , Statement .RETURN_GENERATED_KEYS );
873
- } else {
874
- statement .executeUpdate (query , createStatementPk (pk ));
875
- }
864
+ statement = createStatement (context , connection );
876
865
877
- return mapGeneratedKeys (context , connection , statement );
878
- } catch (final SQLException e ) {
879
- debugErrorSQL (context , query );
880
- throw e ;
881
- } finally {
882
- close (statement );
866
+ if (pk == context .nil || pk == context .fals || !supportsGeneratedKeys (connection )) {
867
+ statement .executeUpdate (query , Statement .RETURN_GENERATED_KEYS );
868
+ } else {
869
+ statement .executeUpdate (query , createStatementPk (pk ));
883
870
}
871
+
872
+ return mapGeneratedKeys (context , connection , statement );
873
+ } catch (final SQLException e ) {
874
+ debugErrorSQL (context , query );
875
+ throw e ;
876
+ } finally {
877
+ close (statement );
884
878
}
885
879
});
886
880
}
@@ -903,26 +897,24 @@ public IRubyObject execute_insert(final ThreadContext context, final IRubyObject
903
897
@ JRubyMethod (name = "execute_insert_pk" , required = 3 )
904
898
public IRubyObject execute_insert_pk (final ThreadContext context , final IRubyObject sql , final IRubyObject binds ,
905
899
final IRubyObject pk ) {
906
- return withConnection (context , new Callable <IRubyObject >() {
907
- public IRubyObject call (final Connection connection ) throws SQLException {
908
- PreparedStatement statement = null ;
909
- final String query = sqlString (sql );
910
- try {
911
- if (pk == context .nil || pk == context .fals || !supportsGeneratedKeys (connection )) {
912
- statement = connection .prepareStatement (query , Statement .RETURN_GENERATED_KEYS );
913
- } else {
914
- statement = connection .prepareStatement (query , createStatementPk (pk ));
915
- }
916
-
917
- setStatementParameters (context , connection , statement , (RubyArray ) binds );
918
- statement .executeUpdate ();
919
- return mapGeneratedKeys (context , connection , statement );
920
- } catch (final SQLException e ) {
921
- debugErrorSQL (context , query );
922
- throw e ;
923
- } finally {
924
- close (statement );
900
+ return withConnection (context , connection -> {
901
+ PreparedStatement statement = null ;
902
+ final String query = sqlString (sql );
903
+ try {
904
+ if (pk == context .nil || pk == context .fals || !supportsGeneratedKeys (connection )) {
905
+ statement = connection .prepareStatement (query , Statement .RETURN_GENERATED_KEYS );
906
+ } else {
907
+ statement = connection .prepareStatement (query , createStatementPk (pk ));
925
908
}
909
+
910
+ setStatementParameters (context , connection , statement , (RubyArray ) binds );
911
+ statement .executeUpdate ();
912
+ return mapGeneratedKeys (context , connection , statement );
913
+ } catch (final SQLException e ) {
914
+ debugErrorSQL (context , query );
915
+ throw e ;
916
+ } finally {
917
+ close (statement );
926
918
}
927
919
});
928
920
}
@@ -1012,12 +1004,12 @@ public IRubyObject execute_query_raw(final ThreadContext context, final IRubyObj
1012
1004
binds = null ;
1013
1005
} else { // (sql, binds)
1014
1006
maxRows = 0 ;
1015
- binds = (RubyArray ) TypeConverter .checkArrayType (args [1 ]);
1007
+ binds = (RubyArray ) TypeConverter .checkArrayType (context , args [1 ]);
1016
1008
}
1017
1009
break ;
1018
1010
case 3 : // (sql, max_rows, binds)
1019
1011
maxRows = RubyNumeric .fix2int (args [1 ]);
1020
- binds = (RubyArray ) TypeConverter .checkArrayType (args [2 ]);
1012
+ binds = (RubyArray ) TypeConverter .checkArrayType (context , args [2 ]);
1021
1013
break ;
1022
1014
default : // (sql) 1-arg
1023
1015
maxRows = 0 ;
0 commit comments