John Thompson
John Thompson

Reputation: 244

Mapping the java language to a database

I want to represent some java concepts in a database schema. I don't mean persist instances into Hibernate, I mean represent java's type system as a series of tables and rows.

So for instance, with respect to types there are a certain definite set of relationships I would like represent. For example, there are two types in Java , primitive types and reference types, and primitive types break down into numeric and boolean and numeric breaks down into integral and floating type and integral breaks down into byte short int long and char and floating types break out into float and double (I think I got that right) .

Java also has classes and classes have methods and methods have signatures and constructors and return types and arguments , both of which have some type.

So I want to create a database that represents this kind of information in 3NF form. Such a database would permit queries about object instances which would be the data put into the database.

Is there anything like this ? I am turning up nothing useful in Google maybe because it's hard to compose a query that doesn't land you in JDBC and Hibernate territory. Still, I think someone must have already done this; maybe there's even a standard or an RFC out there that I don't know about.

What I don't want is to try to reverse engineer some aspects of something like hibernate or anything like. I think that would actually be a largish task with very little payoff. It's not that I can't do it from scratch (after the usual false starts and mistakes have been made), it's that I am wondering if it hasn't already been done and spec'ed out somewhere.

Many thanks.

Upvotes: 0

Views: 118

Answers (4)

James Anderson
James Anderson

Reputation: 27478

Another answer! I was thinking about this overnight and it occured to me that any UML modeling tool must store exactly this sort of data internally in order to support the pretty graphics and arrows.

[Argo][1] and [Papyrus][2] look promising.

Upvotes: 0

James Anderson
James Anderson

Reputation: 27478

Google for "sub-type" "super-type" modelling.

Your problem sounds like it requires tow or three levels of sub-typeing.

A table called "fields" which holds the attributes common to all types name, length, the class it belongs to etc.

A table called "text_fields" which holds the attributes common to all text type fields.

A table called "numeric_fields" which holds all the attributes common to numeric fields. An indicator for float or fixed, perhaps max and min values etc.

So for each field you store the name etc, as a row in the "fields" table and the rest of the data in either the "text_fields" or "numeric_fields" table.

Depending on why you are modelling this you might require a fourth table "classes" as a class variable can appear most places a base type can appear in a Java program.

Upvotes: 0

Stephen C
Stephen C

Reputation: 718886

it's that I am wondering if it hasn't already been done and spec'ed out somewhere.

Not in the sense that you mean. This wheel has been invented before in various ORM mapping products, but I'm not aware of anyone who has done in independently of such a product. (Why would someone be motivated to do that? Its not like there are 100's of projects that would make use of that work ...)

Upvotes: 0

Object-Relational Impedance Mismatch is a hard problem. If you don't want to dive into Hibernate or another ORM layer to try to figure out how they did it, you're going to have to reinvent the wheel yourself.

We can come up with conceptual representations, such as the Object table...and you can use an inheritance strategy like Hibernate uses. But if you want to capture methods, you're going to have to figure that out (a Method - Object relationship?) If you want to capture the ability to @Override, you're going to have to figure that out. Annotations? Etc etc.

"I want to represent some java concepts in a database schema...which I think would actually be a large task with little payoff."

I think you answered your own question. The question you may want to ask is: "is there a better approach for what I'm really trying to do?"

Upvotes: 2

Related Questions