com.jenkov.mrpersister
Class MappingTool

java.lang.Object
  extended by com.jenkov.mrpersister.MappingTool
All Implemented Interfaces:
java.lang.Runnable

public class MappingTool
extends java.lang.Object
implements java.lang.Runnable

The MappingTool class is a method utility that can show how the Mr. Persister API will map a given class to a database. This can be useful to see if your class will be mapped correctly by the API, or you will have to adjust the mapping manually.

The MappingTool utility can be run from commmand line, or be instantiated and run from within an application.

The method tool needs a database property file in order to connect to the database. There has to be the following 4 properties present in the file:

  1. db.driver=xxx The name of the JDBC driver class used to connect to the database
  2. db.url The URL to the database server used to connect to the database.
  3. db.user The database user name to use to connect to the database.
  4. db.password The password of the database user used to connect to the database

Author:
Jakob Jenkov, Jenkov Development

Field Summary
protected  java.lang.Class classToMap
           
protected  java.io.File databasePropertyFile
           
protected  java.lang.String tableName
           
 
Constructor Summary
MappingTool(java.io.File databasePropertyFile, java.lang.Class theClass)
          Initializes the MappingTool instance with the database property file File instance, and the Class instance of the class to be mapped.
MappingTool(java.io.File databasePropertyFile, java.lang.Class theClass, java.lang.String tableName)
          Initializes the MappingTool instance with the database property file, the class to be mapped, and the name of the table to map the class to.
MappingTool(java.lang.String[] args)
          Initializes the MappingTool instance with arguments passed from the command line.
 
Method Summary
static void main(java.lang.String[] args)
          Runs the MappingTool application from the command line.
 void run()
          This method does the hard work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

databasePropertyFile

protected java.io.File databasePropertyFile

classToMap

protected java.lang.Class classToMap

tableName

protected java.lang.String tableName
Constructor Detail

MappingTool

public MappingTool(java.lang.String[] args)
            throws PersistenceException
Initializes the MappingTool instance with arguments passed from the command line.

Parameters:
args - The arguments as passed to the application from the command line, in the main(String[] args) method.
Throws:
PersistenceException - If the arguments are not valid.

MappingTool

public MappingTool(java.io.File databasePropertyFile,
                   java.lang.Class theClass)
Initializes the MappingTool instance with the database property file File instance, and the Class instance of the class to be mapped.

Parameters:
databasePropertyFile - The database property file.
theClass - The class to be mapped.

MappingTool

public MappingTool(java.io.File databasePropertyFile,
                   java.lang.Class theClass,
                   java.lang.String tableName)
Initializes the MappingTool instance with the database property file, the class to be mapped, and the name of the table to map the class to.

Parameters:
databasePropertyFile - The database property file
theClass - The class to be mapped to the database table.
tableName - The name of the table to map the class to.
Method Detail

run

public void run()
This method does the hard work. Opens a connection to the database and asks the object mapper to map the class to the database, and prints the results.

Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)
Runs the MappingTool application from the command line.

Parameters:
args - The arguments passed to the MappingTool class from the command line. The MappingTool class requires two arguments and has an additional optional argument:

  1. propertyFile - The path to the database property file
  2. className - The fully qualified name of the class to map
  3. tableName - Optional. The table name to map the class to, in case the table name is not similar to the class name