This discussion is archived
3 Replies Latest reply: Jan 14, 2013 9:06 AM by greybird RSS

Approach for dynamic entities

914629 Newbie
Currently Being Moderated
Hello dear experts,

I am searching for an approach to dynamically create entities in Berkeley-DB JE. Background is, that I receive an XML file which contains the description of the entity objects and I have to dynamically create the entity objects from the description file.

I would be glad if some could provide me with some hints where to search and if this approach is possible in anyway.

Looking forward to hearing from you.

With kind regards,

Lakin.
  • 1. Re: Approach for dynamic entities
    greybird Expert
    Currently Being Moderated
    Hi Lakin,

    Do you mean specifically using the DPL (com.sleepycat.persist package), or more generally using any of the BDB JE APIs?

    --mark                                                                                                                                                                                                                                                                                           
  • 2. Re: Approach for dynamic entities
    914629 Newbie
    Currently Being Moderated
    Hi Mark,

    using the DPL would be nice but I am afraid that this will be difficult since DPL wants predifined entity classes. So I am searching for a general way to dynamically create content in BDB-JE. Something like SQL-CreateTable.

    With kind regards,

    Lakin.
  • 3. Re: Approach for dynamic entities
    greybird Expert
    Currently Being Moderated
    Because JE's keys/values are simply byte arrays, it is often used for applications where the schema is dynamic. However, the metadata facility in such applications must be implemented by the application. JE provides a way to dynamically create Databases, of course, but it is up to the application to provide the higher level equivalent of CREATE TABLE.

    When creating such an application, you still need to choose a binding -- a serialization format -- from those available: TupleBinding (custom binary format), SerialBinding (Java serialization), the DPL's format, or a creation of your own.

    You are correct that the DPL is based on class definitions, so is primarily meant to be static. The same is true of SerialBinding.

    So you are left with using tuples, which are very flexible and efficient, or creating something on your own.

    There is one other possibility I'll mention, although it is not very space-efficient: You can use the DPL or SerialBinding and define a field of type Map<String, Object> for holding the values. This is inefficient because the field names are repeated in every record -- you might as well store XML or JSON text.

    But in all cases you'll need to design and implement the metadata for each table. So the short answer to your question is that JE doesn't help you with this.

    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Legend

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