01: /*
02: 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 TaskFileDB extends FileDBCreator {
34: TaskFileDB() {
35: }
36:
37: final void init(String file, boolean shared) throws Exception {
38: file = file + "/mrdb.jdb";
39:
40: TaskAdapter ta = new TaskAdapter();
41: // set the schema for the task DB
42: Schema schema = new Schema();
43: URL schurl = getClass()
44: .getResource("/resource/task_schema.xml");
45: XTree sch_xml = XTree.readFromURL(schurl);
46: schema.setFromXML(sch_xml);
47:
48: // create the database if it does not exisit
49: File fp = new File(file);
50: boolean newdb = false;
51: if (!fp.exists()) {
52: // System.out.println( "Task DB does not exist...creating DB " );
53: Errmsg.notice(Resource
54: .getResourceString("Creating_DB_file:_")
55: + file);
56: SMDB.create(
57: Resource.getResourceString("BorgTrac_Database"),
58: file, 100, schema);
59: newdb = true;
60: }
61:
62: // open the DB with the proper mode
63:
64: db_ = new FileBeanDB(file, MDB.READ_WRITE, ta, shared);
65:
66: // check schema for update - transition
67: FileBeanDB fdb = (FileBeanDB) db_;
68: if (newdb) {
69: fdb.setNormalize(true);
70: }
71: Schema oldsch = fdb.getSchema();
72: try {
73: oldsch.getType("UT1");
74: oldsch.getType("CAT");
75: } catch (Exception e) {
76: // DB does not have new fields - update the schema
77: fdb.setSchema(schema);
78: }
79: }
80: }
|