Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've refactored a program to remove its dependency on an sql database by storing all the state in a memory model. However the manager liked the ability to easily inspect the domain state just by doing an sql join/filter on the database at any time; and he wishes to maintain some similar domain inspection ability. We discussed having a call that dumps the model state to a file that can be inspected. There isn't that much state--it can all fit into memory--but the state is large enough that we need some mechanism to allow us to 'fetch' the child if a given parent better then manual inspection of the files.

I need the best tool to make this doable. They are thinking of exporting everything to CSV to be read into a DB, which could work, but it seems off to be using a DB only for doing joins on data types. Plus, their old approach used Strings for joins that weren't guaranteed to be unique, and, with my addition of extra objects, thought would have to put into how to lay out the database fields to represent the new model objects (particularly child objects of parents).

I've toyed with other ideas for this. One idea was to a CSV file and having some other program read in the CSV file and do 'sql like' joins, but haven't found a program that does this easily. I've also toyed with an interactive java interpreter so we can read things into our model and do calls against the model, even using linux base commands to write 'joins' with awk or similar. I'm not sure I like any option though. Does anyone have suggestions for a good way of doing this?

p.s. We can SSH to the maintained systems at any time, but we can't copy files to or from them without permission when maintaining live systems. Any tool used to inspect memory has to be packaged with our release as its own jar with justification as to why we are including it.

share|improve this question
1  
Why did you remove the database in the first place? –  Mike May 14 '13 at 19:38
    
Have you considered an in-memory database such as H2? –  Matthew Flynn May 14 '13 at 19:48
    
The database was being used poorly in many ways as it was done. Either the DB had to go, or had to be replaced with a proper DB tool rathern then there home written logic and general use of the DB modified to avoid all the datarace, stale data, slowness, redundant/ugly code for data access etc etc. The doman was so basic it seemed easier to get rid of the DB as part of a general major refactoring step then try any fancier in-memory or db access tools. –  dsollen May 14 '13 at 23:15
add comment

1 Answer

up vote 2 down vote accepted

Any tool used to inspect memory has to be packaged with our release as it's own jar

We've got a restriction to use Java... This makes some things easier, and some things harder.

Consider having something that serializes the state out to xml and then a separate program to do xpath queries against it. This gives you some forms of queries, but doesn't quite do the joins (if you don't really need them, this might be the easiest approach).

Failing being able to run xpath queries, one could instead serialize the data to something and bring it into another program that uses an embedded database. Something like HSQLDB or H2 or Derby or Sqlite. Then you have two most obvious options...

  1. If the database is exposed, you could use your favorite sql tool and run against it
  2. You could run the query from the command line in the application itself.

Another option of just do a memory dump of the running application and use OQL to analyze the memory. The tool for this is the Memory Analyzer. This gets into it a bit, though there quite a bit more information needed when approaching this problem.

share|improve this answer
    
The Memory Analyzier and OQL look like exactly what I wanted. I had thought something like that had to exist; but no one could point me to it! It looks like JHat is the more generic version that is available in teh JRE, so I'll look at that shortly. Still, I would prefer to dump only those objects considered to be in my model (using basic serlization) and run something like OQL on that; do you know if that is possible? –  dsollen May 14 '13 at 23:27
    
@dsollen no idea - I haven't delved much into the java memory analyzer much at all (I know of it because I was looking for tangents on object databases and found oql which lead me to the java memory analyzer). –  MichaelT May 14 '13 at 23:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.