Is it true that Oracle Berkeley Java Edition always needs a file path for storing data? Do I always have to set an environment home on file system? No 'in-memory' only storing possible?
Asked
Active
Viewed 998 times
2 Answers
2
"in-memory" only storage is possible in Berkeley DB Java Edition. the Environment need to be created with "je.log.memOnly" parameter set to 'true'. this parameter must be set before the EnvironmentConfig is created as it is immutable.
Properties properties = new Properties();
// sets the DB to work "In Memory"
properties.put(EnvironmentConfig.LOG_MEM_ONLY, "true");
// create an enviroment configuration object with the immutable parameter
EnvironmentConfig configuration = new EnvironmentConfig(properties);
File envHome = new File("/db_location");
// create the environment
persistEnvironment = new Environment(envHome, configuration);
An environment directory MUST be specified, but it doesn't need to exist.
description of the "je.log.memOnly" parameter can be found under "LOG_MEM_ONLY" in the EnvironmentConfig Javadoc:

Yoav Slomka
- 372
- 2
- 10
-
2Note this proviso in the docs: "The system operates until it runs out of memory, at which time an OutOfMemoryError is thrown. Because the entire log is kept in memory, this mode is normally useful only for testing." – Simon Kissane Sep 23 '13 at 07:51
-1
Why would you need a database for in memory storage? If you don't require persistent data you can switch to any other data structure which Java has many or create your own class.

user1521554
- 117
- 3
- 14
-
You would need a database for in memory storage for say the integration test phase when using Spring. – Nico de Wet Feb 26 '14 at 06:54