35
35
* @author Eric Nielsen
36
36
*/
37
37
public class Base {
38
-
39
- public static final String DEFAULT_DB_NAME = "default" ;
40
-
41
38
/**
42
39
* Opens a new connection based on JDBC properties and attaches it to a current thread.
43
40
*
@@ -47,7 +44,7 @@ public class Base {
47
44
* @param password password.
48
45
*/
49
46
public static void open (String driver , String url , String user , String password ) {
50
- new DB (DEFAULT_DB_NAME ).open (driver , url , user , password );
47
+ new DB (DB . DEFAULT_NAME ).open (driver , url , user , password );
51
48
}
52
49
53
50
@@ -59,7 +56,7 @@ public static void open(String driver, String url, String user, String password)
59
56
* @param props connection properties
60
57
*/
61
58
public static void open (String driver , String url , Properties props ) {
62
- new DB (DEFAULT_DB_NAME ).open (driver , url , props );
59
+ new DB (DB . DEFAULT_NAME ).open (driver , url , props );
63
60
}
64
61
65
62
/**
@@ -69,7 +66,7 @@ public static void open(String driver, String url, Properties props) {
69
66
* @param jndiName name of a configured data source.
70
67
*/
71
68
public static void open (String jndiName ) {
72
- new DB (DEFAULT_DB_NAME ).open (jndiName );
69
+ new DB (DB . DEFAULT_NAME ).open (jndiName );
73
70
}
74
71
75
72
/**
@@ -80,7 +77,7 @@ public static void open(String jndiName) {
80
77
* @param jndiProperties JNDI properties
81
78
*/
82
79
public static void open (String jndiName , Properties jndiProperties ) {
83
- new DB (DEFAULT_DB_NAME ).open (jndiName , jndiProperties );
80
+ new DB (DB . DEFAULT_NAME ).open (jndiName , jndiProperties );
84
81
}
85
82
86
83
/**
@@ -89,7 +86,7 @@ public static void open(String jndiName, Properties jndiProperties) {
89
86
* @param dataSource datasource will be used to acquire a connection.
90
87
*/
91
88
public static void open (DataSource dataSource ) {
92
- new DB (DEFAULT_DB_NAME ).open (dataSource );
89
+ new DB (DB . DEFAULT_NAME ).open (dataSource );
93
90
}
94
91
95
92
@@ -99,7 +96,7 @@ public static void open(DataSource dataSource) {
99
96
* @return connection attached to a current thread and named "default".
100
97
*/
101
98
public static Connection connection () {
102
- return new DB (DEFAULT_DB_NAME ).connection ();
99
+ return new DB (DB . DEFAULT_NAME ).connection ();
103
100
104
101
}
105
102
@@ -109,8 +106,8 @@ public static Connection connection() {
109
106
*
110
107
* @return true if finds default connection on current thread, false if not.
111
108
*/
112
- public static boolean hasConnection (){
113
- return new DB (DEFAULT_DB_NAME ).hasConnection ();
109
+ public static boolean hasConnection () {
110
+ return new DB (DB . DEFAULT_NAME ).hasConnection ();
114
111
}
115
112
116
113
@@ -120,14 +117,14 @@ public static boolean hasConnection(){
120
117
* @param suppressWarning true to not display a warning in case of a problem (connection not there)
121
118
*/
122
119
public static void close (boolean suppressWarning ) {
123
- new DB (DEFAULT_DB_NAME ).close (suppressWarning );
120
+ new DB (DB . DEFAULT_NAME ).close (suppressWarning );
124
121
}
125
122
126
123
/**
127
124
* Closes connection and detaches it from current thread.
128
125
*/
129
126
public static void close () {
130
- new DB (DEFAULT_DB_NAME ).close ();
127
+ new DB (DB . DEFAULT_NAME ).close ();
131
128
}
132
129
133
130
/**
@@ -136,8 +133,8 @@ public static void close() {
136
133
* @param table name of table.
137
134
* @return count of rows in table.
138
135
*/
139
- public static Long count (String table ){
140
- return new DB (DEFAULT_DB_NAME ).count (table );
136
+ public static Long count (String table ) {
137
+ return new DB (DB . DEFAULT_NAME ).count (table );
141
138
}
142
139
143
140
/**
@@ -150,9 +147,9 @@ public static Long count(String table){
150
147
* @return copunt number of records found in a table.
151
148
*/
152
149
public static Long count (String table , String query , Object ... params ) {
153
- return new DB (DEFAULT_DB_NAME ).count (table , query , params );
150
+ return new DB (DB . DEFAULT_NAME ).count (table , query , params );
154
151
}
155
-
152
+
156
153
/**
157
154
* Returns a value of the first column of the first row.
158
155
* This query expects only one column selected in the select statement.
@@ -163,7 +160,7 @@ public static Long count(String table, String query, Object... params) {
163
160
* @return fetched value, or null if query did not fetch anything.
164
161
*/
165
162
public static Object firstCell (String query , Object ... params ) {
166
- return new DB (DEFAULT_DB_NAME ).firstCell (query , params );
163
+ return new DB (DB . DEFAULT_NAME ).firstCell (query , params );
167
164
}
168
165
169
166
/**
@@ -179,8 +176,8 @@ public static Object firstCell(String query, Object... params) {
179
176
* @param params list of parameters for a parametrized query.
180
177
* @return entire result set corresponding to the query.
181
178
*/
182
- public static List <Map > findAll (String query , Object ... params ) {
183
- return new DB (DEFAULT_DB_NAME ).findAll (query , params );
179
+ public static List <Map > findAll (String query , Object ... params ) {
180
+ return new DB (DB . DEFAULT_NAME ).findAll (query , params );
184
181
}
185
182
186
183
/**
@@ -199,8 +196,8 @@ public static List<Map> findAll(String query, Object ... params) {
199
196
* @param params list of parameters for a parametrized query.
200
197
* @return entire result set corresponding to the query.
201
198
*/
202
- public static List firstColumn (String query , Object ... params ) {
203
- return new DB (DEFAULT_DB_NAME ).firstColumn (query , params );
199
+ public static List firstColumn (String query , Object ... params ) {
200
+ return new DB (DB . DEFAULT_NAME ).firstColumn (query , params );
204
201
}
205
202
206
203
/**
@@ -210,7 +207,7 @@ public static List firstColumn(String query, Object ... params) {
210
207
* @return entire result set corresponding to the query.
211
208
*/
212
209
public static List <Map > findAll (String query ) {
213
- return new DB (DEFAULT_DB_NAME ).findAll (query );
210
+ return new DB (DB . DEFAULT_NAME ).findAll (query );
214
211
}
215
212
216
213
/**
@@ -232,7 +229,7 @@ public void onNext(Map row) {
232
229
*/
233
230
@ Deprecated
234
231
public static RowProcessor find (String query , Object ... params ) {
235
- return new DB (DEFAULT_DB_NAME ).find (query , params );
232
+ return new DB (DB . DEFAULT_NAME ).find (query , params );
236
233
}
237
234
238
235
/**
@@ -258,7 +255,7 @@ public static RowProcessor find(String query, Object... params) {
258
255
* @param params parameters of parametrized query
259
256
*/
260
257
public static void findWith (ResultSetListener listener , boolean streaming , String query , Object ... params ) {
261
- new DB (DEFAULT_DB_NAME ).findWith (listener , streaming , query , params );
258
+ new DB (DB . DEFAULT_NAME ).findWith (listener , streaming , query , params );
262
259
}
263
260
264
261
/**
@@ -271,7 +268,7 @@ public static void findWith(ResultSetListener listener, boolean streaming, Strin
271
268
*/
272
269
@ Deprecated
273
270
public static void find (String sql , RowListener listener ) {
274
- new DB (DEFAULT_DB_NAME ).find (sql , listener );
271
+ new DB (DB . DEFAULT_NAME ).find (sql , listener );
275
272
}
276
273
277
274
/**
@@ -286,7 +283,7 @@ public static void find(String sql, RowListener listener) {
286
283
* @param query raw SQL query
287
284
*/
288
285
public static void findWith (ResultSetListener listener , boolean streaming , String query ) {
289
- new DB (DEFAULT_DB_NAME ).findWith (listener , streaming , query );
286
+ new DB (DB . DEFAULT_NAME ).findWith (listener , streaming , query );
290
287
}
291
288
292
289
/**
@@ -295,8 +292,8 @@ public static void findWith(ResultSetListener listener, boolean streaming, Strin
295
292
* @param query raw DML.
296
293
* @return number of rows afected by query.
297
294
*/
298
- public static int exec (String query ){
299
- return new DB (DEFAULT_DB_NAME ).exec (query );
295
+ public static int exec (String query ) {
296
+ return new DB (DB . DEFAULT_NAME ).exec (query );
300
297
}
301
298
302
299
@@ -307,43 +304,42 @@ public static int exec(String query){
307
304
* @param params query parameters.
308
305
* @return number of records affected.
309
306
*/
310
- public static int exec (String query , Object ... params ){
311
- return new DB (DEFAULT_DB_NAME ).exec (query , params );
307
+ public static int exec (String query , Object ... params ) {
308
+ return new DB (DB . DEFAULT_NAME ).exec (query , params );
312
309
}
313
-
314
310
315
311
/**
316
312
* This method is specific for inserts.
317
- *
313
+ *
318
314
* @param query SQL for inserts.
319
315
* @param autoIncrementColumnName name of a column that is auto-incremented.
320
316
* @param params list of parameter values.
321
317
* @return new value of auto-incremented column that is uniquely identifying a new record inserted. May return -1 if this
322
318
* functionality is not supported by DB or driver.
323
319
*/
324
320
static Object execInsert (String query , String autoIncrementColumnName , Object ... params ) {
325
- return new DB (DEFAULT_DB_NAME ).execInsert (query , autoIncrementColumnName , params );
321
+ return new DB (DB . DEFAULT_NAME ).execInsert (query , autoIncrementColumnName , params );
326
322
}
327
323
328
324
/**
329
325
* Opens local transaction.
330
326
*/
331
327
public static void openTransaction () {
332
- new DB (DEFAULT_DB_NAME ).openTransaction ();
328
+ new DB (DB . DEFAULT_NAME ).openTransaction ();
333
329
}
334
330
335
331
/**
336
332
* Commits local transaction.
337
333
*/
338
334
public static void commitTransaction () {
339
- new DB (DEFAULT_DB_NAME ).commitTransaction ();
335
+ new DB (DB . DEFAULT_NAME ).commitTransaction ();
340
336
}
341
337
342
338
/**
343
339
* Rolls back local transaction.
344
340
*/
345
341
public static void rollbackTransaction () {
346
- new DB (DEFAULT_DB_NAME ).rollbackTransaction ();
342
+ new DB (DB . DEFAULT_NAME ).rollbackTransaction ();
347
343
}
348
344
349
345
/**
@@ -352,8 +348,8 @@ public static void rollbackTransaction() {
352
348
* @param parametrizedStatement Example of a statement: <code>INSERT INTO employees VALUES (?, ?)</code>.
353
349
* @return instance of <code>java.sql.PreparedStatement</code> with compiled query.
354
350
*/
355
- public static PreparedStatement startBatch (String parametrizedStatement ){
356
- return new DB (DEFAULT_DB_NAME ).startBatch (parametrizedStatement );
351
+ public static PreparedStatement startBatch (String parametrizedStatement ) {
352
+ return new DB (DB . DEFAULT_NAME ).startBatch (parametrizedStatement );
357
353
}
358
354
359
355
/**
@@ -362,17 +358,17 @@ public static PreparedStatement startBatch(String parametrizedStatement){
362
358
* @param parameters parameters for the query in <code>java.sql.PreparedStatement</code>. Parameters will be
363
359
* set on the statement in the same order as provided here.
364
360
*/
365
- public static void addBatch (PreparedStatement ps , Object ... parameters ){
366
- new DB (DEFAULT_DB_NAME ).addBatch (ps , parameters );
361
+ public static void addBatch (PreparedStatement ps , Object ... parameters ) {
362
+ new DB (DB . DEFAULT_NAME ).addBatch (ps , parameters );
367
363
}
368
364
369
365
/**
370
366
* Executes a batch on <code>java.sql.PreparedStatement</code>.
371
367
*
372
368
* @param ps <code>java.sql.PreparedStatement</code> to execute batch on.
373
369
*/
374
- public static void executeBatch (PreparedStatement ps ){
375
- new DB (DEFAULT_DB_NAME ).executeBatch (ps );
370
+ public static void executeBatch (PreparedStatement ps ) {
371
+ new DB (DB . DEFAULT_NAME ).executeBatch (ps );
376
372
}
377
373
378
374
@@ -381,8 +377,8 @@ public static void executeBatch(PreparedStatement ps){
381
377
*
382
378
* @param connection instance of connection to attach to current thread.
383
379
*/
384
- public static void attach (Connection connection ){
385
- new DB (DEFAULT_DB_NAME ).attach (connection );
380
+ public static void attach (Connection connection ) {
381
+ new DB (DB . DEFAULT_NAME ).attach (connection );
386
382
}
387
383
388
384
/**
@@ -392,6 +388,6 @@ public static void attach(Connection connection){
392
388
* @return instance of a default connection detached from current thread by name passed to constructor.
393
389
*/
394
390
public static Connection detach () {
395
- return new DB (DEFAULT_DB_NAME ).detach ();
391
+ return new DB (DB . DEFAULT_NAME ).detach ();
396
392
}
397
393
}
0 commit comments