org.apache.openjpa.jdbc.meta
Class MappingTool

java.lang.Object
  extended by org.apache.openjpa.jdbc.meta.MappingTool
All Implemented Interfaces:
MetaDataModes

public class MappingTool
extends Object
implements MetaDataModes

Tool for manipulating class mappings and associated schema.

Author:
Abe White

Nested Class Summary
static class MappingTool.Flags
          Run flags.
static interface MappingTool.ImportExport
          Helper used to import and export mapping data.
 
Field Summary
static String ACTION_ADD
           
static String ACTION_BUILD_SCHEMA
           
static String ACTION_DROP
           
static String ACTION_EXPORT
           
static String ACTION_IMPORT
           
static String ACTION_REFRESH
           
static String ACTION_VALIDATE
           
static String[] ACTIONS
           
static String SCHEMA_ACTION_NONE
           
 
Fields inherited from interface org.apache.openjpa.meta.MetaDataModes
MODE_ALL, MODE_ANN_MAPPING, MODE_MAPPING, MODE_MAPPING_INIT, MODE_META, MODE_NONE, MODE_QUERY
 
Constructor Summary
MappingTool(JDBCConfiguration conf, String action, boolean meta)
          Constructor.
 
Method Summary
 void clear()
          Reset the internal repository.
 String getAction()
          The action supplied on construction.
 boolean getDropUnusedComponents()
          Whether schema components that are unused by any mapping will be dropped from this tool's SchemaGroup, and, depending on the schema action, from the database.
 boolean getForeignKeys()
          Whether foreign keys on existing tables should be manipulated.
 boolean getIgnoreErrors()
          Whether and SQL errors should cause a failure or just issue a warning.
 boolean getIndexes()
          Whether indexes on existing tables should be manipulated.
 Writer getMappingWriter()
          The stream to export the planned mappings to as an XML document.
 File getMetaDataFile()
          If adding metadata, the metadata file to add to.
 boolean getPrimaryKeys()
          Whether primary keys on existing tables should be manipulated.
 boolean getReadSchema()
          Set to true to read the entire schema before mapping.
 MappingRepository getRepository()
          Return the repository to use to access mapping information.
 String getSchemaAction()
          The schema modification policy, or none.
 SchemaGroup getSchemaGroup()
          Return the schema group to use in mapping.
 Writer getSchemaWriter()
          The stream to export the planned schema to as an XML document.
 boolean getSequences()
          Whether to manipulate sequences.
 boolean isMetaDataAction()
          Whether the action works on metadata as well as mappings.
static void main(String[] arguments)
          Usage: java org.apache.openjpa.jdbc.meta.MappingTool [option]* [-action/-a <refresh | add | buildSchema | drop | validate | import | export>] <class name | .java file | .class file | .jdo file>* Where the following options are recognized.
 void record()
          Records the changes that have been made to both the mappings and the associated schema, and clears the tool for further use.
 void record(MappingTool.Flags flags)
           
 void run(Class<?> cls)
          Run the configured action on the given instance.
static boolean run(JDBCConfiguration conf, String[] args, MappingTool.Flags flags, ClassLoader loader)
          Run the tool.
static boolean run(JDBCConfiguration conf, String[] args, Options opts)
          Run the tool.
 void setDropUnusedComponents(boolean dropUnused)
          Whether schema components that are unused by any mapping will be dropped from this tool's SchemaGroup, and, depending on the schema action, from the database.
 void setForeignKeys(boolean fks)
          Whether foreign keys on existing tables should be manipulated.
 void setIgnoreErrors(boolean ignoreErrors)
          Whether and SQL errors should cause a failure or just issue a warning.
 void setIndexes(boolean indexes)
          Whether indexes on existing tables should be manipulated.
 void setMappingWriter(Writer mappingWriter)
          The stream to export the planned mappings to as an XML document.
 void setMetaDataFile(File file)
          If adding metadata, the metadata file to add to.
 void setPrimaryKeys(boolean pks)
          Whether primary keys on existing tables should be manipulated.
 void setReadSchema(boolean readSchema)
          Set to true to read the entire schema before mapping.
 void setRepository(MappingRepository repos)
          Set the repository to use to access mapping information.
 void setSchemaAction(String schemaAction)
          The schema modification policy, or none.
 void setSchemaGroup(SchemaGroup schema)
          Set the schema to use in mapping.
 void setSchemaTool(SchemaTool tool)
          Set the schema tool to use for schema modification.
 void setSchemaWriter(Writer schemaWriter)
          The stream to export the planned schema to as an XML document.
 void setSequences(boolean seqs)
          Whether to manipulate sequences.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEMA_ACTION_NONE

public static final String SCHEMA_ACTION_NONE
See Also:
Constant Field Values

ACTION_ADD

public static final String ACTION_ADD
See Also:
Constant Field Values

ACTION_REFRESH

public static final String ACTION_REFRESH
See Also:
Constant Field Values

ACTION_BUILD_SCHEMA

public static final String ACTION_BUILD_SCHEMA
See Also:
Constant Field Values

ACTION_DROP

public static final String ACTION_DROP
See Also:
Constant Field Values

ACTION_VALIDATE

public static final String ACTION_VALIDATE
See Also:
Constant Field Values

ACTION_EXPORT

public static final String ACTION_EXPORT
See Also:
Constant Field Values

ACTION_IMPORT

public static final String ACTION_IMPORT
See Also:
Constant Field Values

ACTIONS

public static final String[] ACTIONS
Constructor Detail

MappingTool

public MappingTool(JDBCConfiguration conf,
                   String action,
                   boolean meta)
