This discussion is archived
5 Replies Latest reply: Dec 2, 2012 5:14 PM by 977385 RSS

In memory database usage

977385 Newbie
Currently Being Moderated
Hi

I am trying to create an in-memory database (I do not need any files -log or database- to be stored on disk) , do calculations, save the calculations and terminate it. I cannot seem to locate an example in JE to create an in-memory database. As far as I get from the documentation this should be possible but I was not able to change examples to fit my need. Can you please point me to a document or an example that covers this?

thanks
Baris
  • 1. Re: In memory database usage
    greybird Expert
    Currently Being Moderated
    Hi,

    Where did you see in the documentation that in-memory databases are supported in JE? They are not.

    Temporary databases are supported, but they will be written to disk when the cache overflows. See DatabaseConfig.setTemporary.

    For more details, search the forum for "in memory" (with the quotes).

    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  • 2. Re: In memory database usage
    977385 Newbie
    Currently Being Moderated
    I presumed that this meant in-memory (from ~GettingStartedGuide/usingDbt.html#datapersist):

    If you do not want to use transactions, then the assumption is that your data is of a nature that it need not exist the next time your application starts. You may want this if, for example, you are using JE to cache data relevant only to the current application runtime.

    I changed an example to get rid of transactional code and save 1MM records into the table. It's not saving the data that I am saving into the database. It does it when database is opened and closed. This must be what is described in the above paragraph. I understand that if BDB consumes all memory there will be caching for this operation.

    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setTransactional(false);
    envConfig.setAllowCreate(false);
    Environment exampleEnv = new Environment(envDir, envConfig);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTemporary(true);
    dbConfig.setTransactional(false);
    dbConfig.setSortedDuplicates(true);
    dbConfig.setAllowCreate(true);
    Database exampleDb = exampleEnv.openDatabase(null, "a", dbConfig);
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry dataEntry = new DatabaseEntry();
    Map<Integer,Integer> entries=new TreeMap<Integer,Integer>();
         for (int i = offset; i < numRecords + offset; i++) {
              IntegerBinding.intToEntry(i, keyEntry);
              IntegerBinding.intToEntry(i+1, dataEntry);
              OperationStatus status = exampleDb.put(null, keyEntry, dataEntry);
              if (status != OperationStatus.SUCCESS) {
              throw new RuntimeException("Data insertion got status " +
                             status);
              }
         }
    exampleDb.close();
    exampleEnv.close();
  • 3. Re: In memory database usage
    greybird Expert
    Currently Being Moderated
    Hi again,

    Durability, transactions, temporary databases and in-memory databases are all different things, and each is a topic all on its own. Rather than try to describe all of that, it would help if you could describe exactly what you want to do, and why -- what is the purpose of your questions -- so I can better give you the information you need.

    I noticed in your code example, you're using temporary databases -- you're calling DatabaseConfig.setTemporary(true). If you don't need the data to be persistent, this is the right thing to do. If you're asking how temporary databases work, see:
    http://docs.oracle.com/cd/E17277_02/html/java/com/sleepycat/je/DatabaseConfig.html#setTemporary(boolean)
    and
    http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/DB.html#tempdbje

    However, you should also ask yourself why you're using a database. Why not just just a HashMap or TreeMap? If you can answer this question, it will help to understand the problem you're trying to solve.

    Thanks,
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  • 4. Re: In memory database usage
    Ashok_Ora Explorer
    Currently Being Moderated
    You may want to look at Berkeley DB (a product very similar to Berkeley DB Java Edition, but distinct), which does support pure in-memory databases as well as a Java API.

    you look up the programmer reference for Berkeley DB here: http://docs.oracle.com/cd/E17076_02/html/programmer_reference/BDB_Prog_Reference.pdf Search for "Memory-only or Flash configurations".

    If you decide to go ahead with Berkeley DB, and have questions, you should post them to the Berkeley DB forum (Berkeley DB

    Hope this is helpful.

    Warm regards.
    ashok
  • 5. Re: In memory database usage
    977385 Newbie
    Currently Being Moderated
    Thanks for taking time. The reason I've looked into BDB JE was the fact that it is in-process. I'll read a bit more on when it starts caching to find out if it fits my use case.

    Baris

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points