public class SchemaTool
extends java.lang.Object
DatabaseMetaData
does not include information on these
constraints.Modifier and Type | Class and Description |
---|---|
static class |
SchemaTool.Flags
Run flags.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTION_ADD |
static java.lang.String |
ACTION_BUILD |
static java.lang.String |
ACTION_CREATEDB |
static java.lang.String |
ACTION_DELETE_TABLE_CONTENTS |
static java.lang.String |
ACTION_DROP |
static java.lang.String |
ACTION_DROPDB |
static java.lang.String |
ACTION_EXPORT |
static java.lang.String |
ACTION_IMPORT |
static java.lang.String |
ACTION_REFLECT |
static java.lang.String |
ACTION_REFRESH |
static java.lang.String |
ACTION_RETAIN |
static java.lang.String[] |
ACTIONS |
Constructor and Description |
---|
SchemaTool(JDBCConfiguration conf)
Default constructor.
|
SchemaTool(JDBCConfiguration conf,
java.lang.String action)
Construct a tool to perform the given action.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
add()
Adds any components present in the schema repository but absent from
the database.
|
boolean |
addColumn(Column col)
Add the given column to the database schema.
|
boolean |
addForeignKey(ForeignKey fk)
Add the given foreign key to the database schema.
|
boolean |
addPrimaryKey(PrimaryKey pk)
Add the given primary key to the database schema.
|
(package private) void |
build()
Re-execute all SQL used for the creation of the current database;
this action is usually used when creating SQL scripts.
|
void |
clear()
Cleanup DataSource after run()/record()
|
(package private) void |
createDB()
Re-execute all SQL used for the creation of the current database;
this action is usually used when creating SQL scripts.
|
boolean |
createIndex(Index idx,
Table table)
Add the given index to the database schema.
|
boolean |
createIndex(Index idx,
Table table,
Unique[] uniques) |
boolean |
createSequence(Sequence seq)
Add the given sequence to the database schema.
|
boolean |
createTable(Table table)
Add the given table to the database schema.
|
(package private) void |
drop()
Drops all schema components in the schema repository that also exist
in the database.
|
boolean |
dropColumn(Column col)
Drop the given column from the database schema.
|
(package private) void |
dropDB()
Drop the current database.
|
boolean |
dropForeignKey(ForeignKey fk)
Drop the given foreign key from the database schema.
|
boolean |
dropIndex(Index idx)
Drop the given index from the database schema.
|
boolean |
dropPrimaryKey(PrimaryKey pk)
Drop the given primary key from the database schema.
|
boolean |
dropSequence(Sequence seq)
Drop the given sequence from the database schema.
|
boolean |
dropTable(Table table)
Drop the given table from the database schema.
|
java.lang.String |
getAction()
The action supplied on construction.
|
SchemaGroup |
getDBSchemaGroup()
Return the database schema.
|
boolean |
getDropSequences()
If true, sequences that appear to be unused will be dropped.
|
boolean |
getDropTables()
If true, tables that appear to be unused will be dropped.
|
boolean |
getForeignKeys()
Whether foreign keys on existing tables should be manipulated.
|
boolean |
getIgnoreErrors()
If true, SQLExceptions thrown during schema manipulation will be
printed but ignored.
|
boolean |
getIndexes()
Whether indexes on existing tables should be manipulated.
|
boolean |
getOpenJPATables()
Whether to act on special tables used by OpenJPA components
for bookkeeping.
|
boolean |
getPrimaryKeys()
Whether primary keys on existing tables should be manipulated.
|
SchemaGroup |
getSchemaGroup()
Return the schema group the tool will act on.
|
boolean |
getSequences()
Whether sequences should be manipulated.
|
java.io.Writer |
getWriter()
The stream to write to for the creation of SQL scripts.
|
static void |
main(java.lang.String[] args)
Usage: java org.apache.openjpa.jdbc.schema.SchemaTool [option]*
[-action/-a <add | retain | drop | refresh | createDB | dropDB
| build | reflect | import | export>]
<.schema file or resource>*
Where the following options are recognized.
|
void |
record()
Record the changes made to the DB in the current
SchemaFactory . |
(package private) void |
refresh()
Adds any components present in the schema repository but absent from
the database, and drops unused database components.
|
(package private) void |
retain()
Drops database components that are not mentioned in the schema
repository.
|
void |
run()
Run the tool action.
|
static boolean |
run(JDBCConfiguration conf,
java.lang.String[] args,
Options opts)
Run the tool.
|
static boolean |
run(JDBCConfiguration conf,
java.lang.String[] args,
SchemaTool.Flags flags,
java.lang.ClassLoader loader)
Run the tool.
|
void |
setDBSchemaGroup(SchemaGroup db)
Set the database schema.
|
void |
setDropSequences(boolean dropSeqs)
If true, sequences that appear to be unused will be dropped.
|
void |
setDropTables(boolean dropTables)
If true, tables that appear to be unused will be dropped.
|
void |
setForeignKeys(boolean fks)
Whether foreign keys on existing tables should be manipulated.
|
void |
setIgnoreErrors(boolean ignoreErrs)
If true, SQLExceptions thrown during schema manipulation will be
printed but ignored.
|
void |
setIndexes(boolean indexes)
Whether indexes on existing tables should be manipulated.
|
void |
setOpenJPATables(boolean openjpaTables)
Whether to act on special tables used by OpenJPA components
for bookkeeping.
|
void |
setPrimaryKeys(boolean pks)
Whether primary keys on existing tables should be manipulated.
|
void |
setSchemaGroup(SchemaGroup group)
Set the schema group the tool will act on.
|
void |
setSequences(boolean seqs)
Whether sequences should be manipulated.
|
void |
setSQLTerminator(java.lang.String t) |
void |
setWriter(java.io.Writer writer)
The stream to write to for the creation of SQL scripts.
|
public static final java.lang.String ACTION_ADD
public static final java.lang.String ACTION_DROP
public static final java.lang.String ACTION_RETAIN
public static final java.lang.String ACTION_REFRESH
public static final java.lang.String ACTION_BUILD
public static final java.lang.String ACTION_REFLECT
public static final java.lang.String ACTION_CREATEDB
public static final java.lang.String ACTION_DROPDB
public static final java.lang.String ACTION_IMPORT
public static final java.lang.String ACTION_EXPORT
public static final java.lang.String ACTION_DELETE_TABLE_CONTENTS
public static final java.lang.String[] ACTIONS
public SchemaTool(JDBCConfiguration conf)
run()
method will be a no-op.public SchemaTool(JDBCConfiguration conf, java.lang.String action)
public void clear()
public java.lang.String getAction()
public boolean getIgnoreErrors()
public void setIgnoreErrors(boolean ignoreErrs)
public boolean getOpenJPATables()
public void setOpenJPATables(boolean openjpaTables)
public boolean getDropTables()
public void setDropTables(boolean dropTables)
public boolean getDropSequences()
public void setDropSequences(boolean dropSeqs)
public boolean getSequences()
public void setSequences(boolean seqs)
public boolean getIndexes()
public void setIndexes(boolean indexes)
public boolean getForeignKeys()
public void setForeignKeys(boolean fks)
public boolean getPrimaryKeys()
public void setPrimaryKeys(boolean pks)
public java.io.Writer getWriter()
public void setWriter(java.io.Writer writer)
public void setSQLTerminator(java.lang.String t)
public SchemaGroup getSchemaGroup()
public void setSchemaGroup(SchemaGroup group)
public void run() throws java.sql.SQLException
java.sql.SQLException
void add() throws java.sql.SQLException
java.sql.SQLException
void drop() throws java.sql.SQLException
java.sql.SQLException
void retain() throws java.sql.SQLException
java.sql.SQLException
void refresh() throws java.sql.SQLException
java.sql.SQLException
void createDB() throws java.sql.SQLException
java.sql.SQLException
void build() throws java.sql.SQLException
java.sql.SQLException
void dropDB() throws java.sql.SQLException
java.sql.SQLException
public void record()
SchemaFactory
.public boolean createTable(Table table) throws java.sql.SQLException
java.sql.SQLException
public boolean dropTable(Table table) throws java.sql.SQLException
java.sql.SQLException
public boolean createSequence(Sequence seq) throws java.sql.SQLException
java.sql.SQLException
public boolean dropSequence(Sequence seq) throws java.sql.SQLException
java.sql.SQLException
public boolean createIndex(Index idx, Table table) throws java.sql.SQLException
java.sql.SQLException
public boolean createIndex(Index idx, Table table, Unique[] uniques) throws java.sql.SQLException
java.sql.SQLException
public boolean dropIndex(Index idx) throws java.sql.SQLException
java.sql.SQLException
public boolean addColumn(Column col) throws java.sql.SQLException
java.sql.SQLException
public boolean dropColumn(Column col) throws java.sql.SQLException
java.sql.SQLException
public boolean addPrimaryKey(PrimaryKey pk) throws java.sql.SQLException
java.sql.SQLException
public boolean dropPrimaryKey(PrimaryKey pk) throws java.sql.SQLException
java.sql.SQLException
public boolean addForeignKey(ForeignKey fk) throws java.sql.SQLException
java.sql.SQLException
public boolean dropForeignKey(ForeignKey fk) throws java.sql.SQLException
java.sql.SQLException
public SchemaGroup getDBSchemaGroup()
public void setDBSchemaGroup(SchemaGroup db)
public static void main(java.lang.String[] args) throws java.io.IOException, java.sql.SQLException
JDBCConfiguration
. Optional.JDBCConfiguration
can be set by
using their names and supplying a value. For example:
-licenseKey adslfja83r3lkadf
false
.export
and reflect
actions.reflect
action, whether to reflect on tables with
the name OPENJPA_*
. Under other actions, whether to
drop such tables. Defaults to false
.retain
and refresh
actions. Defaults to
true
.retain
and refresh
actions. Defaults to
true
.false
to prevent writing the schema changes to the
current SchemaFactory
.file
option.file
option.file
option, or to stdout if no file is given.dropTables
.SchemaFactory
.SchemaFactory
's recorded
schema to an XML schema definition file.java org.apache.openjpa.jdbc.schema.SchemaTool -f stdout
-a createDB
java org.apache.openjpa.jdbc.schema.SchemaTool
-a dropDB
java org.apache.openjpa.jdbc.schema.SchemaTool
-a refresh,deleteTableContents
java org.apache.openjpa.jdbc.schema.SchemaTool
myschema.xml
java.io.IOException
java.sql.SQLException
public static boolean run(JDBCConfiguration conf, java.lang.String[] args, Options opts) throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
main(java.lang.String[])
public static boolean run(JDBCConfiguration conf, java.lang.String[] args, SchemaTool.Flags flags, java.lang.ClassLoader loader) throws java.io.IOException, java.sql.SQLException
java.io.IOException
java.sql.SQLException
Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.