Dynamicly generate class from foreign key lookup table, referencevalues

A

Adam

Hello,

I'm generally new to Java and have a project where I've got a db
schema with normalized reference tables with static/readonly lookup
values.. I've also generated a Bean mapping from the overall schema
and was wondering how to tag(?) or annotate the reference types
(corresponding to the normalized reference/lookup tables) with their
readonly content, for example:
table:
FK_Ref_Table1
"SomeKey", "Value"
"SomeOtherKey", "someOtherValue"
....

And in the mapped bean class
FK_Ref_TableObject.SomeKey
FK_Ref_TableObject.SomeOtherKey
....
where these object.property resolves to the "Value" and
"someOtherValue" ...
What I'd like to avoid is hard-coding the keys into the project but to
be able to reference them as a class; and without having to hard-code
the class... a data access layer might provide inserts, updates, etc.
to the FK reference values which would then reflect in the generated
class, automatically.

Not even sure what to call what I'm talking about.


Thanks for any help.
 
S

Stefan Ram

Adam said:
Not even sure what to call what I'm talking about.

You can write and load a class file at run-time.

In this case, you should adhere to the Java Class file format:

http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html

However, it usually is recommended to use code (classes) for
everything static (things that never change at run time,
that never change during the lifetime of the software).

What changes at run time is considered to be data.

Data is handled by the dynamic means intended for it,
for example container objects and so.

So your program would read the scheam from the DB and then
build everything it needs at run time from the schema as data,
not as classes. When the schema changes, it re-reads it and
re-builds what needs to be rebuilt.

For example, when you want to convert from Celsius to
Fahrenheit, and the user has input the value »32«, you store
this in a variable and then use it. You do not generate a
class with this value, then load the class and use it.
 
D

dontlikenicknames

Sounds like a great candidate for Hibernate. If you're new to Java,
you can check out their site at http://www.hibernate.org/. I'm not
sure how complicated your project is, but hibernate will do exactly
what I think you are looking to do...Load DB values into POJOs, and
vice versa?

The basic concept is that you map out your DB to Java objects in an
XML document and Hibernate takes care of a lot of the details for you.

Hope I helped.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top