Class ModelExporter

java.lang.Object
org.pgcodekeeper.core.model.exporter.ModelExporter
Direct Known Subclasses:
OverridesModelExporter

public class ModelExporter extends Object
Exports database model as directory tree with SQL files containing object definitions. Supports full, partial, and project exports with configurable encoding and database type support.

For historical reasons we expect a filtered user-selection-only list in exportPartial() but we use the new API TreeElement.isSelected() for selection checks instead of calling Collection.contains(Object) for performance reasons.

Author:
Alexander Levsha
  • Field Details

  • Constructor Details

    • ModelExporter

      public ModelExporter(Path outDir, AbstractDatabase db, DatabaseType databaseType, String sqlEncoding, ISettings settings)
      Creates a new ModelExporter for full database export.
      Parameters:
      outDir - output directory, should be empty or not exist
      db - database to export
      databaseType - database type for directory structure
      sqlEncoding - SQL file encoding
      settings - export settings
    • ModelExporter

      public ModelExporter(Path outDir, AbstractDatabase newDb, AbstractDatabase oldDb, DatabaseType databaseType, Collection<TreeElement> changedObjects, String sqlEncoding, ISettings settings)
      Creates a new ModelExporter for partial or project export.
      Parameters:
      outDir - output directory
      newDb - new database schema
      oldDb - old database schema, can be null for project export
      databaseType - database type for directory structure
      changedObjects - collection of changed objects
      sqlEncoding - SQL file encoding
      settings - export settings
  • Method Details

    • exportFull

      public void exportFull() throws IOException
      Exports the complete database schema to directory structure. Creates output directory and exports all database objects as SQL files.
      Throws:
      IOException - if export operation fails
    • exportPartial

      public void exportPartial() throws IOException, PgCodekeeperException
      Exports only changed objects based on comparison between old and new schemas. Handles object additions, deletions, and modifications.
      Throws:
      IOException - if export operation fails
      PgCodekeeperException - if old database is null or directory issues occur
    • exportProject

      public void exportProject() throws IOException
      Exports selected objects as a new project structure. Creates clean directory structure with only specified objects.
      Throws:
      IOException - if export operation fails
    • getExportedFilename

      public static String getExportedFilename(PgStatement statement)
      Gets the exported filename for a database statement.
      Parameters:
      statement - the database statement
      Returns:
      sanitized filename suitable for file system
    • getExportedFilenameSql

      public static String getExportedFilenameSql(String name)
      Gets the SQL filename with .sql extension.
      Parameters:
      name - the base name
      Returns:
      filename with .sql extension
    • writeProjVersion

      public static void writeProjVersion(Path path) throws IOException
      Writes project version marker file.
      Parameters:
      path - the path to write version file
      Throws:
      IOException - if writing fails
    • getRelativeFilePath

      public static Path getRelativeFilePath(PgStatement st)
      Gets the relative file path for a database statement within project structure.
      Parameters:
      st - the database statement
      Returns:
      relative path for the statement's file