Top Description Inners Fields Constructors Methods
org.hibernate.tool.hbm2ddl

public Class SchemaExport

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .FileInputStream, .FileWriter, .IOException, .InputStream, .InputStreamReader, .Reader, .Writer, java.sql.Connection, .SQLException, .SQLWarning, .Statement, java.util.ArrayList, .List, .Properties, org.slf4j.Logger, .LoggerFactory, org.hibernate.HibernateException, .JDBCException, org.hibernate.cfg.Configuration, .Environment, .NamingStrategy, .Settings, org.hibernate.dialect.Dialect, org.hibernate.jdbc.util.FormatStyle, .Formatter, .SQLStatementLogger, org.hibernate.util.ConfigHelper, .JDBCExceptionReporter, .PropertiesHelper, .ReflectHelper

Commandline tool to export table schema to the database. This class may also be called from inside an application.
Authors
Daniel Bradby, Gavin King

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private ConnectionHelper
private String[]
private static final String
private String
private Dialect
private String[]
private final List<E>
private Formatter
private boolean
private String
private static final Logger
private String
private SQLStatementLogger

Constructor Summary

AccessConstructor and Description
public
SchemaExport(Configuration
The configuration from which to build a schema export.
cfg
)

Create a schema exporter for the given Configuration

public
SchemaExport(Configuration
The configuration from which to build a schema export.
cfg
,
Settings
The 'parsed' settings.
settings
)

Create a schema exporter for the given Configuration and given settings

public
SchemaExport(Configuration
The configuration from which to build a schema export.
cfg
,
Properties
The properties from which to configure connectivity etc.
properties
)

Deprecated properties may be specified via the Configuration object
Create a schema exporter for the given Configuration, with the given database connection properties.
public
SchemaExport(Configuration
The configuration to use.
cfg
,
Connection
The JDBC connection to use.
connection
)

Create a schema exporter for the given Configuration, using the supplied connection for connectivity.

Method Summary

Modifier and TypeMethod and Description
public void
create(boolean
print the DDL to the console
script
,
boolean
export the script to the database
export
)

Run the schema creation script.

private void
create(boolean script, boolean export, Writer fileOutput, Statement statement)

public void
drop(boolean
print the DDL to the console
script
,
boolean
export the script to the database
export
)

Run the drop schema script.

private void
drop(boolean script, boolean export, Writer fileOutput, Statement statement)

public void
execute(boolean script, boolean export, boolean justDrop, boolean justCreate)

private void
execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql)

public List<E>

Returns:

A List containig the Exceptions occured during the export
getExceptions
()

Returns a List of all Exceptions which occured during the export.

private void
importScript(SchemaExport.NamedReader importFileReader, Statement statement)

public static void
main(String[] args)

public SchemaExport

Returns:

this
setDelimiter
(String
The delimiter
delimiter
)

Set the end of statement delimiter

public SchemaExport

Returns:

this
setFormat
(boolean
Should we format SQL strings
format
)

Should we format the sql strings?

public SchemaExport

Returns:

this
setHaltOnError
(boolean
True if export should stop after error.
haltOnError
)

Should we stop once an error occurs?

public SchemaExport

Returns:

this
setImportFile
(String
The import file name.
filename
)

An import file, containing raw SQL statements to be executed.
public SchemaExport

Returns:

this
setOutputFile
(String
The name of the file to which to write the export script.
filename
)

For generating a export script file, this is the file which will be written.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionHelperback to summary
private ConnectionHelper connectionHelper
createSQLback to summary
private String[] createSQL
DEFAULT_IMPORT_FILEback to summary
private static final String DEFAULT_IMPORT_FILE
delimiterback to summary
private String delimiter
dialectback to summary
private Dialect dialect
dropSQLback to summary
private String[] dropSQL
exceptionsback to summary
private final List<E> exceptions
formatterback to summary
private Formatter formatter
haltOnErrorback to summary
private boolean haltOnError
importFilesback to summary
private String importFiles
logback to summary
private static final Logger log
outputFileback to summary
private String outputFile
sqlStatementLoggerback to summary
private SQLStatementLogger sqlStatementLogger

