1 package persist.gettingStarted; 2 3 import java.io.File ; 4 5 import com.sleepycat.je.DatabaseException; 6 import com.sleepycat.je.Environment; 7 import com.sleepycat.je.EnvironmentConfig; 8 9 import com.sleepycat.persist.EntityStore; 10 import com.sleepycat.persist.StoreConfig; 11 12 public class MyDbEnv { 13 14 private Environment myEnv; 15 private EntityStore store; 16 17 public MyDbEnv() {} 19 20 public void setup(File envHome, boolean readOnly) 23 throws DatabaseException { 24 25 EnvironmentConfig myEnvConfig = new EnvironmentConfig(); 26 StoreConfig storeConfig = new StoreConfig(); 27 28 myEnvConfig.setReadOnly(readOnly); 29 storeConfig.setReadOnly(readOnly); 30 31 myEnvConfig.setAllowCreate(!readOnly); 35 storeConfig.setAllowCreate(!readOnly); 36 37 myEnvConfig.setTransactional(!readOnly); 39 storeConfig.setTransactional(!readOnly); 40 41 myEnv = new Environment(envHome, myEnvConfig); 43 store = new EntityStore(myEnv, "EntityStore", storeConfig); 44 45 } 46 47 public EntityStore getEntityStore() { 49 return store; 50 } 51 52 public Environment getEnv() { 54 return myEnv; 55 } 56 57 58 public void close() { 60 if (store != null) { 61 try { 62 store.close(); 63 } catch(DatabaseException dbe) { 64 System.err.println("Error closing store: " + 65 dbe.toString()); 66 System.exit(-1); 67 } 68 } 69 70 if (myEnv != null) { 71 try { 72 myEnv.close(); 74 } catch(DatabaseException dbe) { 75 System.err.println("Error closing MyDbEnv: " + 76 dbe.toString()); 77 System.exit(-1); 78 } 79 } 80 } 81 } 82 83
| Popular Tags
|