Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a database modelling library for Java?

Does anyone know of a Java library that provides a useful abstraction for analyzing and manipulating arbitrary relational database schemata? I'm thinking of something that could do things like

LibraryClass dbLib = ...;
DbSchema schema = dbLib.getSchema("my_schema");
List<DbTable> tables = schema.getTables();

and

DbTable myTable  = ...
for(DbColumn col : myTable.getColumns()){
    ... = col.getType();
}

or even manipulate tables like

myTable.addColumn(
    new DbColumn("my_new_column", Type.UNSIGNED_INTEGER);
);

DbColumn myColumn = ...
myTable.removeColumn(myColumn);

Most Database modeling tools will have such an abstraction internally, but is there one in Java that I can use, or will I have to roll my own?

like image 315
Henning Avatar asked Nov 14 '08 14:11

Henning


2 Answers

JDBC itself has such an abstraction. Look at java.sql.DatabaseMetaData. However, this is an optional part of the standard and it depends on the JDBC driver you are using wether it is implemented or not.

like image 191
Gowri Avatar answered Sep 25 '22 20:09

Gowri


DdlUtils has what you're looking for. You can read/write schemas to/from XML (in Torque format) or a live database, or even define the database schema in pure Java. Better yet, read the on-line doco, it's quite good.

like image 30
Andrew Swan Avatar answered Sep 21 '22 20:09

Andrew Swan