Skip to content

Commit 07be740

Browse files
committed
#374 Moved Base.DEFAULT_DB_NAME to DB.DEFAULT_NAME
as a public member, and it was private before pushing this (so this is backwards compatible)
1 parent 3c03b7e commit 07be740

File tree

3 files changed

+44
-47
lines changed

3 files changed

+44
-47
lines changed

activejdbc/src/main/java/org/javalite/activejdbc/Base.java

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
* @author Eric Nielsen
3636
*/
3737
public class Base {
38-
39-
public static final String DEFAULT_DB_NAME = "default";
40-
4138
/**
4239
* Opens a new connection based on JDBC properties and attaches it to a current thread.
4340
*
@@ -47,7 +44,7 @@ public class Base {
4744
* @param password password.
4845
*/
4946
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);
5148
}
5249

5350

@@ -59,7 +56,7 @@ public static void open(String driver, String url, String user, String password)
5956
* @param props connection properties
6057
*/
6158
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);
6360
}
6461

6562
/**
@@ -69,7 +66,7 @@ public static void open(String driver, String url, Properties props) {
6966
* @param jndiName name of a configured data source.
7067
*/
7168
public static void open(String jndiName) {
72-
new DB(DEFAULT_DB_NAME).open(jndiName);
69+
new DB(DB.DEFAULT_NAME).open(jndiName);
7370
}
7471

7572
/**
@@ -80,7 +77,7 @@ public static void open(String jndiName) {
8077
* @param jndiProperties JNDI properties
8178
*/
8279
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);
8481
}
8582

8683
/**
@@ -89,7 +86,7 @@ public static void open(String jndiName, Properties jndiProperties) {
8986
* @param dataSource datasource will be used to acquire a connection.
9087
*/
9188
public static void open(DataSource dataSource) {
92-
new DB(DEFAULT_DB_NAME).open(dataSource);
89+
new DB(DB.DEFAULT_NAME).open(dataSource);
9390
}
9491

9592

@@ -99,7 +96,7 @@ public static void open(DataSource dataSource) {
9996
* @return connection attached to a current thread and named "default".
10097
*/
10198
public static Connection connection() {
102-
return new DB(DEFAULT_DB_NAME).connection();
99+
return new DB(DB.DEFAULT_NAME).connection();
103100

104101
}
105102

@@ -109,8 +106,8 @@ public static Connection connection() {
109106
*
110107
* @return true if finds default connection on current thread, false if not.
111108
*/
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();
114111
}
115112

116113

@@ -120,14 +117,14 @@ public static boolean hasConnection(){
120117
* @param suppressWarning true to not display a warning in case of a problem (connection not there)
121118
*/
122119
public static void close(boolean suppressWarning) {
123-
new DB(DEFAULT_DB_NAME).close(suppressWarning);
120+
new DB(DB.DEFAULT_NAME).close(suppressWarning);
124121
}
125122

126123
/**
127124
* Closes connection and detaches it from current thread.
128125
*/
129126
public static void close() {
130-
new DB(DEFAULT_DB_NAME).close();
127+
new DB(DB.DEFAULT_NAME).close();
131128
}
132129

133130
/**
@@ -136,8 +133,8 @@ public static void close() {
136133
* @param table name of table.
137134
* @return count of rows in table.
138135
*/
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);
141138
}
142139

143140
/**
@@ -150,9 +147,9 @@ public static Long count(String table){
150147
* @return copunt number of records found in a table.
151148
*/
152149
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);
154151
}
155-
152+
156153
/**
157154
* Returns a value of the first column of the first row.
158155
* 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) {
163160
* @return fetched value, or null if query did not fetch anything.
164161
*/
165162
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);
167164
}
168165

169166
/**
@@ -179,8 +176,8 @@ public static Object firstCell(String query, Object... params) {
179176
* @param params list of parameters for a parametrized query.
180177
* @return entire result set corresponding to the query.
181178
*/
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);
184181
}
185182

186183
/**
@@ -199,8 +196,8 @@ public static List<Map> findAll(String query, Object ... params) {
199196
* @param params list of parameters for a parametrized query.
200197
* @return entire result set corresponding to the query.
201198
*/
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);
204201
}
205202

206203
/**
@@ -210,7 +207,7 @@ public static List firstColumn(String query, Object ... params) {
210207
* @return entire result set corresponding to the query.
211208
*/
212209
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);
214211
}
215212

216213
/**
@@ -232,7 +229,7 @@ public void onNext(Map row) {
232229
*/
233230
@Deprecated
234231
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);
236233
}
237234

