Class AbstractDatabase

java.lang.Object
org.pgcodekeeper.core.schema.PgStatement
org.pgcodekeeper.core.schema.AbstractDatabase
All Implemented Interfaces:
IHashable, IDatabase, IStatement, IStatementContainer
Direct Known Subclasses:
ChDatabase, MsDatabase, PgDatabase

public abstract class AbstractDatabase extends PgStatement implements IDatabase
Abstract base class representing a database schema. Contains schemas, handles database-specific operations, and manages object references and analysis launchers for PostgreSQL, Microsoft SQL, and ClickHouse databases.
  • Method Details

    • getOverrides

      public List<PgOverride> getOverrides()
      Gets the list of object overrides for this database.
      Returns:
      the list of overrides
    • getStatementType

      public final DbObjType getStatementType()
      Description copied from interface: IStatement
      Gets the type of this database object.
      Specified by:
      getStatementType in interface IStatement
      Returns:
      the database object type
    • getDatabase

      public AbstractDatabase getDatabase()
      Description copied from interface: IStatement
      Gets the database that contains this statement.
      Specified by:
      getDatabase in interface IStatement
      Returns:
      the containing database
    • getVersion

      public SupportedPgVersion getVersion()
    • setVersion

      public void setVersion(SupportedPgVersion version)
    • getObjReferences

      public Map<String,Set<PgObjLocation>> getObjReferences()
    • getObjReferences

      public Set<PgObjLocation> getObjReferences(String name)
    • addReference

      public void addReference(String fileName, PgObjLocation loc)
      Adds an object reference to the specified file.
      Parameters:
      fileName - the file name to associate with the location
      loc - the object location to add
    • getAnalysisLaunchers

      public List<AbstractAnalysisLauncher> getAnalysisLaunchers()
    • clearAnalysisLaunchers

      public void clearAnalysisLaunchers()
      Clears all analysis launchers and trims the internal list to size.
    • addAnalysisLauncher

      public void addAnalysisLauncher(AbstractAnalysisLauncher launcher)
      Add 'analysis launcher' for deferred analyze.
      Parameters:
      launcher - launcher that contains almost everything needed to analyze a statement contained in it
    • getSchemas

      public Collection<AbstractSchema> getSchemas()
      Getter for schemas. The list cannot be modified.
      Specified by:
      getSchemas in interface IDatabase
      Returns:
      schemas
    • addSchema

      public void addSchema(AbstractSchema schema)
      Adds a schema to this database.
      Parameters:
      schema - the schema to add
    • setDefaultSchema

      public void setDefaultSchema(String name)
    • getDefaultSchema

      public AbstractSchema getDefaultSchema()
    • containsSchema

      public boolean containsSchema(String name)
    • getSchema

      public AbstractSchema getSchema(String name)
      Returns schema of given name or null if the schema has not been found. If schema name is null then default schema is returned.
      Specified by:
      getSchema in interface IDatabase
      Parameters:
      name - schema name or null which means default schema
      Returns:
      found schema or null
    • getCreationSQL

      public void getCreationSQL(SQLScript script)
      Description copied from class: PgStatement
      Generates the SQL statements needed to create this database object. This is an abstract method that must be implemented by subclasses to provide the specific CREATE SQL for each object type.
      Specified by:
      getCreationSQL in class PgStatement
      Parameters:
      script - the SQL script to append creation statements to
    • appendAlterSQL

      public ObjectState appendAlterSQL(PgStatement newCondition, SQLScript script)
      Description copied from class: PgStatement
      Fill script with object changes and return change type
      Specified by:
      appendAlterSQL in class PgStatement
      Parameters:
      newCondition - new object state
      script - script to collect changes
      Returns:
      object change type
    • getDropSQL

      public void getDropSQL(SQLScript script, boolean optionExists)
      Description copied from class: PgStatement
      Generates DROP SQL for this statement.
      Overrides:
      getDropSQL in class PgStatement
      Parameters:
      script - the SQL script to append the DROP statement to
      optionExists - whether to include "IF EXISTS" in the DROP statement
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Parameters:
      hasher - the hasher instance to use for hash computation
    • computeChildrenHash

      public void computeChildrenHash(Hasher hasher)
    • addLib

      public void addLib(AbstractDatabase lib, String libName, String owner)
      Adds a library database to this database, merging its objects and analysis launchers.
      Parameters:
      lib - the library database to add
      libName - the name of the library
      owner - the owner to set for owned objects
    • listPgObjects

      public static Map<String,PgStatement> listPgObjects(AbstractDatabase db)
      Creates a map of all database objects with their qualified names as keys.
      Parameters:
      db - the database to list objects from
      Returns:
      a map of qualified names to statements
    • copyLaunchers

      public void copyLaunchers(AbstractDatabase db)
      Copies analysis launchers from another database to this one.
      Parameters:
      db - the database to copy launchers from
    • compare

      public boolean compare(PgStatement obj)
      Description copied from class: PgStatement
      This method does not account for nested child PgStatements. Shallow version of PgStatement.equals(Object)
      Overrides:
      compare in class PgStatement
    • compareChildren

      public boolean compareChildren(PgStatement obj)
      Description copied from class: PgStatement
      Deep part of PgStatement.equals(Object). Compares all object's child PgStatements for equality.
      Overrides:
      compareChildren in class PgStatement
    • shallowCopy

      public final AbstractDatabase shallowCopy()
      Description copied from class: PgStatement
      Copies all object properties into a new object and leaves all its children empty.
      Specified by:
      shallowCopy in class PgStatement
      Returns:
      shallow copy of a DB object.
    • getStatement

      public final PgStatement getStatement(GenericColumn gc)
      Resolves and returns a database statement based on the provided generic column specification.
      Parameters:
      gc - the generic column specification containing type and naming information
      Returns:
      the resolved statement, or null if not found