1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
Files
gnosygnu_xowa/140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr.java

65 lines
2.1 KiB
Java
Raw Normal View History

2015-07-12 21:10:02 -04:00
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
2015-11-22 21:39:33 -05:00
import gplx.core.stores.*;
2015-07-12 21:10:02 -04:00
class TdbDbSaveMgr {
public void SaveDb(TdbDatabase db) {
for (Object filObj : db.Files()) {
TdbFile fil = (TdbFile)filObj;
SaveFile(db, fil);
}
}
public void SaveFile(TdbDatabase db, TdbFile fil) {
List_adp tbls = FetchTablesWithSamePath(db, fil.Path());
boolean isSaveNeeded = db.IsNew();
for (Object tblObj : tbls) {
TdbTable tbl = (TdbTable)tblObj;
if (tbl.IsDirty()) {
isSaveNeeded = true;
break;
}
}
if (isSaveNeeded) {
SaveTblsToFile(db, fil, tbls);
db.IsNew_set(false);
}
}
void SaveTblsToFile(TdbDatabase db, TdbFile fil, List_adp tbls) {
DataWtr wtr = TdbStores.wtr_();
if (fil.Id() == TdbFile.MainFileId) { // if MainFile, save critical Files and Tables data
db.Files().DataObj_Wtr(wtr);
db.Tables().DataObj_Wtr(wtr);
}
for (Object tblObj : tbls) {
TdbTable tbl = (TdbTable)tblObj;
tbl.DataObj_Wtr(wtr);
}
2015-10-18 22:17:57 -04:00
Io_mgr.Instance.SaveFilStr(fil.Path(), wtr.To_str());
2015-07-12 21:10:02 -04:00
}
List_adp FetchTablesWithSamePath(TdbDatabase db, Io_url filPath) {
2016-06-19 23:58:10 -04:00
List_adp list = List_adp_.New();
2015-07-12 21:10:02 -04:00
for (Object tblObj : db.Tables()) {
TdbTable tbl = (TdbTable)tblObj;
if (tbl.File().Path().Eq (filPath))
list.Add(tbl);
}
return list;
}
public static TdbDbSaveMgr new_() {return new TdbDbSaveMgr();} TdbDbSaveMgr() {}
}