SchemaSpy - Excellent Database Graphs for Free!
Join the DZone community and get the full member experience.Join For Free
A lot of Java projects have quite complex database schemas in the backend. Although, using object-relational mapping it can be useful to have a deeper understanding of such a schema, e.g. when writing CRUD tests.
For me the visualization of table relations is quite important, besides the table attributes. There are a lot of entity relationship modeling tools out there, doing a pretty good job. But, most of them are also quite expensive.
I did a search for something OpenSource and found some tools from the mySQL community. Although, these should support Oracle I had problems to get things running. In one case only a pro version allowed to do an analysis for a remote database installation (what is the normal case for Oracle schemas ;-)).
Well, in the end I found a German article by Joachim Uhl that confirmed some of my experiences and gave some useful tips to get a productive solution. He prefers SchemaSpy, a Java-based commandline tool, and also develops a Java-based GUI application for it.
Although, "nominated" in 2006, SchemaSpy seems to be still the best OpenSource tool for schema documentation. The list of databases, that are supported, is impressive. My first tests with SchemaSpyGUI, SchemaSpy and GraphViz for Windows, the tool that generates the cool dependency graphs, are promising.
Fig. 1: SchemaSpy Example for a Dependency Graph
There's an online example for a first look [Fig. 1]. If you click on the "Relationships" tab you get the first of three possible graphical presentations. Use the checkboxes for presentation changes. There's also an "Anomalies" tab that may helps to find design issues in the schema.
Before you start SchemaSpyGUI the first time, SchemaSpy and GraphViz already have to be installed on your system. GraphViz is the only guy who not resides in Javaland, so you need a platform-dependent installation instead. I tested all this on Windows XP.
SchemaSpyGUI delivers a simple ZIP archive you can extract to your program files directory. SchemaSpy delivers a production-ready JAR, that you may put into the existing SchemaSpyGUI directory, too. GraphViz delivers a full-blown Windows installer. There's nothing special here. SchemaSpyGUI only needs the dot.exe in the environment path, that is done automatically by the installer.
If you start SchemaSpyGUI the first time, all fields are empty. The form is pretty simple, but can only manage one profile at the moment (use buttons "Save Parameters" and "Load Parameters" for this). The profile is saved in the "sSpyGUIini.xml", so you may create a batch hack to create a schema presentation for more than one database automatically.
Fig. 2: SchemaSpyGUI - Required Parameters for Database Access
The "Required Parameters" defines which database to use and where the JDBC driver and SchemaSpy can be found [Fig. 2]. For the Oracle database I used
- DB Type: orathin (all other DB parameters as usual)
- Path to DB driver: \com\oracle\jdbc\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar from our Maven2 repository
- Path to SchemaSpy: \SchemaSpyGUI\schemaSpy_3.1.1.jar (as suggested above)
Fig. 3: SchemaSpyGUI - Optional Parameters for Output and Schema Selection
I also set the "Optional" parameters on the right [Fig. 3]. The "Output directory" defines the place where you can find "index.html" and all other files after processing. I also set the "Schema to explore". It is also possible to be more fine-grained using regular expressions on tables or attributes.
Don't forget to click on "Save Parameters" in the end. If you start SchemaSpyGUI the next time you click on "Load Parameters" and everything is set - except from the database password ;-).
All parameters are set. So, we can start to create the schema presentation. For this click on "Start SchemaSpy" [Fig. 3]. The log window shows messages from SchemaSpy during the processing. When everything is done click on "Show Schema Output" to have a look at the results in your Web browser.
Published at DZone with permission of Rainer Eschen. See the original article here.
Opinions expressed by DZone contributors are their own.