From 98112eef6b5def28fbb7fb34ca49e76849126f41 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 15 Oct 2014 14:30:47 +0800 Subject: [PATCH] Update FinalDb.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加removeDBFromCache和closeDb方法,用于某些情况下数据库文件动态改变,数据库名称不变需要重新加载daoMap存在的数据库实例不更新问题. --- src/net/tsz/afinal/FinalDb.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/net/tsz/afinal/FinalDb.java b/src/net/tsz/afinal/FinalDb.java index 52b700e..cc56d8a 100644 --- a/src/net/tsz/afinal/FinalDb.java +++ b/src/net/tsz/afinal/FinalDb.java @@ -391,6 +391,26 @@ public void dropDb() { } } + /** + * 重新加载指定数据库,清除daoMap中的指定数据库 + * + * @param dbName + * @return + */ + public void removeDBFromCache(String dbName){ + if(daoMap.containsKey(dbName)){ + FinalDB db=daoMap.get(dbName); + db.closeDb(); + daoMap.remove(dbName) + } + } + //关闭数据库 + private void closeDB(){ + try { + db.close(); + } catch (Exception e) { + } + } private void exeSqlInfo(SqlInfo sqlInfo) { if (sqlInfo != null) { debugSql(sqlInfo.getSql());