Mercurial > hg > mpdl-group
comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/donatus/xmlrpc/DonatusBerkeleyDbEnv.java @ 0:408254cf2f1d
Erstellung
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 24 Nov 2010 17:24:23 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:408254cf2f1d |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.donatus.xmlrpc; | |
2 | |
3 import java.io.File; | |
4 | |
5 import com.sleepycat.je.Database; | |
6 import com.sleepycat.je.DatabaseConfig; | |
7 import com.sleepycat.je.DatabaseException; | |
8 import com.sleepycat.je.Environment; | |
9 import com.sleepycat.je.EnvironmentConfig; | |
10 | |
11 public class DonatusBerkeleyDbEnv { | |
12 private File envPath; | |
13 private Environment env; | |
14 private Database lemmaDb; | |
15 private Database variantDb; | |
16 | |
17 public DonatusBerkeleyDbEnv() { | |
18 } | |
19 | |
20 public void setup(boolean readOnly) throws DatabaseException { | |
21 EnvironmentConfig envConfig = new EnvironmentConfig(); | |
22 DatabaseConfig dbConfig = new DatabaseConfig(); | |
23 // If the environment is read-only, then make the databases read-only too. | |
24 envConfig.setReadOnly(readOnly); | |
25 dbConfig.setReadOnly(readOnly); | |
26 // If the environment is opened for write, then we want to be able to create the environment and databases if they do not exist. | |
27 envConfig.setAllowCreate(!readOnly); | |
28 dbConfig.setAllowCreate(!readOnly); | |
29 // Allow transactions if we are writing to the database | |
30 envConfig.setTransactional(!readOnly); | |
31 dbConfig.setTransactional(!readOnly); | |
32 // Open the environment | |
33 envPath = new File(DonatusConstants.BERKELEY_DB_DIR); | |
34 env = new Environment(envPath, envConfig); | |
35 // open databases (and create them if not existent) | |
36 lemmaDb = env.openDatabase(null, "LemmaDB", dbConfig); | |
37 variantDb = env.openDatabase(null, "VariantDB", dbConfig); | |
38 } | |
39 | |
40 public void removeDatabases() { | |
41 try { | |
42 lemmaDb.close(); | |
43 variantDb.close(); | |
44 env.removeDatabase(null, "LemmaDB"); | |
45 env.removeDatabase(null, "VariantDB"); | |
46 } catch (DatabaseException e) { | |
47 e.printStackTrace(); // TODO | |
48 } | |
49 } | |
50 | |
51 public Environment getEnv() { | |
52 return env; | |
53 } | |
54 | |
55 public Database getLemmaDB() { | |
56 return lemmaDb; | |
57 } | |
58 | |
59 public Database getVariantDB() { | |
60 return variantDb; | |
61 } | |
62 | |
63 public void close() { | |
64 if (env != null) { | |
65 try { | |
66 lemmaDb.close(); | |
67 variantDb.close(); | |
68 env.close(); | |
69 } catch(DatabaseException e) { | |
70 e.printStackTrace(); // TODO | |
71 } | |
72 } | |
73 } | |
74 } | |
75 |