Constructor. Supply configuration and action.

Method Detail

getAction

public String getAction()
The action supplied on construction.


isMetaDataAction

public boolean isMetaDataAction()
Whether the action works on metadata as well as mappings.


getSchemaAction

public String getSchemaAction()
The schema modification policy, or none. See the ACTION constants in SchemaTool. May be a comma-separated list of values. Defaults to SchemaTool.ACTION_ADD.


setSchemaAction

public void setSchemaAction(String schemaAction)
The schema modification policy, or none. See the ACTION constants in SchemaTool. May be a comma-separated list of values. Defaults to SchemaTool.ACTION_ADD.


getReadSchema

public boolean getReadSchema()
Set to true to read the entire schema before mapping. Leaving this option false saves time, but is dangerous when adding new mappings, because without full knowledge of the existing schema the mapping tool might create tables or indexes that conflict with existing components.


setReadSchema

public void setReadSchema(boolean readSchema)
Set to true to read the entire schema before mapping. Leaving this option false saves time, but is dangerous when adding new mappings, because without full knowledge of the existing schema the mapping tool might create tables or indexes that conflict with existing components.


getSequences

public boolean getSequences()
Whether to manipulate sequences. Defaults to true.


setSequences

public void setSequences(boolean seqs)
Whether to manipulate sequences. Defaults to true.


getIndexes

public boolean getIndexes()
Whether indexes on existing tables should be manipulated. Defaults to false.


setIndexes

public void setIndexes(boolean indexes)
Whether indexes on existing tables should be manipulated. Defaults to false.


getForeignKeys

public boolean getForeignKeys()
Whether foreign keys on existing tables should be manipulated. Defaults to false.


setForeignKeys

public void setForeignKeys(boolean fks)
Whether foreign keys on existing tables should be manipulated. Defaults to false.


getPrimaryKeys

public boolean getPrimaryKeys()
Whether primary keys on existing tables should be manipulated. Defaults to false.


setPrimaryKeys

public void setPrimaryKeys(boolean pks)
Whether primary keys on existing tables should be manipulated. Defaults to false.


getDropUnusedComponents

public boolean getDropUnusedComponents()
Whether schema components that are unused by any mapping will be dropped from this tool's SchemaGroup, and, depending on the schema action, from the database. Defaults to true.


setDropUnusedComponents

public void setDropUnusedComponents(boolean dropUnused)
Whether schema components that are unused by any mapping will be dropped from this tool's SchemaGroup, and, depending on the schema action, from the database. Defaults to true.


setIgnoreErrors

public void setIgnoreErrors(boolean ignoreErrors)
Whether and SQL errors should cause a failure or just issue a warning.


getIgnoreErrors

public boolean getIgnoreErrors()
Whether and SQL errors should cause a failure or just issue a warning.


setSchemaTool

public void setSchemaTool(SchemaTool tool)
Set the schema tool to use for schema modification.


getSchemaWriter

public Writer getSchemaWriter()
The stream to export the planned schema to as an XML document. If non-null, then the database schema will not be altered.


setSchemaWriter

public void setSchemaWriter(Writer schemaWriter)
The stream to export the planned schema to as an XML document. If non-null, then the database schema will not be altered.


getMappingWriter

public Writer getMappingWriter()
The stream to export the planned mappings to as an XML document. If non-null, then the mapping repository will not be altered.


setMappingWriter

public void setMappingWriter(Writer mappingWriter)
The stream to export the planned mappings to as an XML document. If non-null, then the mapping repository will not be altered.


getMetaDataFile

public File getMetaDataFile()
If adding metadata, the metadata file to add to.


setMetaDataFile

public void setMetaDataFile(File file)
If adding metadata, the metadata file to add to.


getRepository

public MappingRepository getRepository()
Return the repository to use to access mapping information. Defaults to a new MappingRepository.


setRepository

public void setRepository(MappingRepository repos)
Set the repository to use to access mapping information.


getSchemaGroup

public SchemaGroup getSchemaGroup()
Return the schema group to use in mapping. If none has been set, the schema will be generated from the database.


setSchemaGroup

public void setSchemaGroup(SchemaGroup schema)
Set the schema to use in mapping.


clear

public void clear()
Reset the internal repository. This is called automatically after every record().


record

public void record()
Records the changes that have been made to both the mappings and the associated schema, and clears the tool for further use. This also involves clearing the internal mapping repository.


record

public void record(MappingTool.Flags flags)

run

public void run(Class<?> cls)
Run the configured action on the given instance.


main

public static void main(String[] arguments)
                 throws IOException,
                        SQLException
Usage: java org.apache.openjpa.jdbc.meta.MappingTool [option]* [-action/-a <refresh | add | buildSchema | drop | validate | import | export>] <class name | .java file | .class file | .jdo file>* Where the following options are recognized. The various actions are as follows. Each class supplied as an argument must have valid metadata. If no class arguments are given, the tool runs on all metadata files in the CLASSPATH. Examples:

Throws:
IOException
SQLException

run

public static boolean run(JDBCConfiguration conf,
                          String[] args,
                          Options opts)
                   throws IOException,
                          SQLException
Run the tool. Returns false if invalid options are given.

Throws:
IOException
SQLException
See Also:
main(java.lang.String[])

run

public static boolean run(JDBCConfiguration conf,
                          String[] args,
                          MappingTool.Flags flags,
                          ClassLoader loader)
                   throws IOException,
                          SQLException
Run the tool. Return false if an invalid option was given.

Throws:
IOException
SQLException


Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.