|
3.1.2: 2012-07-31 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.basedb.core.Migration
public final class Migration
Class for migrating a database to PostgreSQL.
The 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.
Nested Class Summary | |
---|---|
(package private) class |
Migration.ProgressInputStream
|
Field Summary | |
---|---|
private boolean |
analyzeAfterImport
|
private File |
directory
|
private boolean |
dropConstraintsBeforeImport
|
private boolean |
dropPrimaryKeyBeforeImport
|
private boolean |
export
|
private boolean |
exportCompressed
|
private int |
fetchSize
|
private DecimalFormat |
numRowsFormat
|
private ProgressReporter |
progress
|
private Session |
session
|
Constructor Summary | |
---|---|
private |
Migration(boolean export,
File directory,
Session session,
ProgressReporter progress)
|
Method Summary | |
---|---|
private void |
doExport(Connection connection)
Perform the export. |
private void |
doImport(Connection connection)
Perform the import. |
void |
execute(Connection connection)
|
static void |
exportAll(String path,
ProgressReporter progress)
Export the current BASE database to data files in the directory on the given path. |
private File |
getColumnsFile(TableInfo table)
Get the columns file for the given table. |
private File |
getDataFile(TableInfo table)
Get the data file for the given table. |
private File |
getDataFile(TableInfo table,
boolean compress)
Get the data file for the given table. |
private InputStream |
getInputStream(File file)
Get a stream for reading from the given file. |
private OutputStream |
getOutputStream(File file)
Get a stream for writing to the given file. |
Object |
getResult()
Get the result of the work. |
static void |
importAll(String path,
ProgressReporter progress)
Import data to a BASE database. |
private Integer |
importFromFile(TableInfo table,
File dataFile,
File columnsFile,
DbEngine engine,
Statement st,
ProgressReporter progress)
Import data to the given table. |
private 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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final boolean export
private final File directory
private final Session session
private final ProgressReporter progress
private final DecimalFormat numRowsFormat
private boolean exportCompressed
private int fetchSize
private boolean dropPrimaryKeyBeforeImport
private boolean dropConstraintsBeforeImport
private boolean analyzeAfterImport
Constructor Detail |
---|
private Migration(boolean export, File directory, Session session, ProgressReporter progress)
Method Detail |
---|
public static void exportAll(String path, ProgressReporter progress) throws SQLException, IOException
path
- A path to an existing directoryprogress
- A progress reporter
SQLException
IOException
public static void importAll(String path, ProgressReporter progress) throws SQLException, IOException
path
- The path to the directory with data filesprogress
- A progress reporter
SQLException
IOException
public Object getResult()
JdbcWork
getResult
in interface JdbcWork<Object>
public void execute(Connection connection) throws SQLException
execute
in interface Work
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(Connection connection) throws SQLException, IOException
SQLException
IOException
private void doImport(Connection connection) throws SQLException, IOException
SQLException
IOException
private String numRows(long numRows)
private File getDataFile(TableInfo table)
private File getDataFile(TableInfo table, boolean compress)
private File getColumnsFile(TableInfo table)
private OutputStream getOutputStream(File file) throws IOException
IOException
private InputStream getInputStream(File file) throws IOException
IOException
private Integer importFromFile(TableInfo table, File dataFile, File columnsFile, DbEngine engine, Statement st, ProgressReporter progress) throws SQLException, IOException
SQLException
IOException
|
3.1.2: 2012-07-31 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |