SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

com.solarmetric.rd.kodo.impl.jdbc.meta
Class ReverseMappingTool

java.lang.Object
  |
  +--com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseMappingTool

public class ReverseMappingTool
extends java.lang.Object

Reverse-maps a schema into class mappings and the assiciated java code. Generates an XML schema definition file, an XML mapping file, java code files for persistent classes and their application IDs, and metadata files for these classes. The schema definition file and XML mapping file can then be imported into the schema factory and mapping factory of your choosing.


Field Summary
static java.lang.String LEVEL_CLASS
           
static java.lang.String LEVEL_PACKAGE
           
 
Constructor Summary
ReverseMappingTool(com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration conf)
          Constructor.
 
Method Summary
 void addClassIndicator(com.solarmetric.rd.kodo.impl.jdbc.meta.ClassIndicator cls, com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
          Add a mapping.
 boolean addClassMapping(com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping mapping)
          Add a mapping.
 boolean addFieldMapping(com.solarmetric.rd.kodo.impl.jdbc.meta.FieldMapping field, com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
          Add a mapping.
 void addVersionIndicator(com.solarmetric.rd.kodo.impl.jdbc.meta.VersionIndicator version, com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
          Add a mapping.
 java.lang.Class generateClass(java.lang.String name, java.lang.Class parent)
          Generate a new class with the given name.
 void generateMappings()
          Generate mappings and class code for the current schema group.
 com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping getClassMapping(com.solarmetric.rd.kodo.impl.jdbc.schema.Table table)
          Return the class mapping for the given table, or null if none.
 java.lang.String getClassName(com.solarmetric.rd.kodo.impl.jdbc.schema.Table table)
          Return a Java identifier-formatted name for the given table name, using the default package.
 java.io.File getCodeDirectory()
          The file to output the generated code to, or null for the current directory.
 serp.util.CodeFormat getCodeFormat()
          The code formatter for the generated Java code.
 com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration getConfiguration()
          Return the configuration provided on construction.
 com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer getCustomizer()
          Return the customizer in use, or null if none.
 java.lang.String getFieldName(java.lang.String name, com.solarmetric.rd.kodo.meta.ClassMetaData fieldOwner)
          Return a default Java identifier-formatted name for the given column/table name.
 java.lang.Class getFieldType(com.solarmetric.rd.kodo.impl.jdbc.schema.Column col, boolean forceObject)
          Return the default field type for the given column.
 com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping[] getMappings()
          Return the generated mappings.
 boolean getNullableAsObject()
          Return whether even nullable columns will be mapped to wrappers rather than primitives.
 java.lang.String getPackageName()
          Return the default package for the generated classes, or null if unset.
 boolean getPrimaryKeyOnJoin()
          Return true if join tables are allowed to have primary keys, false if all primary key tables will be mapped as persistent classes.
 java.lang.String getRelationName(java.lang.Class fieldType, boolean coll, com.solarmetric.rd.kodo.impl.jdbc.schema.ForeignKey fk, boolean inverse, com.solarmetric.rd.kodo.meta.ClassMetaData fieldOwner)
          Return a default java identifier-formatted field relation name for the given class name.
 com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository getRepository()
          Return the mapping repository used to hold generated mappings.
 com.solarmetric.rd.kodo.impl.jdbc.schema.SchemaGroup getSchemaGroup()
          Return the schema group to reverse map.
 boolean getUseDatastoreIdentity()
          Whether to use datastore identity when possible.
 boolean getUseForeignKeyName()
          Return whether the foreign key name will be used to generate relation names.
 boolean getUseSchemaName()
          Return true if the schema name will be included in the generated class name for each table.
static void main(java.lang.String[] args)
          Usage: java com.solarmetric.kodo.impl.jdbc.meta.ReverseMappingTool [option]* <.schema file or resource>*
 com.solarmetric.rd.kodo.meta.ClassMetaData newClassMetaData(java.lang.Class cls, java.lang.Class pcParent, int idType)
          Return a new class metadata for the given name and parent.
 com.solarmetric.rd.kodo.meta.FieldMetaData newFieldMetaData(java.lang.String name, java.lang.Class type, com.solarmetric.rd.kodo.meta.ClassMetaData owner)
          Return a new field metadata for the given name, type, and owner.
static void run(com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration conf, java.lang.String[] args, java.lang.String packageName, java.io.File codeDir, boolean useSchemaName, boolean useFKName, boolean nullAsObj, boolean pkOnJoin, boolean datastore, java.lang.String metaLevel, java.lang.String mappingLevel, com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer customizer, serp.util.CodeFormat format, java.lang.ClassLoader loader)
          Run the tool.
 void setCodeDirectory(java.io.File dir)
          The file to output the generated code to, or null for the current directory.
 void setCodeFormat(serp.util.CodeFormat format)
          Set the code formatter for the generated Java code.
 void setCustomizer(com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer customizer)
          Set the customizer.
 void setNullableAsObject(boolean nullAsObj)
          Set whether even nullable columns will be mapped to wrappers rather than primitives.
 void setPackageName(java.lang.String packageName)
          Set the default package for the generated classes; use null to indicate no package.
 void setPrimaryKeyOnJoin(boolean pkOnJoin)
          Set to true if join tables are allowed to have primary keys, false if all primary key tables will be mapped as persistent classes.
 void setRepository(com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository repos)
          Set the repository to use.
 void setSchemaGroup(com.solarmetric.rd.kodo.impl.jdbc.schema.SchemaGroup schema)
          Set the schema to reverse map.
 void setUseDatastoreIdentity(boolean datastore)
          Whether to use datastore identity when possible.
 void setUseForeignKeyName(boolean useFK)
          Set whether the foreign key name will be used to generate relation names.
 void setUseSchemaName(boolean useSchema)
          Set whether the schema name will be included in the generated class name for each table.
 void writeApplicationIdentityCode()
          Uses the ApplicationIdTool to write identity classes to the proper packages.
 void writeCode()
          Uses CodeGenerators to write the Java code for the generated mappings to the proper packages.
 void writeMappings(boolean perClass)
          Uses the XMLMappingInfoSerializer to write the generated metadata to the proper packages.
 void writeMetaData(boolean perClass)
          Uses the JDOMetaDataSerializer to write the generated metadata to the proper packages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEVEL_PACKAGE

public static final java.lang.String LEVEL_PACKAGE
See Also:
Constant Field Values

LEVEL_CLASS

public static final java.lang.String LEVEL_CLASS
See Also:
Constant Field Values
Constructor Detail

ReverseMappingTool

public ReverseMappingTool(com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration conf)
Constructor. Supply configuration.

Method Detail

getConfiguration

public com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration getConfiguration()
Return the configuration provided on construction.


getPackageName

public java.lang.String getPackageName()
Return the default package for the generated classes, or null if unset.


setPackageName

public void setPackageName(java.lang.String packageName)
Set the default package for the generated classes; use null to indicate no package.


getCodeDirectory

public java.io.File getCodeDirectory()
The file to output the generated code to, or null for the current directory. If the directory matches the package, it will be used. Otherwise, the package structure will be created under this directory.


setCodeDirectory

public void setCodeDirectory(java.io.File dir)
The file to output the generated code to, or null for the current directory. If the directory matches the package, it will be used. Otherwise, the package structure will be created under this directory.


getUseSchemaName

public boolean getUseSchemaName()
Return true if the schema name will be included in the generated class name for each table. Defaults to false.


setUseSchemaName

public void setUseSchemaName(boolean useSchema)
Set whether the schema name will be included in the generated class name for each table. Defaults to false.


getUseForeignKeyName

public boolean getUseForeignKeyName()
Return whether the foreign key name will be used to generate relation names. Defaults to false.


setUseForeignKeyName

public void setUseForeignKeyName(boolean useFK)
Set whether the foreign key name will be used to generate relation names. Defaults to false.


getNullableAsObject

public boolean getNullableAsObject()
Return whether even nullable columns will be mapped to wrappers rather than primitives. Defaults to false.


setNullableAsObject

public void setNullableAsObject(boolean nullAsObj)
Set whether even nullable columns will be mapped to wrappers rather than primitives. Defaults to false.


getPrimaryKeyOnJoin

public boolean getPrimaryKeyOnJoin()
Return true if join tables are allowed to have primary keys, false if all primary key tables will be mapped as persistent classes. Defaults to false.


setPrimaryKeyOnJoin

public void setPrimaryKeyOnJoin(boolean pkOnJoin)
Set to true if join tables are allowed to have primary keys, false if all primary key tables will be mapped as persistent classes. Defaults to false.


getUseDatastoreIdentity

public boolean getUseDatastoreIdentity()
Whether to use datastore identity when possible. Defaults to false.


setUseDatastoreIdentity

public void setUseDatastoreIdentity(boolean datastore)
Whether to use datastore identity when possible. Defaults to false.


getCodeFormat

public serp.util.CodeFormat getCodeFormat()
The code formatter for the generated Java code.


setCodeFormat

public void setCodeFormat(serp.util.CodeFormat format)
Set the code formatter for the generated Java code.


getCustomizer

public com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer getCustomizer()
Return the customizer in use, or null if none.


setCustomizer

public void setCustomizer(com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer customizer)
Set the customizer. The configuration on the customizer, if any, should already be set.


getRepository

public com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository getRepository()
Return the mapping repository used to hold generated mappings. You can also use the repository to seed the schema group to generate classes from.


setRepository

public void setRepository(com.solarmetric.rd.kodo.impl.jdbc.meta.MappingRepository repos)
Set the repository to use.


getSchemaGroup

public com.solarmetric.rd.kodo.impl.jdbc.schema.SchemaGroup getSchemaGroup()
Return the schema group to reverse map. If none has been set, the schema will be generated from the database.


setSchemaGroup

public void setSchemaGroup(com.solarmetric.rd.kodo.impl.jdbc.schema.SchemaGroup schema)
Set the schema to reverse map.


getMappings

public com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping[] getMappings()
Return the generated mappings.


generateMappings

public void generateMappings()
Generate mappings and class code for the current schema group.


writeCode

public void writeCode()
               throws java.io.IOException
Uses CodeGenerators to write the Java code for the generated mappings to the proper packages.

java.io.IOException

writeMetaData

public void writeMetaData(boolean perClass)
                   throws java.io.IOException
Uses the JDOMetaDataSerializer to write the generated metadata to the proper packages.

java.io.IOException

writeMappings

public void writeMappings(boolean perClass)
                   throws java.io.IOException
Uses the XMLMappingInfoSerializer to write the generated metadata to the proper packages.

java.io.IOException

writeApplicationIdentityCode

public void writeApplicationIdentityCode()
                                  throws java.io.IOException
Uses the ApplicationIdTool to write identity classes to the proper packages.

java.io.IOException

getClassMapping

public com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping getClassMapping(com.solarmetric.rd.kodo.impl.jdbc.schema.Table table)
Return the class mapping for the given table, or null if none.


addClassMapping

public boolean addClassMapping(com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping mapping)
Add a mapping.


addFieldMapping

public boolean addFieldMapping(com.solarmetric.rd.kodo.impl.jdbc.meta.FieldMapping field,
                               com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
Add a mapping.


addVersionIndicator

public void addVersionIndicator(com.solarmetric.rd.kodo.impl.jdbc.meta.VersionIndicator version,
                                com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
Add a mapping.


addClassIndicator

public void addClassIndicator(com.solarmetric.rd.kodo.impl.jdbc.meta.ClassIndicator cls,
                              com.solarmetric.rd.kodo.impl.jdbc.meta.ClassMapping owner)
Add a mapping.


newClassMetaData

public com.solarmetric.rd.kodo.meta.ClassMetaData newClassMetaData(java.lang.Class cls,
                                                                   java.lang.Class pcParent,
                                                                   int idType)
Return a new class metadata for the given name and parent.

Parameters:
idType - ClassMetaData.ID_APPLICATION or ClassMetaData.ID_DATASTORE
pcParent - nearest persistent parent class, or null

newFieldMetaData

public com.solarmetric.rd.kodo.meta.FieldMetaData newFieldMetaData(java.lang.String name,
                                                                   java.lang.Class type,
                                                                   com.solarmetric.rd.kodo.meta.ClassMetaData owner)
Return a new field metadata for the given name, type, and owner.


getClassName

public java.lang.String getClassName(com.solarmetric.rd.kodo.impl.jdbc.schema.Table table)
Return a Java identifier-formatted name for the given table name, using the default package.


getFieldName

public java.lang.String getFieldName(java.lang.String name,
                                     com.solarmetric.rd.kodo.meta.ClassMetaData fieldOwner)
Return a default Java identifier-formatted name for the given column/table name.


getRelationName

public java.lang.String getRelationName(java.lang.Class fieldType,
                                        boolean coll,
                                        com.solarmetric.rd.kodo.impl.jdbc.schema.ForeignKey fk,
                                        boolean inverse,
                                        com.solarmetric.rd.kodo.meta.ClassMetaData fieldOwner)
Return a default java identifier-formatted field relation name for the given class name.


getFieldType

public java.lang.Class getFieldType(com.solarmetric.rd.kodo.impl.jdbc.schema.Column col,
                                    boolean forceObject)
Return the default field type for the given column.


generateClass

public java.lang.Class generateClass(java.lang.String name,
                                     java.lang.Class parent)
Generate a new class with the given name. If a non-null parent class is given, it will be set as the superclass.


main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        java.sql.SQLException

Usage: java com.solarmetric.kodo.impl.jdbc.meta.ReverseMappingTool [option]* <.schema file or resource>*

Where the following options are recognized.

Each schema given as an argument will be reverse-mapped into JDO classes and associated metadata. If no arguments are given, the database schemas defined by the system configuration will be reverse-mapped.

java.io.IOException
java.sql.SQLException

run

public static void run(com.solarmetric.rd.kodo.impl.jdbc.conf.JDBCConfiguration conf,
                       java.lang.String[] args,
                       java.lang.String packageName,
                       java.io.File codeDir,
                       boolean useSchemaName,
                       boolean useFKName,
                       boolean nullAsObj,
                       boolean pkOnJoin,
                       boolean datastore,
                       java.lang.String metaLevel,
                       java.lang.String mappingLevel,
                       com.solarmetric.rd.kodo.impl.jdbc.meta.ReverseCustomizer customizer,
                       serp.util.CodeFormat format,
                       java.lang.ClassLoader loader)
                throws java.io.IOException,
                       java.sql.SQLException
Run the tool.

java.io.IOException
java.sql.SQLException

SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.