public boolean setup(boolean readOnly) { boolean open = false; try { EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setReadOnly(readOnly); envConfig.setAllowCreate(!readOnly); env = new Environment(envHome, envConfig); StoreConfig storeConfig = new StoreConfig(); storeConfig.setReadOnly(readOnly); storeConfig.setAllowCreate(!readOnly); store = new EntityStore(env, "EntityStore", storeConfig); objectBySid = store.getPrimaryIndex(String.class, TestObject.class); open = true; } catch (EnvironmentLockedException e) { } catch (Exception e) { e.printStackTrace(); System.exit(-1); } return open; }
/** * When opening read-only, secondaries are not opened when the primary is opened, causing a * different code path to be used for opening secondaries. For a RawStore in particular, this * caused an unreported NullPointerException in JE 3.0.12. No SR was created because the use case * is very obscure and was discovered by code inspection. */ public void testOpenRawStoreReadOnly() throws DatabaseException { open(); store.getPrimaryIndex(Integer.class, MyEntity.class); close(); StoreConfig config = new StoreConfig(); config.setReadOnly(true); config.setTransactional(envConfig.getTransactional()); RawStore rawStore = new RawStore(env, "test", config); String clsName = MyEntity.class.getName(); rawStore.getSecondaryIndex(clsName, "secKey"); rawStore.close(); }
boolean openStoreReadOnly() throws Exception { StoreConfig config = new StoreConfig(); config.setReadOnly(true); return openStore(config); }
private void openReadOnly() throws DatabaseException { StoreConfig config = new StoreConfig(); config.setReadOnly(true); open(config); }