11

Several times I have wanted a data structure that is similar to a SQL Table where you can select on various fields and multiple fields. Similar to an in memory SQL implementation except that I don't want to store that many objects in the data structure.

I also require the object to be serializable through standard Java means.

I have done this before with multiple hash tables or custom hash keys but it ended up being a lot of code and very specific the problem.

I have also used Groovy with its closure ability and gpath to help but I don't always have it available (different projects).

EDIT: I think my problem is more of an object traversal/selection problem Here are some interesting projects:

However the downside to most of these projects is that they are much slower than accessing the objects directly (non reflection getter/setter) and definitely slower than an index (hash).

3
  • Are you going to query some standalone snapshot of data? What about multithreading, locking, transactions, inserts/updates? If any of above possible - I'd 100% agree with @Alex. Commented Dec 30, 2010 at 2:21
  • @Osw No this purely for convenience. I don't need the ACID nature of RDBMS. I need the query ability. Commented Dec 30, 2010 at 2:30
  • think these links might be helpful: docs.jboss.org/hibernate/core/3.3/reference/en/html/… and almaer.com/blog/… Commented Dec 30, 2010 at 3:00

2 Answers 2

3

JavaDB and HSQLDB, among others, have fully in-memory databases.

Sign up to request clarification or add additional context in comments.

5 Comments

The issue with those guys is that do not give me data structures that I can marshal/serialize. I'm looking for something I can XStream.
Although I suppose I could make some kind of generic data object to represent a table and on unmarshal gets loaded to an in-memory singleton rdbms but this has problems with thread safety if its not thread safe and lots of thread blocking if it is.
I doubt you'll find something that satisfies both requirements. My suggestion: use a serializable POJO to take a snapshot of the tables in the in-memory db, and then serialize that. Going the other way would be trivial as well, just unmarshall the XStream into a POJO and then load the data into the in-memory db.
Thinking along the same lines. :) There are probably several reasonable ways to handle the concurrence issues, depending on how available the in memory db has to be, and whether you need to make a hot copy, or can take the db offline to the affected threads.
I think most of my problems stem with Java's lack of builtin object graph traversal. C#'s LINQ and Groovy's GPath make traversing and objects based on different properties much easier than Java.
2

What concerns you about using in-memory SQL storage for these purposes? You'd save a ton of development time; performance overhead is really insignificant. You risk much more by trying to implement this yourself.

2 Comments

It sounds like (to me anyway) he was looking for an alternative to building his own. Also, this isn't really an answer and might be better as a comment on the original question.
I don't want to build my own (hence the Q). I can't just use an in memory database the tables are not serializable data structures. In other words I can't send a whole db table over the wire through JAXB (enter your favorite serialization technology here) or save it to a file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.