Class EntityGraph

java.lang.Object
net.sf.jailer.entitygraph.EntityGraph
Direct Known Subclasses:
LocalEntityGraph, RemoteEntityGraph

public abstract class EntityGraph extends Object
Persistent graph of entities.
Author:
Ralf Wisser
  • Field Details

  • Constructor Details

  • Method Details

    • setBirthdayOfSubject

      public abstract void setBirthdayOfSubject(int birthdayOfSubject)
      Sets birthday of subject rows.
      Parameters:
      birthdayOfSubject - birthday of subject rows
    • copy

      public abstract EntityGraph copy(int graphID, Session session) throws SQLException
      Copies an entity-graph.
      Parameters:
      graphID - the unique ID of the graph
      session - for executing SQL-Statements
      Returns:
      the newly created entity-graph
      Throws:
      SQLException
    • createNewGraph

      public abstract EntityGraph createNewGraph() throws SQLException
      Creates a new entity-graph of same type and session.
      Returns:
      the newly created entity-graph
      Throws:
      SQLException
    • copy

      public EntityGraph copy(Set<Table> tables) throws SQLException
      Copies some tables.
      Parameters:
      tables - tables to copy
      Throws:
      SQLException
    • getAge

      public abstract int getAge() throws SQLException
      Gets the age of the graph.
      Returns:
      the age of the graph
      Throws:
      SQLException
    • setAge

      public abstract void setAge(int age) throws SQLException
      Sets the age of the graph.
      Parameters:
      age - the age of the graph
      Throws:
      SQLException
    • getSize

      public abstract long getSize() throws SQLException
      Gets the number of entities in the graph.
      Returns:
      the number of entities in the graph
      Throws:
      SQLException
    • getSize

      public long getSize(Set<Table> tables) throws SQLException
      Gets the number of entities from given tables in the graph.
      Parameters:
      tables - the tables to count entities for
      Returns:
      the number of entities from the given tables in the graph
      Throws:
      SQLException - if a database access error occurs
    • delete

      public final void delete() throws SQLException
      Deletes the graph.
      Throws:
      SQLException
    • delete

      public abstract void delete(boolean forced)
      Deletes the graph.
      Parameters:
      forced - if true, force deletion and don't allow optimization
    • addEntities

      public abstract long addEntities(Table table, String condition, int today) throws SQLException
      Adds entities to the graph.
      Parameters:
      table - the table
      condition - the condition in SQL that the entities must fulfill
      today - the birthday of the new entities
      Returns:
      row-count
      Throws:
      SQLException
    • addEntities

      public abstract long addEntities(Table table, String condition, int today, SubjectLimitDefinition limitDefinition, boolean joinWithEntity) throws SQLException
      Adds limited number of entities to the graph.
      Parameters:
      table - the table
      condition - the condition in SQL that the entities must fulfill
      today - the birthday of the new entities
      limitDefinition - limit
      joinWithEntity - if true, join with the entity-table to avoid duplicates
      Returns:
      row-count
      Throws:
      SQLException
    • resolveAssociation

      public abstract long resolveAssociation(Table table, Association association, int today) throws SQLException
      Resolves an association. Retrieves and adds all entities associated with an entity born yesterday in the graph and adds the dependencies.
      Parameters:
      table - the table
      association - the association to resolve
      today - the birthday of the new entities
      Returns:
      row-count or -1, if association is ignored
      Throws:
      SQLException
    • resolveAssociation

      public abstract long resolveAssociation(Table table, Association association, EntityGraph otherGraph, EntityGraph universum, boolean forDelete) throws SQLException
      Resolves an association. Retrieves and adds all entities associated with an entity into a given entity-graph. Restrictions are ignored.
      Parameters:
      table - the table
      association - the association to resolve
      otherGraph - the target entity-graph to add resolved entities into
      universum - the universe entity-graph used to filter candidates
      forDelete - if true, resolves for deletion rather than export
      Returns:
      row-count
      Throws:
      SQLException
    • addDependencies

      public abstract void addDependencies(Table from, String fromAlias, Table to, String toAlias, String condition, int aggregationId, int dependencyId, boolean isAssociationReversed) throws SQLException
      Adds dependencies.
      Parameters:
      from - source of dependency
      fromAlias - alias for from-table
      to - destination of dependency
      toAlias - alias for to-table
      condition - condition of dependency
      aggregationId - id of aggregation association (for XML export), 0 if not applicable
      dependencyId - id of dependency
      isAssociationReversed - if true, the association is used in reverse direction
      Throws:
      SQLException
    • getDistinctDependencyIDs

      public abstract Set<Integer> getDistinctDependencyIDs() throws SQLException
      Gets distinct association-ids of all edges.
      Returns:
      set of distinct dependency IDs
      Throws:
      SQLException
    • markIndependentEntities

      public abstract void markIndependentEntities(Table table) throws SQLException
      Marks all entities of a given table which don't dependent on other entities, s.t. they can be read and deleted.
      Throws:
      SQLException
    • markRoots

      public abstract void markRoots(Table table) throws SQLException
      Marks all rows which are not target of a dependency.
      Throws:
      SQLException
    • readMarkedEntities

      public abstract void readMarkedEntities(Table table, boolean orderByPK) throws SQLException
      Reads all entities of a given table which are marked as independent or as roots.
      Parameters:
      table - the table
      orderByPK - if true, result will be ordered by primary keys
      Throws:
      SQLException
    • readMarkedEntities

      public abstract void readMarkedEntities(Table table, Session.ResultSetReader reader, String selectionSchema, String originalPKAliasPrefix, boolean orderByPK) throws SQLException
      Reads all entities of a given table which are marked as independent or as roots.
      Parameters:
      table - the table
      reader - for reading the result-set
      orderByPK - if true, result will be ordered by primary keys
      Throws:
      SQLException
    • readEntities

      public abstract void readEntities(Table table, boolean orderByPK) throws SQLException
      Reads all entities of a given table.
      Parameters:
      table - the table
      orderByPK - if true, result will be ordered by primary keys
      Throws:
      SQLException
    • updateEntities

      public abstract void updateEntities(Table table, Set<Column> columns, OutputStreamWriter scriptFileWriter, DBMS targetConfiguration, boolean inSourceSchema, String reason) throws SQLException
      Updates columns of a table.
      Parameters:
      table - the table
      columns - the columns
      scriptFileWriter - writer for the SQL script output
      targetConfiguration - the target DBMS configuration
      inSourceSchema - if true, use source-schema-mapping, else use schema-mapping
      reason - to be written as comment
      Throws:
      SQLException
    • readUnfilteredEntityColumns

      public abstract long readUnfilteredEntityColumns(Table table, List<Column> columns, Session.ResultSetReader reader) throws SQLException
      Reads some columns of all entities of a given table without using filters.
      Parameters:
      table - the table
      columns - the columns
      reader - to read
      Throws:
      SQLException
    • deleteIndependentEntities

      public abstract void deleteIndependentEntities(Table table) throws SQLException
      Deletes all entities which are marked as independent.
      Throws:
      SQLException
    • deleteEntities

      public abstract long deleteEntities(Table table) throws SQLException
      Deletes all entities from a given table.
      Throws:
      SQLException
    • countEntities

      public abstract long countEntities(Table table) throws SQLException
      Counts the entities of a given table in this graph.
      Parameters:
      table - the table
      Returns:
      the number of entities from table in this graph
      Throws:
      SQLException
    • removeAssociatedDestinations

      public abstract long removeAssociatedDestinations(Association association, boolean deletedEntitiesAreMarked, Set<Table> allTables) throws SQLException
      Removes all entities from this graph which are associated with an entity outside the graph.
      Parameters:
      association - the association
      deletedEntitiesAreMarked - if true, consider entity as deleted if its birthday is negative
      allTables - set of tables from which there are entities in E
      Returns:
      number of removed entities
      Throws:
      SQLException
    • readDependentEntities

      public abstract void readDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Session.ResultSetReader reader, Map<String,Integer> typeCache, String selectionSchema, String originalPKAliasPrefix) throws SQLException
      Reads all entities which depend on a given entity.
      Parameters:
      table - the table from which to read entities
      association - the dependency
      resultSet - current row is the given entity
      resultSetMetaData - meta data of the result set
      reader - reads the entities
      typeCache - cache for column type lookups
      selectionSchema - the selection schema
      originalPKAliasPrefix - prefix for original primary key aliases
      Throws:
      SQLException
    • markDependentEntitiesAsTraversed

      public abstract void markDependentEntitiesAsTraversed(Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Map<String,Integer> typeCache) throws SQLException
      Marks all entities which depend on a given entity as traversed.
      Parameters:
      association - the dependency
      resultSet - current row is the given entity
      resultSetMetaData - meta data of the result set
      typeCache - cache for column type lookups
      Throws:
      SQLException
    • readNonTraversedDependencies

      public abstract void readNonTraversedDependencies(Table table, Session.ResultSetReader reader) throws SQLException
      Reads all non-traversed dependencies.
      Parameters:
      table - the source of dependencies to look for
      reader - reads the entities
      Throws:
      SQLException
    • removeReflexiveDependencies

      public abstract void removeReflexiveDependencies(Table table) throws SQLException
      Removes all reflexive dependencies of given table.
      Parameters:
      table - the table
      Throws:
      SQLException
    • getTotalRowcount

      public abstract long getTotalRowcount()
      Gets total row-count.
      Returns:
      total row-count
    • getUniversalPrimaryKey

      public abstract PrimaryKey getUniversalPrimaryKey()
      Gets the universal primary key.
      Returns:
      the universal primary key
    • shutDown

      public abstract void shutDown() throws SQLException
      Shuts down statement-executor.
      Throws:
      SQLException
    • getSession

      public abstract Session getSession()
      Gets the session.
      Returns:
      the session
    • createUniqueGraphID

      public static int createUniqueGraphID()
      Creates a unique ID for a new graph.
      Returns:
      a unique ID
    • incLobCount

      public int incLobCount()
      Increments lob-counter and returns new value.
      Returns:
      the incremented lob-counter value
    • getDatamodel

      public abstract DataModel getDatamodel()
      Gets the data model.
      Returns:
      the data model
    • close

      public abstract void close() throws SQLException
      Closes the graph. Deletes the local database.
      Throws:
      SQLException
    • removeDependencies

      public void removeDependencies(Association association) throws SQLException
      Removes all dependencies for a given association.
      Parameters:
      association - the association
      Throws:
      SQLException
    • getTargetSession

      public abstract Session getTargetSession()
      Gets the target session.
      Returns:
      the target session
    • setDeleteMode

      public void setDeleteMode(boolean deleteMode)
      Sets the delete mode.
      Parameters:
      deleteMode - if true, the graph operates in delete mode
    • typeName

      protected int typeName(Table table)
    • setTransformerFactory

      public void setTransformerFactory(TransformerFactory transformerFactory)
      Parameters:
      transformerFactory - the factory
    • getTransformerFactory

      public TransformerFactory getTransformerFactory()
      Returns:
      the factory
    • setImportFilterManager

      public void setImportFilterManager(ImportFilterManager importFilterManager)
      Parameters:
      importFilterManager - the ImportFilterManager
    • getImportFilterManager

      public ImportFilterManager getImportFilterManager()
      Returns:
      the ImportFilterManager
    • fillAndWriteMappingTables

      public void fillAndWriteMappingTables(JobManager jobManager, OutputStreamWriter dmlResultWriter, int numberOfEntities, Session targetSession, DBMS targetDBMSConfiguration, DBMS dbmsConfiguration) throws SQLException, IOException
      Inserts the values of columns with non-derived import-filters into the local database.
      Parameters:
      jobManager - the job manager used to execute jobs in parallel
      dmlResultWriter - writer for the DML result output
      numberOfEntities - the number of entities to process
      targetSession - the session for the target database
      targetDBMSConfiguration - the target DBMS configuration
      dbmsConfiguration - the source DBMS configuration
      Throws:
      SQLException
      IOException
    • dropMappingTables

      public void dropMappingTables(OutputStreamWriter result, DBMS targetDBMSConfiguration) throws IOException, SQLException
      Creates the DROP-statements for the mapping tables.
      Parameters:
      result - writer for the DROP-statement output
      targetDBMSConfiguration - the target DBMS configuration
      Throws:
      IOException
      SQLException
    • dmlTableReference

      protected String dmlTableReference(String tableName, Session session) throws SQLException
      Gets table reference for DML statements for a given working table.
      Parameters:
      tableName - the working table
      session - holds connection to DBMS
      Returns:
      table reference for the working table
      Throws:
      SQLException
    • deleteRows

      protected long deleteRows(Session session, String table, String where) throws SQLException
      Deletes rows from table. Applies DBMS-specific deletion strategies, if available.
      Parameters:
      session - the session
      table - the table
      where - the "where" condition
      Returns:
      row count
      Throws:
      SQLException
    • truncate

      public void truncate(ExecutionContext executionContext, boolean checkExist) throws SQLException
      Tries to delete this graph using "truncate".
      Parameters:
      executionContext - the execution context
      checkExist - if true, checks existence of each graph
      Throws:
      SQLException
    • checkExist

      public void checkExist(ExecutionContext executionContext) throws SQLException
      Checks if the graph still exists.
      Parameters:
      executionContext - the execution context
      Throws:
      RuntimeException - if the graph no longer exists
      SQLException
    • addExportedCount

      protected void addExportedCount(long count)
    • getExportedCount

      public long getExportedCount()
      Gets the total number of exported rows.
      Returns:
      the total number of exported rows
    • getSelectionClause

      protected List<Column> getSelectionClause(Table table)
      Gets all non-virtual columns of the table in the order in which they are selected.
      Parameters:
      table - the table
      Returns:
      all non-virtual columns of the table in the order in which they are selected
      Throws:
      RuntimeException - if the selection clause is empty