27
27
28
28
import java .sql .Connection ;
29
29
import java .sql .SQLException ;
30
- import javax .sql .DataSource ;
31
-
32
- import org .jruby .RubyObject ;
33
- import org .jruby .RubyString ;
34
- import org .jruby .runtime .ThreadContext ;
35
- import org .jruby .runtime .builtin .IRubyObject ;
36
30
37
31
/**
38
32
* Interface to be implemented in Ruby for retrieving a new connection.
@@ -49,84 +43,3 @@ public interface ConnectionFactory {
49
43
Connection newConnection () throws SQLException ;
50
44
51
45
}
52
-
53
- class DataSourceConnectionFactoryImpl implements ConnectionFactory {
54
-
55
- private final DataSource dataSource ;
56
- final String username , password ; // optional
57
-
58
- public DataSourceConnectionFactoryImpl (final DataSource dataSource ) {
59
- this .dataSource = dataSource ;
60
- this .username = null ; this .password = null ;
61
- }
62
-
63
- public DataSourceConnectionFactoryImpl (final DataSource dataSource ,
64
- final String username , final String password ) {
65
- this .dataSource = dataSource ;
66
- this .username = username ; this .password = password ;
67
- }
68
-
69
- @ Override
70
- public Connection newConnection () throws SQLException {
71
- if ( username != null ) {
72
- dataSource .getConnection (username , password );
73
- }
74
- return dataSource .getConnection ();
75
- }
76
-
77
- DataSource getDataSource () { return dataSource ; } /* for tests */
78
-
79
- }
80
-
81
- class DriverConnectionFactoryImpl implements ConnectionFactory {
82
-
83
- private final DriverWrapper driverWrapper ;
84
- final String url ;
85
- final String username , password ; // null allowed
86
-
87
- public DriverConnectionFactoryImpl (final DriverWrapper driver , final String url ) {
88
- this .driverWrapper = driver ; this .url = url ;
89
- this .username = null ; this .password = null ;
90
- }
91
-
92
- public DriverConnectionFactoryImpl (final DriverWrapper driver , final String url ,
93
- final String username , final String password ) {
94
- this .driverWrapper = driver ; this .url = url ;
95
- this .username = username ; this .password = password ;
96
- }
97
-
98
- @ Override
99
- public Connection newConnection () throws SQLException {
100
- return driverWrapper .connect (url , username , password );
101
- }
102
-
103
- DriverWrapper getDriverWrapper () { return driverWrapper ; } /* for tests */
104
-
105
- }
106
-
107
- // @legacy ActiveRecord::ConnectionAdapters::JdbcDriver
108
- class RubyConnectionFactoryImpl implements ConnectionFactory {
109
-
110
- private final IRubyObject driver ;
111
- final RubyString url ;
112
- final IRubyObject username , password ; // null allowed
113
-
114
- private final RubyObject contextProvider ;
115
-
116
- public RubyConnectionFactoryImpl (final IRubyObject driver , final RubyString url ,
117
- final IRubyObject username , final IRubyObject password ) {
118
- this .driver = driver ; this .url = url ;
119
- this .username = username ; this .password = password ;
120
- contextProvider = (RubyObject ) driver ;
121
- }
122
-
123
- @ Override
124
- public Connection newConnection () throws SQLException {
125
- final ThreadContext context = contextProvider .getRuntime ().getCurrentContext ();
126
- final IRubyObject connection = driver .callMethod (context , "connection" , new IRubyObject [] { url , username , password });
127
- return (Connection ) connection .toJava (Connection .class );
128
- }
129
-
130
- IRubyObject getDriver () { return driver ; } /* for tests */
131
-
132
- }
0 commit comments