Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database Abstraction Language for Java

Tags:

java

database

The problem: I need to abstract my database interaction on my application. The thing is JPA doesn't work for me because the tables/schemas are dynamic and I only know them at runtime. I thought of creating the classes dynamically, but I'm looking at performance problems with that approach since every insertion would result in an instantiation of the class using reflection. I thought about using XML to model, but seems also slow and a bit difficult to manage.

What am I looking for? I'm looking for some middle layer language (something like JPQL [Java Persistence Query Language]) that I don't need to map to objects. Some language that abstracts schema/catalog and table creation as well queries using select clause.

Thanks in advance.

like image 777
rpvilao Avatar asked Mar 21 '11 15:03

rpvilao


1 Answers

I'm pretty sure hibernate has an object-less mode, where entities are described using Maps. and, you can setup a hibernate factory at runtime if you so desire. i believe the combination of these features could do what you need.

that said, i worked on a similar system at my last job. we wanted a functionality layer which was abstracted from the data layer. the data layer wasn't "dynamic" per-se, it was just not known at compile time. we ended up building a system which loaded a configuration file which defined the db schema and could generate sql against that schema. we wanted a pretty high level of control over the resulting sql, so we ended up building our own sql building library, which we open sourced as SqlBuilder. SqlBuilder works best for generating queries using an in-memory db schema (which we built from the config file).

like image 93
jtahlborn Avatar answered Nov 07 '22 12:11

jtahlborn