Constructor Detail

SchemaExportback to summary
public SchemaExport(Configuration cfg) throws HibernateException

Create a schema exporter for the given Configuration

Parameters
cfg:Configuration

The configuration from which to build a schema export.

Exceptions
HibernateException:
Indicates problem preparing for schema export.
SchemaExportback to summary
public SchemaExport(Configuration cfg, Settings settings) throws HibernateException

Create a schema exporter for the given Configuration and given settings

Parameters
cfg:Configuration

The configuration from which to build a schema export.

settings:Settings

The 'parsed' settings.

Exceptions
HibernateException:
Indicates problem preparing for schema export.
SchemaExportback to summary
public SchemaExport(Configuration cfg, Properties properties) throws HibernateException

Deprecated

properties may be specified via the Configuration object

Create a schema exporter for the given Configuration, with the given database connection properties.

Parameters
cfg:Configuration

The configuration from which to build a schema export.

properties:Properties

The properties from which to configure connectivity etc.

Exceptions
HibernateException:
Indicates problem preparing for schema export.
SchemaExportback to summary
public SchemaExport(Configuration cfg, Connection connection) throws HibernateException

Create a schema exporter for the given Configuration, using the supplied connection for connectivity.

Parameters
cfg:Configuration

The configuration to use.

connection:Connection

The JDBC connection to use.

Exceptions
HibernateException:
Indicates problem preparing for schema export.

Method Detail

createback to summary
public void create(boolean script, boolean export)

Run the schema creation script.

Parameters
script:boolean

print the DDL to the console

export:boolean

export the script to the database

createback to summary
private void create(boolean script, boolean export, Writer fileOutput, Statement statement) throws IOException
dropback to summary
public void drop(boolean script, boolean export)

Run the drop schema script.

Parameters
script:boolean

print the DDL to the console

export:boolean

export the script to the database

dropback to summary
private void drop(boolean script, boolean export, Writer fileOutput, Statement statement) throws IOException
executeback to summary
public void execute(boolean script, boolean export, boolean justDrop, boolean justCreate)
executeback to summary
private void execute(boolean script, boolean export, Writer fileOutput, Statement statement, final String sql) throws IOException, SQLException
getExceptionsback to summary
public List<E> getExceptions()

Returns a List of all Exceptions which occured during the export.

Returns:List<E>

A List containig the Exceptions occured during the export

importScriptback to summary
private void importScript(SchemaExport.NamedReader importFileReader, Statement statement) throws IOException
mainback to summary
public static void main(String[] args)
setDelimiterback to summary
public SchemaExport setDelimiter(String delimiter)

Set the end of statement delimiter

Parameters
delimiter:String

The delimiter

Returns:SchemaExport

this

setFormatback to summary
public SchemaExport setFormat(boolean format)

Should we format the sql strings?

Parameters
format:boolean

Should we format SQL strings

Returns:SchemaExport

this

setHaltOnErrorback to summary
public SchemaExport setHaltOnError(boolean haltOnError)

Should we stop once an error occurs?

Parameters
haltOnError:boolean

True if export should stop after error.

Returns:SchemaExport

this

setImportFileback to summary
public SchemaExport setImportFile(String filename)

An import file, containing raw SQL statements to be executed.

Parameters
filename:String

The import file name.

Returns:SchemaExport

this

setOutputFileback to summary
public SchemaExport setOutputFile(String filename)

For generating a export script file, this is the file which will be written.

Parameters
filename:String

The name of the file to which to write the export script.

Returns:SchemaExport

this

org.hibernate.tool.hbm2ddl back to summary

private Class SchemaExport.NamedReader

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final Reader

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
public Reader
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
private final String name
readerback to summary
private final Reader reader

Constructor Detail

NamedReaderback to summary
public NamedReader(String name, InputStream stream)

Method Detail

getNameback to summary
public String getName()
getReaderback to summary
public Reader getReader()