DbKit.java 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.yihu.quota.util.sql;
  2. import java.util.HashMap;
  3. public class DbKit {
  4. private Db defaultDb;
  5. private HashMap<Db.Type, Db> mapDB = new HashMap<>();
  6. private DbKit(Db.Type type) {
  7. Db db = mapDB.get(type);
  8. if (db != null) {
  9. defaultDb = db;
  10. return;
  11. }
  12. switch (type) {
  13. case mysql:
  14. db = new MysqlDb();
  15. break;
  16. case oracle:
  17. db = new OracleDb();
  18. break;
  19. default:
  20. break;
  21. }
  22. defaultDb = db;
  23. mapDB.put(type, db);
  24. }
  25. public static DbKit use() {
  26. return use(Db.Type.mysql);
  27. }
  28. public static DbKit use(Db.Type type) {
  29. return new DbKit(type);
  30. }
  31. public String getDate(String value) {
  32. return defaultDb.getDate(value);
  33. }
  34. public String getLongDate(String value) {
  35. return defaultDb.getLongDate(value);
  36. }
  37. public String getNumber(String value) {
  38. return defaultDb.getNumber(value);
  39. }
  40. }