238235
/**
@@ -258,7 +255,7 @@ public static RowProcessor find(String query, Object... params) {
258255
* @param params parameters of parametrized query
259256
*/
260257
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);
262259
}
263260

264261
/**
@@ -271,7 +268,7 @@ public static void findWith(ResultSetListener listener, boolean streaming, Strin
271268
*/
272269
@Deprecated
273270
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);
275272
}
276273

277274
/**
@@ -286,7 +283,7 @@ public static void find(String sql, RowListener listener) {
286283
* @param query raw SQL query
287284
*/
288285
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);
290287
}
291288

292289
/**
@@ -295,8 +292,8 @@ public static void findWith(ResultSetListener listener, boolean streaming, Strin
295292
* @param query raw DML.
296293
* @return number of rows afected by query.
297294
*/
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);
300297
}
301298

302299

@@ -307,43 +304,42 @@ public static int exec(String query){
307304
* @param params query parameters.
308305
* @return number of records affected.
309306
*/
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);
312309
}
313-
314310

315311
/**
316312
* This method is specific for inserts.
317-
*
313+
*
318314
* @param query SQL for inserts.
319315
* @param autoIncrementColumnName name of a column that is auto-incremented.
320316
* @param params list of parameter values.
321317
* @return new value of auto-incremented column that is uniquely identifying a new record inserted. May return -1 if this
322318
* functionality is not supported by DB or driver.
323319
*/
324320
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);
326322
}
327323

328324
/**
329325
* Opens local transaction.
330326
*/
331327
public static void openTransaction() {
332-
new DB(DEFAULT_DB_NAME).openTransaction();
328+
new DB(DB.DEFAULT_NAME).openTransaction();
333329
}
334330

335331
/**
336332
* Commits local transaction.
337333
*/
338334
public static void commitTransaction() {
339-
new DB(DEFAULT_DB_NAME).commitTransaction();
335+
new DB(DB.DEFAULT_NAME).commitTransaction();
340336
}
341337

342338
/**
343339
* Rolls back local transaction.
344340
*/
345341
public static void rollbackTransaction() {
346-
new DB(DEFAULT_DB_NAME).rollbackTransaction();
342+
new DB(DB.DEFAULT_NAME).rollbackTransaction();
347343
}
348344

349345
/**
@@ -352,8 +348,8 @@ public static void rollbackTransaction() {
352348
* @param parametrizedStatement Example of a statement: <code>INSERT INTO employees VALUES (?, ?)</code>.
353349
* @return instance of <code>java.sql.PreparedStatement</code> with compiled query.
354350
*/
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);
357353
}
358354

359355
/**
@@ -362,17 +358,17 @@ public static PreparedStatement startBatch(String parametrizedStatement){
362358
* @param parameters parameters for the query in <code>java.sql.PreparedStatement</code>. Parameters will be
363359
* set on the statement in the same order as provided here.
364360
*/
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);
367363
}
368364

369365
/**
370366
* Executes a batch on <code>java.sql.PreparedStatement</code>.
371367
*
372368
* @param ps <code>java.sql.PreparedStatement</code> to execute batch on.
373369
*/
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);
376372
}
377373

378374

@@ -381,8 +377,8 @@ public static void executeBatch(PreparedStatement ps){
381377
*
382378
* @param connection instance of connection to attach to current thread.
383379
*/
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);
386382
}
387383

388384
/**
@@ -392,6 +388,6 @@ public static void attach(Connection connection){
392388
* @return instance of a default connection detached from current thread by name passed to constructor.
393389
*/
394390
public static Connection detach() {
395-
return new DB(DEFAULT_DB_NAME).detach();
391+
return new DB(DB.DEFAULT_NAME).detach();
396392
}
397393
}

activejdbc/src/main/java/org/javalite/activejdbc/DB.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class DB {
4444
static final Pattern INSERT_PATTERN = Pattern.compile("^\\s*INSERT",
4545
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
4646

47+
public static final String DEFAULT_NAME = "default";
4748

4849
private final String dbName;
4950

activejdbc/src/main/java/org/javalite/activejdbc/MetaModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ protected void checkAttributeOrAssociation(String attributeOrAssociation) {
374374

375375
protected static String getDbName(Class<? extends Model> modelClass) {
376376
DbName dbNameAnnotation = modelClass.getAnnotation(DbName.class);
377-
return dbNameAnnotation == null ? Base.DEFAULT_DB_NAME : dbNameAnnotation.value();
377+
return dbNameAnnotation == null ? DB.DEFAULT_NAME : dbNameAnnotation.value();
378378
}
379379

380380
/**

0 commit comments

Comments
 (0)