01: /*
02: $Id: AddrFileDB.java 319 2005-08-25 14:52:30Z membar $\n$Id: AddrFileDB.java 319 2005-08-25 14:52:30Z membar $$Id: AddrFileDB.java 319 2005-08-25 14:52:30Z membar $This file is part of BORG.
03:
04: BORG is free software; you can redistribute it and/or modify
05: it under the terms of the GNU General Public License as published by
06: the Free Software Foundation; either version 2 of the License, or
07: (at your option) any later version.
08:
09: BORG is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License
15: along with BORG; if not, write to the Free Software
16: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17:
18: Copyright 2003 by Mike Berger
19: */
20:
21: package net.sf.borg.model.db.file;
22:
23: import java.io.File;
24: import java.net.URL;
25:
26: import net.sf.borg.common.Errmsg;
27: import net.sf.borg.common.Resource;
28: import net.sf.borg.common.XTree;
29: import net.sf.borg.model.db.file.mdb.MDB;
30: import net.sf.borg.model.db.file.mdb.SMDB;
31: import net.sf.borg.model.db.file.mdb.Schema;
32:
33: class AddrFileDB extends FileDBCreator {
34: AddrFileDB() {
35: }
36:
37: final void init(String file, boolean shared) throws Exception {
38: file = file + "/addr.jdb";
39:
40: AddressAdapter ta = new AddressAdapter();
41: Schema schema = new Schema();
42: URL schurl = getClass()
43: .getResource("/resource/addr_schema.xml");
44: XTree sch_xml = XTree.readFromURL(schurl);
45: schema.setFromXML(sch_xml);
46:
47: // create the database if it does not exist
48: boolean newdb = false;
49: File fp = new File(file);
50: if (!fp.exists()) {
51: Errmsg.notice(Resource
52: .getResourceString("Creating_DB_file:_")
53: + file);
54: SMDB.create("BorgAddr Database", file, 200, schema);
55: newdb = true;
56: }
57:
58: db_ = new FileBeanDB(file, MDB.READ_WRITE, ta, shared);
59:
60: // check schema for update - transition
61: FileBeanDB fdb = (FileBeanDB) db_;
62: if (newdb) {
63: fdb.setNormalize(true);
64: }
65: Schema oldsch = fdb.getSchema();
66: try {
67: oldsch.getType("DEL");
68: } catch (Exception e) {
69: // DB does not have new fields - update the schema
70: fdb.setSchema(schema);
71: }
72: }
73:
74: }
|