This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a48e675
commit c7f80a9
Showing
6 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
package com.blade.jdbc; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.sql2o.Sql2o; | ||
|
||
public final class Base { | ||
public static Sql2o sql2o; | ||
|
||
public static Map<String, Sql2o> sql2oMap = new HashMap<String, Sql2o>(8); | ||
|
||
public static void open(String url, String user, String password) { | ||
sql2o = new Sql2o(url, user, password); | ||
sql2oMap.put(Const.DEFAULT_DB_NAME, new Sql2o(url, user, password)); | ||
} | ||
|
||
public static void open(DataSource dataSource) { | ||
sql2o = new Sql2o(dataSource); | ||
sql2oMap.put(Const.DEFAULT_DB_NAME, new Sql2o(dataSource)); | ||
} | ||
|
||
public static void open(String dbName, DataSource dataSource) { | ||
sql2oMap.put(dbName, new Sql2o(dataSource)); | ||
} | ||
|
||
public static Sql2o database() { | ||
return sql2oMap.get(Const.DEFAULT_DB_NAME); | ||
} | ||
|
||
public static Sql2o database(String dbName) { | ||
return sql2oMap.get(dbName); | ||
} | ||
|
||
public static void execute(String sql) { | ||
database().open().createQuery(sql).executeUpdate(); | ||
} | ||
|
||
public static void execute(String sql){ | ||
sql2o.open().createQuery(sql).executeUpdate(); | ||
public static void execute(String dbName, String sql) { | ||
database(dbName).open().createQuery(sql).executeUpdate(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters