Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.3.5 generated on August 31 2005
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## kodo.jdbc.meta
Class ReverseMappingTool

    java.lang.Object
      |
      +--kodo.jdbc.meta.ReverseMappingTool

All Implemented Interfaces:
  Cloneable

public class ReverseMappingTool
extends Object
implements Cloneable

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 String` | `LEVEL_CLASS`
`static String` | `LEVEL_PACKAGE`

Constructor Summary
`ReverseMappingTool(JDBCConfiguration conf)` Constructor.

Method Summary
`void` | `addClassIndicator(ClassIndicator cls, ClassMapping owner)` Add a mapping.
`boolean` | `addClassMapping(ClassMapping mapping)` Add a mapping.
`boolean` | `addFieldMapping(FieldMapping field, ClassMapping owner)` Add a mapping.
`void` | `addVersionIndicator(VersionIndicator version, ClassMapping owner)` Add a mapping.
`Object` | `clone()`
`Class` | `generateClass(String name, Class parent)` Generate a new class with the given name.
`void` | `generateMappings()` Generate mappings and class code for the current schema group.
`boolean` | `getBlobAsObject()` Whether to reverse-map blob columns as containing serialized Java objects, rather than the default of using a byte[] field.
`ClassMapping` | `getClassMapping(Table table)` Return the class mapping for the given table, or null if none.
`String` | `getClassName(Table table)` Return a Java identifier-formatted name for the given table name, using the default package.
`serp.util.CodeFormat` | `getCodeFormat()` The code formatter for the generated Java code.
`JDBCConfiguration` | `getConfiguration()` Return the configuration provided on construction.
`ReverseCustomizer` | `getCustomizer()` Return the customizer in use, or null if none.
`File` | `getDirectory()` The file to output the generated code to, or null for the current directory.
`String` | `getFieldName(String name, ClassMetaData fieldOwner)` Return a default Java identifier-formatted name for the given column/table name.
`Class` | `getFieldType(Column col, boolean forceObject)` Return the default field type for the given column.
`boolean` | `getInnerObjectIdClasses()` Whether or not to generate inner classes when creating application identity classes.
`Log` | `getLog()` Return the log to write to.
`ClassMapping[]` | `getMappings()` Return the generated mappings.
`Set` | `getMetaDataFiles()` Returns the `Set` of `File`s to which metadata has been written.
`boolean` | `getNullableAsObject()` Return whether even nullable columns will be mapped to wrappers rather than primitives.
`boolean` | `getOneToManyRelations()` Whether to generate inverse 1-many relations for all 1-1 relations.
`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.
`String` | `getRelationName(Class fieldType, boolean coll, ForeignKey fk, boolean inverse, ClassMetaData fieldOwner)` Return a default java identifier-formatted field relation name for the given class name.
`MappingRepository` | `getRepository()` Return the mapping repository used to hold generated mappings.
`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(String[] args)` Usage: java kodo.jdbc.meta.ReverseMappingTool [option]* <.schema file or resource>*
`ClassMetaData` | `newClassMetaData(Class cls, Class pcParent, int idType)` Return a new class metadata for the given name and parent.
`FieldMetaData` | `newFieldMetaData(String name, Class type, ClassMetaData owner)` Return a new field metadata for the given name, type, and owner.
`static boolean` | `run(JDBCConfiguration conf, String[] args, serp.util.Options opts)` Run the tool.
`static void` | `run(JDBCConfiguration conf, String[] args, String packageName, File codeDir, boolean useSchemaName, boolean useFKName, boolean nullAsObj, boolean blobAsObj, boolean pkOnJoin, boolean datastore, boolean oneMany, boolean innerAppid, String metaLevel, ReverseCustomizer customizer, serp.util.CodeFormat format, ClassLoader loader)` Run the tool.
`void` | `setBlobAsObject(boolean blobAsObj)` Whether to reverse-map blob columns as containing serialized Java objects, rather than the default of using a byte[] field.
`void` | `setCodeFormat(serp.util.CodeFormat format)` Set the code formatter for the generated Java code.
`void` | `setCustomizer(ReverseCustomizer customizer)` Set the customizer.
`void` | `setDirectory(File dir)` The file to output the generated code to, or null for the current directory.
`void` | `setInnerObjectIdClasses(boolean appid)` Whether or not to generate inner classes when creating application identity classes.
`void` | `setNullableAsObject(boolean nullAsObj)` Set whether even nullable columns will be mapped to wrappers rather than primitives.
`void` | `setOneToManyRelations(boolean oneMany)` Whether to generate inverse 1-many relations for all 1-1 relations.
`void` | `setPackageName(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(MappingRepository repos)` Set the repository to use.
`void` | `setSchemaGroup(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.
`List` | `writeCode()` Uses `CodeGenerator`s to write the Java code for the generated mappings to the proper packages.
`List` | `writeCode(Map output)` Write the code for the tool.
`void` | `writeMappings(boolean perClass)` Uses the `XMLMappingInfoSerializer` to write the generated metadata to the proper packages.
`void` | `writeMappings(boolean perClass, Map output)`
`void` | `writeMetaData(boolean perClass)` Uses the `JDOMetaDataSerializer` to write the generated metadata to the proper packages.
`void` | `writeMetaData(boolean perClass, Map output)`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LEVEL_PACKAGE

    public static final String LEVEL_PACKAGE

### LEVEL_CLASS

    public static final String LEVEL_CLASS

Constructor Detail

### ReverseMappingTool

    public ReverseMappingTool(JDBCConfiguration conf)

  Constructor. Supply configuration.

Method Detail

### getConfiguration

    public JDBCConfiguration getConfiguration()

  Return the configuration provided on construction.

### getLog

    public Log getLog()

  Return the log to write to.

### getPackageName

    public String getPackageName()

  Return the default package for the generated classes, or null if unset.

### setPackageName

    public void setPackageName(String packageName)

  Set the default package for the generated classes; use null to indicate no package.

### getDirectory

    public File getDirectory()

  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.

### setDirectory

    public void setDirectory(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.

### getBlobAsObject

    public boolean getBlobAsObject()

  Whether to reverse-map blob columns as containing serialized Java objects, rather than the default of using a byte[] field.

### setBlobAsObject

    public void setBlobAsObject(boolean blobAsObj)

  Whether to reverse-map blob columns as containing serialized Java objects, rather than the default of using a byte[] field.

### 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.

### getOneToManyRelations

    public boolean getOneToManyRelations()

  Whether to generate inverse 1-many relations for all 1-1 relations. Defaults to true.

### setOneToManyRelations

    public void setOneToManyRelations(boolean oneMany)

  Whether to generate inverse 1-many relations for all 1-1 relations. Defaults to true.

### setInnerObjectIdClasses

    public void setInnerObjectIdClasses(boolean appid)

  Whether or not to generate inner classes when creating application identity classes.

### getInnerObjectIdClasses

    public boolean getInnerObjectIdClasses()

  Whether or not to generate inner classes when creating application identity classes.

### 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 ReverseCustomizer getCustomizer()

  Return the customizer in use, or null if none.

### setCustomizer

    public void setCustomizer(ReverseCustomizer customizer)

  Set the customizer. The configuration on the customizer, if any, should already be set.

### getRepository

    public 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(MappingRepository repos)

  Set the repository to use.

### getSchemaGroup

    public 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(SchemaGroup schema)

  Set the schema to reverse map.

### getMappings

    public ClassMapping[] getMappings()

  Return the generated mappings.

### generateMappings

    public void generateMappings()

  Generate mappings and class code for the current schema group.

### writeCode

    public List writeCode()
                   throws IOException

  Uses `CodeGenerator`s to write the Java code for the generated mappings to the proper packages.
  Returns:
    a `List` of `File` instances that were written

### writeCode

    public List writeCode(Map output)
                   throws IOException

  Write the code for the tool.
  Parameters:
    `output` - if null, then perform the write directly to the filesystem; otherwise, populate the specified map with keys as the generated `ClassMapping` and values as a `String` that contains the generated code
  Returns:
    a `List` of `File` instances that were written

### writeMetaData

    public void writeMetaData(boolean perClass)
                       throws IOException

  Uses the `JDOMetaDataSerializer` to write the generated metadata to the proper packages.

### writeMetaData

    public void writeMetaData(boolean perClass,
                              Map output)
                       throws IOException

### getMetaDataFiles

    public Set getMetaDataFiles()

  Returns the `Set` of `File`s to which metadata has been written.

### writeMappings

    public void writeMappings(boolean perClass)
                       throws IOException

  Uses the `XMLMappingInfoSerializer` to write the generated metadata to the proper packages.

### writeMappings

    public void writeMappings(boolean perClass,
                              Map output)
                       throws IOException

### getClassMapping

    public ClassMapping getClassMapping(Table table)

  Return the class mapping for the given table, or null if none.

### addClassMapping

    public boolean addClassMapping(ClassMapping mapping)

  Add a mapping.

### addFieldMapping

    public boolean addFieldMapping(FieldMapping field,
                                   ClassMapping owner)

  Add a mapping.

### addVersionIndicator

    public void addVersionIndicator(VersionIndicator version,
                                    ClassMapping owner)

  Add a mapping.

### addClassIndicator

    public void addClassIndicator(ClassIndicator cls,
                                  ClassMapping owner)

  Add a mapping.

### newClassMetaData

    public ClassMetaData newClassMetaData(Class cls,
                                          Class pcParent,
                                          int idType)

  Return a new class metadata for the given name and parent.
  Parameters:
    `name` - the full name of the class to generate
    `idType` - `ClassMetaData.ID_APPLICATION` or `ClassMetaData.ID_DATASTORE`
    `pcParent` - nearest persistent parent class, or null

### newFieldMetaData

    public FieldMetaData newFieldMetaData(String name,
                                          Class type,
                                          ClassMetaData owner)

  Return a new field metadata for the given name, type, and owner.

### getClassName

    public String getClassName(Table table)

  Return a Java identifier-formatted name for the given table name, using the default package.

### getFieldName

    public String getFieldName(String name,
                               ClassMetaData fieldOwner)

  Return a default Java identifier-formatted name for the given column/table name.

### getRelationName

    public String getRelationName(Class fieldType,
                                  boolean coll,
                                  ForeignKey fk,
                                  boolean inverse,
                                  ClassMetaData fieldOwner)

  Return a default java identifier-formatted field relation name for the given class name.

### getFieldType

    public Class getFieldType(Column col,
                              boolean forceObject)

  Return the default field type for the given column.

### generateClass

    public Class generateClass(String name,
                               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(String[] args)
                     throws IOException,
                            SQLException

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

  Where the following options are recognized.

  - -properties/-p <properties file or resource>: The path or resource name of a Kodo properties file containing information such as the license key data as outlined in `JDOConfiguration`. Optional.
  - -<property name> <property value>: All bean properties of the Kodo `JDBCConfiguration` can be set by using their names and supplying a value. For example: `-licenseKey adslfja83r3lkadf`
  - -schemas/-s <schemas and tables>: Comma-separated list of schemas and tables to reverse-map.
  - -package/-pkg <package name>: The name of the package for all generated classes. Defaults to no package.
  - -directory/-d <output directory>: The directory where all generated code should be placed. Defaults to the current directory.
  - -useSchemaName/-sn <true/t | false/f>: Set this flag to true to include the schema name as part of the generated class name for each table.
  - -useForeignKeyName/-fkn <true/t | false/f>: Set this flag to true to use the foreign key name to generate fields representing relations between classes.
  - -nullableAsObject/-no <true/t | false/f>: Set to true to make all nullable columns map to object types; columns that would normally map to a primitive will map to the appropriate wrapper type instead.
  - -blobAsObject/-bo <true/t | false/f>: Set to true to make all binary columns map to Object rather than byte[].
  - -primaryKeyOnJoin/-pkj <true/t | false/f>: Set to true to allow primary keys on join tables.
  - -useDatastoreIdentity/-ds <true/t | false/f>: Set to true to use datastore identity where possible.
  - -oneToManyRelations/-omr <true/t | false/f>: Set to false to prevent the creation of inverse 1-many relations for each encountered 1-1 relation.
  - -metadata/-md <class | package>: Specify the level the JDO metadata should be generated at. Defaults to generating a single package-level metadata file.
  - -customizerClass/-cc <class name>: The full class name of a `ReverseCustomizer` implementation to use to customize the reverse mapping process. Optional.
  - -customizerProperties/-cp <properties file or resource> : The path or resource name of a properties file that will be passed to the reverse customizer on initialization. Optional.
  - -customizer/-c.<property name> < property value> : Arguments like this will be used to configure the bean properties of the `ReverseCustomizer`.
  - -codeFormat/-cf.<property name> < property value> : Arguments like this will be used to configure the bean properties of the internal `CodeFormat`.

  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.

### run

    public static boolean run(JDBCConfiguration conf,
                              String[] args,
                              serp.util.Options opts)
                       throws IOException,
                              SQLException

  Run the tool. Returns false if invalid options were given.
  See Also:
    `main(java.lang.String[])`

### run

    public static void run(JDBCConfiguration conf,
                           String[] args,
                           String packageName,
                           File codeDir,
                           boolean useSchemaName,
                           boolean useFKName,
                           boolean nullAsObj,
                           boolean blobAsObj,
                           boolean pkOnJoin,
                           boolean datastore,
                           boolean oneMany,
                           boolean innerAppid,
                           String metaLevel,
                           ReverseCustomizer customizer,
                           serp.util.CodeFormat format,
                           ClassLoader loader)
                    throws IOException,
                           SQLException

  Run the tool.

### clone

    public Object clone()

  Overrides:
    `clone` in class `Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
| SolarMetric Kodo JDO 3.3.5 generated on August 31 2005
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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