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();


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

or even manipulate tables like

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

DbColumn 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?

Asked by: Luke372 | Posted: 28-01-2022

Answer 1

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.

Answered by: Connie658 | Posted: 01-03-2022

Answer 2

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.

Answered by: Fiona494 | Posted: 01-03-2022

Answer 3

I haven't used it in years but Hibernate used to have tools for manipulating data models at build time. Hibernate also has the notion dialects which would be helpful if you're targeting more than one database vendor.

Answered by: Lucas663 | Posted: 01-03-2022

Answer 4

When I was at MetaMatrix, we built such a thing using EMF (Eclipse Modeling Framework) where we created a representational meta-model in UML, then generated it from code. The nice thing about metamodeling is that if you do it well, you can interoperate things across metamodels, provided you have made good choices against the meta-meta-model.

We also had an importer that would import metadata from the JDBC API and create the appropriate equivalent model objects (database, table, column, keys, etc).

This code might be open source some day since they got bought by JBoss but I don't think it is yet.

Answered by: Samantha455 | Posted: 01-03-2022

Similar questions

java - Proper way of modelling classes based on database parent and child tables

I thought it would be best to ask this question from SO community who are more experienced than I am. Since I'm still a student. I know modelling classes and matching them with the relationships of database tables have a very significant impact on code readability especially when a program or a system continue to grow when it gets added with more and more codes. Say, I have the entities Customer

java - How to create this database using Object Oriented Modelling

Users There are two types of users in the system for the purpose of access control: administrators and regular users. Anyone can register and becomes a regular user in the system. During registration, a user must provide the following information: First and last name Position: Student, Faculty, or Staff Organizational unit: this could be a college, a department, a division, an offic...

java - Language Modelling toolkit

I would like to build a language model for a text corpus. Are there good out-of-the-box toolkits which will alleviate my task? The only toolkit I know off is the Statistical Language Modelling(SLM) Toolkit by CMU. Regards,

java - Modelling multiple days of the week

This is the second time i've come accross a one-many relationship between object and weekday and I'm not sure if i'm modelling it in the best way: @Entity MyObject { private int id; private String foo; private boolean monday; private boolean tuesday; private boolean wednesday; private boolean thursday; private boolean friday; private boolean saturday; private boolean sund...

java - Mallet topic modelling

I have been using mallet for inferring topics for a text file containing 100,000 lines(around 34 MB in mallet format). But now i need to run it for on a file containing a million lines(around 180MB) and I am getting an java.lang.outofmemory exception . Is there a way of splitting the file into smaller ones and build a model for the data present in all the files combined?? thanks in advance

c# - Building a game of dominoes - modelling and laying out

I started to make a simple domino game. (the one where you place the tiles with same numbers next to each other). I started modelling it and i seem to have landed in a tough spot now. Im modelling the actual domino (called "bone"): namespace DominoCore { public enum BoneOrientation { Horizontal, Vertical } public interface IBone { int FirstValue { get; } int SecondValue { get; }...

jogl - 3d modelling loading , updating and rendering in java

i am new to java 3d. i have encountered a situation like , i want to load ready made developed 3d model of any object [as an example shoe] developed in 3d modeling software like 3d studio max or Maya in my java program , update its texture or color properties etc. then render it and then display the updated model to the end user. so i am asking all the 3d experts how should i proceed ahead to accomplish my goal ? ...

java - EE service design and OO modelling

Closed. This question is opinion-based. It is not c...

java - Libgdx weird modelling - depth error?

I'm getting this when I load any .obj file with ObjLoader: How it looks like in real: How I'm loading it: ModelInstance instance = new ModelInstance(model); instance.transform.setToTranslation(-4, 0, 0); instance...

java - what is the use of Eclipse Modelling Frameowrk and Eclipse Graphical Editing Framework?

May be this question is easy but it created me a bit of confusion with their purpose. Just exploring the Eclipse Modelling Frameowrk and Eclipse Graphical Editing Framework. Basically The Graphical Editing Framework (GEF) provides a framework for creating visual editors. And The Eclipse Modeling Framework (EMF) is a Java framework and code generation facility for building tools and other applications based on a str...

java - Class for modelling a view

I'm writing an application in GWT. I need to have a class that represents the state that is displayed in a particular view. The view is for viewing contacts, so there's a contact list, and there are a few types that can be displayed: all contacts a group of contacts (with a Group class) search results (with search query) type is an enum (ALL, GROUP, SEARCH)...

cplex java api modelling 1-sum_j 2d array

I have tried modelling the expression Sum_j (1-(Sum_i z[i][j])) * c[i][j], where z[i][j] are my boolean variables of the obj function. I tried this by modelling as an expression every column of the array and then an expression for 1-sum of collumns and so forth. Something like sum(prod(sum(1,negative(sum_j)),c[ij])). But didn't make it. I would like a little help. Thanks [edi...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)