public class ReverseMappingTool extends Object implements MetaDataModes, Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
ReverseMappingTool.Flags
Holder for run flags.
|
Modifier and Type | Field and Description |
---|---|
static String |
ACCESS_TYPE_FIELD
Access type for generated source, defaults to field-based access.
|
static String |
ACCESS_TYPE_PROPERTY |
static String |
LEVEL_CLASS |
static String |
LEVEL_NONE |
static String |
LEVEL_PACKAGE |
static int |
TABLE_ASSOCIATION
Association table.
|
static int |
TABLE_BASE
Primary table for a new base class.
|
static int |
TABLE_NONE
Unmapped table.
|
static int |
TABLE_SECONDARY
Secondary table of an existing class.
|
static int |
TABLE_SECONDARY_OUTER
Secondary table of an existing class.
|
static int |
TABLE_SUBCLASS
Subclass table.
|
MODE_ALL, MODE_ANN_MAPPING, MODE_MAPPING, MODE_MAPPING_INIT, MODE_META, MODE_NONE, MODE_QUERY
Constructor and Description |
---|
ReverseMappingTool(JDBCConfiguration conf)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addConstraints(ValueMapping vm)
Add existing unique constraints and indexes to the given value.
|
void |
addJoinConstraints(FieldMapping field)
Add existing unique constraints and indexes to the given field's join.
|
void |
buildAnnotations() |
Object |
clone()
Return a new tool with the same settings as this one.
|
Class |
generateClass(String name,
Class parent)
Generate a new class with the given name.
|
String |
getAccessType()
Whether to use field or property-based access on generated code.
|
List |
getAnnotationsForMeta(Object meta)
Returns a list of stringified annotations for specified meta.
|
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.
|
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.
|
boolean |
getDetachable()
Whether to make generated classes detachable.
|
File |
getDirectory()
The file to output the generated code to, or null for
the current directory.
|
String |
getDiscriminatorStrategy()
Default discriminator strategy for base class mappings.
|
String |
getFieldName(String name,
ClassMapping dec)
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 |
getGenerateAnnotations()
Whether to generate annotations along with generated code.
|
String |
getIdentityClassSuffix()
Suffix used to create application identity class name from a class name,
or in the case of inner identity classes, the inner class name.
|
boolean |
getInnerIdentityClasses()
Whether or not to generate inner classes when creating application
identity classes.
|
boolean |
getInverseRelations()
Whether to generate inverse 1-many/1-1 relations for all many-1/1-1
relations.
|
Log |
getLog()
Return the log to write to.
|
ClassMapping[] |
getMappings()
Return the generated mappings.
|
boolean |
getNullableAsObject()
Return whether even nullable columns will be mapped to wrappers
rather than primitives.
|
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.
|
MappingRepository |
getRepository()
Return the mapping repository used to hold generated mappings.
|
SchemaGroup |
getSchemaGroup()
Return the schema group to reverse map.
|
Properties |
getTypeMap()
Map of JDBC-name to Java-type-name entries that allows customization
of reverse mapping columns to field types.
|
ForeignKey |
getUniqueForeignKey(Table table)
If the given table has a single unique foreign key or a foreign
key that matches the primary key, return it.
|
boolean |
getUseBuiltinIdentityClass()
Whether to use built in identity classes when possible.
|
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 |
getUseGenericCollections()
Whether to use generic collections on one-to-many and many-to-many
relations instead of untyped collections.
|
boolean |
getUseSchemaElement()
Returns whether or not the schema name will be included in the @Table
annotation within the generated class for each table, as well as the
corresponding XML mapping files.
|
boolean |
getUseSchemaName()
Return true if the schema name will be included in the generated
class name for each table.
|
String |
getVersionStrategy()
Default version strategy for base class mappings.
|
boolean |
isBaseTable(Table table)
Return whether the given table is a base class table.
|
boolean |
isUnique(ForeignKey fk)
Return whether the given foreign key is unique.
|
static void |
main(String[] args)
Usage: java org.apache.openjpa.jdbc.meta.ReverseMappingTool
[option]* <.schema file or resource>*
Where the following options are recognized.
|
ClassMapping |
newClassMapping(Class cls,
Table table)
Create a new class to be mapped to a table.
|
FieldMapping |
newFieldMapping(String name,
Class type,
Column col,
ForeignKey fk,
ClassMapping dec)
Create a field mapping for the given info, or return null if
customizer rejects.
|
protected static ReverseMappingTool |
newInstance(JDBCConfiguration conf) |
List |
recordCode()
Uses
CodeGenerator s to write the Java code for the generated
mappings to the proper packages. |
List |
recordCode(Map<Class<?>,String> output)
Write the code for the tool.
|
Collection |
recordMetaData(boolean perClass)
Write the generated metadata to the proper packages.
|
Collection |
recordMetaData(boolean perClass,
Map output)
Write the code for the tool.
|
void |
run()
Generate mappings and class code for the current schema group.
|
static boolean |
run(JDBCConfiguration conf,
String[] args,
Options opts)
Run the tool.
|
static boolean |
run(JDBCConfiguration conf,
String[] args,
Options opts,
Map<Class<?>,String> output)
Run the tool and write to the optionally provided map.
|
static void |
run(JDBCConfiguration conf,
String[] args,
ReverseMappingTool.Flags flags,
ClassLoader loader)
Run the tool.
|
static void |
run(JDBCConfiguration conf,
String[] args,
ReverseMappingTool.Flags flags,
ClassLoader loader,
Map<Class<?>,String> output)
Run the tool and write to the optionally provided map
|
void |
setAccessType(String accessType)
Whether to use field or property-based access on generated code.
|
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(CodeFormat format)
Set the code formatter for the generated Java code.
|
void |
setCustomizer(ReverseCustomizer customizer)
Set the customizer.
|
void |
setDetachable(boolean detachable)
Whether to make generated classes detachable.
|
void |
setDirectory(File dir)
The file to output the generated code to, or null for
the current directory.
|
void |
setDiscriminatorStrategy(String discStrat)
Default discriminator strategy for base class mappings.
|
void |
setGenerateAnnotations(boolean genAnnotations)
Whether to generate annotations along with generated code.
|
void |
setIdentityClassSuffix(String suffix)
Suffix used to create application identity class name from a class name,
or in the case of inner identity classes, the inner class name.
|
void |
setInnerIdentityClasses(boolean inner)
Whether or not to generate inner classes when creating application
identity classes.
|
void |
setInverseRelations(boolean inverse)
Whether to generate inverse 1-many/1-1 relations for all many-1/1-1
relations.
|
void |
setNullableAsObject(boolean nullAsObj)
Set whether even nullable columns will be mapped to wrappers
rather than primitives.
|
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 |
setTypeMap(Properties typeMap)
Map of JDBC-name to Java-type-name entries that allows customization
of reverse mapping columns to field types.
|
void |
setUseBuiltinIdentityClass(boolean builtin)
Whether to use built in identity classes when possible.
|
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 |
setUseGenericCollections(boolean useGenericCollections)
Whether to use generic collections on one-to-many and many-to-many
relations instead of untyped collections.
|
void |
setUseSchemaElement(boolean useSchemaElement)
Sets whether or not the schema name will be included in the @Table
annotation within the generated class for each table, as well as the
corresponding XML mapping files.
|
void |
setUseSchemaName(boolean useSchema)
Set whether the schema name will be included in the generated
class name for each table.
|
void |
setVersionStrategy(String versionStrat)
Default version strategy for base class mappings.
|
public static final int TABLE_NONE
public static final int TABLE_BASE
public static final int TABLE_SECONDARY
public static final int TABLE_SECONDARY_OUTER
public static final int TABLE_ASSOCIATION
public static final int TABLE_SUBCLASS
public static final String LEVEL_NONE
public static final String LEVEL_PACKAGE
public static final String LEVEL_CLASS
public static final String ACCESS_TYPE_FIELD
public static final String ACCESS_TYPE_PROPERTY
public ReverseMappingTool(JDBCConfiguration conf)
public JDBCConfiguration getConfiguration()
public Log getLog()
public String getPackageName()
public void setPackageName(String packageName)
public File getDirectory()
public void setDirectory(File dir)
public boolean getUseSchemaName()
public void setUseSchemaName(boolean useSchema)
public boolean getUseForeignKeyName()
public void setUseForeignKeyName(boolean useFK)
public boolean getNullableAsObject()
public void setNullableAsObject(boolean nullAsObj)
public boolean getBlobAsObject()
public void setBlobAsObject(boolean blobAsObj)
public boolean getUseGenericCollections()
public void setUseGenericCollections(boolean useGenericCollections)
public Properties getTypeMap()
public void setTypeMap(Properties typeMap)
public boolean getPrimaryKeyOnJoin()
public void setPrimaryKeyOnJoin(boolean pkOnJoin)
public boolean getUseDataStoreIdentity()
public void setUseDataStoreIdentity(boolean datastore)
public boolean getUseBuiltinIdentityClass()
public void setUseBuiltinIdentityClass(boolean builtin)
public boolean getInnerIdentityClasses()
public void setInnerIdentityClasses(boolean inner)
public String getIdentityClassSuffix()
public void setIdentityClassSuffix(String suffix)
public boolean getInverseRelations()
public void setInverseRelations(boolean inverse)
public boolean getDetachable()
public void setDetachable(boolean detachable)
public String getDiscriminatorStrategy()
public void setDiscriminatorStrategy(String discStrat)
public String getVersionStrategy()
public void setVersionStrategy(String versionStrat)
public boolean getGenerateAnnotations()
public void setGenerateAnnotations(boolean genAnnotations)
public String getAccessType()
public void setAccessType(String accessType)
public CodeFormat getCodeFormat()
public void setCodeFormat(CodeFormat format)
public ReverseCustomizer getCustomizer()
public void setCustomizer(ReverseCustomizer customizer)
public boolean getUseSchemaElement()
public void setUseSchemaElement(boolean useSchemaElement)
public MappingRepository getRepository()
public void setRepository(MappingRepository repos)
public SchemaGroup getSchemaGroup()
public void setSchemaGroup(SchemaGroup schema)
public ClassMapping[] getMappings()
public void run()
public List recordCode() throws IOException
CodeGenerator
s to write the Java code for the generated
mappings to the proper packages.File
instances that were writtenIOException
public List recordCode(Map<Class<?>,String> output) throws IOException
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 codeFile
instances that were writtenIOException
public Collection recordMetaData(boolean perClass) throws IOException
File
s that were writtenIOException
public Collection recordMetaData(boolean perClass, Map output) throws IOException
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 codeFile
s that were writtenIOException
public void buildAnnotations()
public List getAnnotationsForMeta(Object meta)
public ClassMapping getClassMapping(Table table)
public ClassMapping newClassMapping(Class cls, Table table)
public Class generateClass(String name, Class parent)
public boolean isUnique(ForeignKey fk)
public ForeignKey getUniqueForeignKey(Table table)
public void addJoinConstraints(FieldMapping field)
public void addConstraints(ValueMapping vm)
public boolean isBaseTable(Table table)
public FieldMapping newFieldMapping(String name, Class type, Column col, ForeignKey fk, ClassMapping dec)
public String getFieldName(String name, ClassMapping dec)
public Class getFieldType(Column col, boolean forceObject)
public Object clone()
protected static ReverseMappingTool newInstance(JDBCConfiguration conf)
public static void main(String[] args) throws IOException, SQLException
OpenJPAConfiguration
. Optional.JDBCConfiguration
can be set by
using their names and supplying a value. For example:
-licenseKey adslfja83r3lkadf
ReverseCustomizer
implementation to use to
customize the reverse mapping process. Optional.ReverseCustomizer
.CodeFormat
.IOException
SQLException
public static boolean run(JDBCConfiguration conf, String[] args, Options opts) throws IOException, SQLException
IOException
SQLException
main(java.lang.String[])
public static boolean run(JDBCConfiguration conf, String[] args, Options opts, Map<Class<?>,String> output) throws IOException, SQLException
IOException
SQLException
main(java.lang.String[])
public static void run(JDBCConfiguration conf, String[] args, ReverseMappingTool.Flags flags, ClassLoader loader) throws IOException, SQLException
IOException
SQLException
public static void run(JDBCConfiguration conf, String[] args, ReverseMappingTool.Flags flags, ClassLoader loader, Map<Class<?>,String> output) throws IOException, SQLException
IOException
SQLException
Copyright © 2006–2018 Apache Software Foundation. All rights reserved.