Class Migration

  • All Implemented Interfaces:
    Work

    public final class Migration
    extends Object
    implements Work
    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.
    Since:
    3.1
    Author:
    Nicklas
    Last modified
    $Date: 2019-05-21 13:37:09 +0200 (tis, 21 maj 2019) $
    • Field Detail

      • export

        private final boolean export
      • directory

        private final File directory
      • session

        private final Session session
      • exportCompressed

        private boolean exportCompressed
      • fetchSize

        private int fetchSize
      • dropPrimaryKeyBeforeImport

        private boolean dropPrimaryKeyBeforeImport
      • dropConstraintsBeforeImport

        private boolean dropConstraintsBeforeImport
      • analyzeAfterImport

        private boolean analyzeAfterImport
    • Method Detail

      • setDropPrimaryKeyBeforeImport

        public void setDropPrimaryKeyBeforeImport​(boolean drop)
        Should we drop the primary key before importing data? This can speed up the import. The primary key will be re-created after the import is complete.
        Parameters:
        drop - TRUE to drop (default), FALSE to leave it
      • setDropConstraintsBeforeImport

        public void setDropConstraintsBeforeImport​(boolean drop)
        Should we drop the unique constraints and indexes before importing data? This can speed up the import. The constraints will be re-created after the import is complete.
        Parameters:
        drop - TRUE to drop (default), FALSE to leave it
      • setAnalyzeAfterImport

        public void setAnalyzeAfterImport​(boolean analyze)
        Should we execute an analyis command after the import has been completed. This may result in improved performance when re-creating indexes and foreign keys. The default is whatever the current DbEngine.analyzeAfterBatchOperation() reports.
        Parameters:
        analyze - TRUE to analyze, FALSE to not
      • setExportCompressed

        public void setExportCompressed​(boolean compress)
        Should the exporter compress the data files or leave them as is? Compressing can considerably reduce the disk space needed for migration. The import will automatically detect if the files are compressed or not.
        Parameters:
        compress - TRUE to compress the files, FALSE to not compress (default)
      • setFetchSize

        public void setFetchSize​(int fetchSize)
        Set the JDBC fetch size to use when fetching rows from the database. A higher value may improve performance but uses more memory. The default value is 20000.
        Parameters:
        fetchSize - The fetch size to use
        See Also:
        Statement.setFetchSize(int)
      • doExport

        private void doExport​(Connection connection)
                       throws SQLException,
                              IOException
        Perform the export. In principle we support all databases that BASE supports, but it may depend on the actual underlying SQL column types. The export generates files that can be imported into PostgreSQL only.
        Throws:
        SQLException
        IOException
      • numRows

        private String numRows​(long numRows)
      • getDataFile

        private File getDataFile​(TableInfo table)
        Get the data file for the given table. Automatically detect if a compressed file is present or not.
      • getDataFile

        private File getDataFile​(TableInfo table,
                                 boolean compress)
        Get the data file for the given table.
      • getColumnsFile

        private File getColumnsFile​(TableInfo table)
        Get the columns file for the given table.
      • getOutputStream

        private OutputStream getOutputStream​(File file)
                                      throws IOException
        Get a stream for writing to the given file. If the file name ends with .gz it is automatically wrapped with a GZIPOutputStream.
        Throws:
        IOException
      • getInputStream

        private InputStream getInputStream​(File file)
                                    throws IOException
        Get a stream for reading from the given file. If the file name ends with .gz it is automatically wrapped with a GZIPInputStream.
        Throws:
        IOException