public final class Migration extends java.lang.Object implements JdbcWork<java.lang.Object>
exportAll(String, ProgressReporter)
method should work on
both MySQL and PostgreSQL (but is only tested regularly with MySQL).
The export generates data that is suitable for importing into
PostgreSQL using the COPY command. The importAll(String, ProgressReporter)
only works on a PostgreSQL database.Modifier and Type | Class and Description |
---|---|
(package private) class |
Migration.ProgressInputStream |
Modifier and Type | Field and Description |
---|---|
private boolean |
analyzeAfterImport |
private java.io.File |
directory |
private boolean |
dropConstraintsBeforeImport |
private boolean |
dropPrimaryKeyBeforeImport |
private boolean |
export |
private boolean |
exportCompressed |
private int |
fetchSize |
private java.text.DecimalFormat |
numRowsFormat |
private ProgressReporter |
progress |
private Session |
session |
Modifier | Constructor and Description |
---|---|
private |
Migration(boolean export,
java.io.File directory,
Session session,
ProgressReporter progress) |
Modifier and Type | Method and Description |
---|---|
private void |
doExport(java.sql.Connection connection)
Perform the export.
|
private void |
doImport(java.sql.Connection connection)
Perform the import.
|
void |
execute(java.sql.Connection connection) |
static void |
exportAll(java.lang.String path,
ProgressReporter progress)
Export the current BASE database to data files in the
directory on the given path.
|
private java.io.File |
getColumnsFile(TableInfo table)
Get the columns file for the given table.
|
private java.io.File |
getDataFile(TableInfo table)
Get the data file for the given table.
|
private java.io.File |
getDataFile(TableInfo table,
boolean compress)
Get the data file for the given table.
|
private java.io.InputStream |
getInputStream(java.io.File file)
Get a stream for reading from the given file.
|
private java.io.OutputStream |
getOutputStream(java.io.File file)
Get a stream for writing to the given file.
|
java.lang.Object |
getResult()
Get the result of the work.
|
static void |
importAll(java.lang.String path,
ProgressReporter progress)
Import data to a BASE database.
|
private java.lang.Integer |
importFromFile(TableInfo table,
java.io.File dataFile,
java.io.File columnsFile,
DbEngine engine,
java.sql.Statement st,
ProgressReporter progress)
Import data to the given table.
|
private java.lang.String |
numRows(long numRows) |
void |
setAnalyzeAfterImport(boolean analyze)
Should we execute an analyis command after the import has
been completed.
|
void |
setDropConstraintsBeforeImport(boolean drop)
Should we drop the unique constraints and indexes before importing
data?
|
void |
setDropPrimaryKeyBeforeImport(boolean drop)
Should we drop the primary key before importing data?
|
void |
setExportCompressed(boolean compress)
Should the exporter compress the data files or leave them
as is?
|
void |
setFetchSize(int fetchSize)
Set the JDBC fetch size to use when fetching rows from the database.
|
private final boolean export
private final java.io.File directory
private final Session session
private final ProgressReporter progress
private final java.text.DecimalFormat numRowsFormat
private boolean exportCompressed
private int fetchSize
private boolean dropPrimaryKeyBeforeImport
private boolean dropConstraintsBeforeImport
private boolean analyzeAfterImport
private Migration(boolean export, java.io.File directory, Session session, ProgressReporter progress)
public static void exportAll(java.lang.String path, ProgressReporter progress) throws java.sql.SQLException, java.io.IOException
path
- A path to an existing directoryprogress
- A progress reporterjava.sql.SQLException
java.io.IOException
public static void importAll(java.lang.String path, ProgressReporter progress) throws java.sql.SQLException, java.io.IOException
path
- The path to the directory with data filesprogress
- A progress reporterjava.sql.SQLException
java.io.IOException
public java.lang.Object getResult()
JdbcWork
public void execute(java.sql.Connection connection) throws java.sql.SQLException
public void setDropPrimaryKeyBeforeImport(boolean drop)
drop
- TRUE to drop (default), FALSE to leave itpublic void setDropConstraintsBeforeImport(boolean drop)
drop
- TRUE to drop (default), FALSE to leave itpublic void setAnalyzeAfterImport(boolean analyze)
DbEngine.analyzeAfterBatchOperation()
reports.analyze
- TRUE to analyze, FALSE to notpublic void setExportCompressed(boolean compress)
compress
- TRUE to compress the files, FALSE to not compress (default)public void setFetchSize(int fetchSize)
fetchSize
- The fetch size to useStatement.setFetchSize(int)
private void doExport(java.sql.Connection connection) throws java.sql.SQLException, java.io.IOException
java.sql.SQLException
java.io.IOException
private void doImport(java.sql.Connection connection) throws java.sql.SQLException, java.io.IOException
java.sql.SQLException
java.io.IOException
private java.lang.String numRows(long numRows)
private java.io.File getDataFile(TableInfo table)
private java.io.File getDataFile(TableInfo table, boolean compress)
private java.io.File getColumnsFile(TableInfo table)
private java.io.OutputStream getOutputStream(java.io.File file) throws java.io.IOException
java.io.IOException
private java.io.InputStream getInputStream(java.io.File file) throws java.io.IOException
java.io.IOException
private java.lang.Integer importFromFile(TableInfo table, java.io.File dataFile, java.io.File columnsFile, DbEngine engine, java.sql.Statement st, ProgressReporter progress) throws java.sql.SQLException, java.io.IOException
java.sql.SQLException
java.io.IOException