Class LocalEntityGraph

java.lang.Object
net.sf.jailer.entitygraph.EntityGraph
net.sf.jailer.entitygraph.local.LocalEntityGraph

public class LocalEntityGraph extends EntityGraph
Persistent graph of entities. Persists the graph in a local database.
Author:
Ralf Wisser
  • Method Details

    • close

      public void close() throws SQLException
      Closes the graph. Deletes the local database.
      Specified by:
      close in class EntityGraph
      Throws:
      SQLException
    • setBirthdayOfSubject

      public void setBirthdayOfSubject(int birthdayOfSubject)
      Sets birthday of subject rows.
      Specified by:
      setBirthdayOfSubject in class EntityGraph
      Parameters:
      birthdayOfSubject - birthday of subject rows
    • create

      public static LocalEntityGraph create(DataModel dataModel, int graphID, Session remoteSession, ExecutionContext executionContext) throws IOException, SQLException
      Creates a new entity-graph.
      Parameters:
      graphID - the unique ID of the graph
      remoteSession - for executing SQL-Statements
      Returns:
      the newly created entity-graph
      Throws:
      IOException
      SQLException
    • copy

      public EntityGraph copy(int newGraphID, Session _unused) throws SQLException
      Copies an entity-graph.
      Specified by:
      copy in class EntityGraph
      Parameters:
      newGraphID - the unique ID of the new graph
      _unused - not used (the local session is reused from this graph)
      Returns:
      the newly created entity-graph
      Throws:
      SQLException
    • createNewGraph

      public EntityGraph createNewGraph() throws SQLException
      Creates a new entity-graph of same type and session.
      Specified by:
      createNewGraph in class EntityGraph
      Returns:
      the newly created entity-graph
      Throws:
      SQLException
    • getAge

      public int getAge() throws SQLException
      Gets the age of the graph.
      Specified by:
      getAge in class EntityGraph
      Returns:
      the age of the graph
      Throws:
      SQLException
    • setAge

      public void setAge(int age) throws SQLException
      Sets the age of the graph.
      Specified by:
      setAge in class EntityGraph
      Parameters:
      age - the age of the graph
      Throws:
      SQLException
    • getSize

      public long getSize() throws SQLException
      Gets the number of entities in the graph.
      Specified by:
      getSize in class EntityGraph
      Returns:
      the number of entities in the graph
      Throws:
      SQLException
    • delete

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

      public long addEntities(Table table, String condition, int today) throws SQLException
      Adds entities to the graph.
      Specified by:
      addEntities in class EntityGraph
      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 long addEntities(Table table, String condition, int today, SubjectLimitDefinition limitDefinition, boolean joinWithEntity) throws SQLException
      Adds limited number of entities to the graph.
      Specified by:
      addEntities in class EntityGraph
      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 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.
      Specified by:
      resolveAssociation in class EntityGraph
      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 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.
      Specified by:
      resolveAssociation in class EntityGraph
      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 void addDependencies(Table from, String fromAlias, Table to, String toAlias, String condition, int aggregationId, int dependencyId, boolean isAssociationReversed) throws SQLException
      Adds dependencies.
      Specified by:
      addDependencies in class EntityGraph
      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 Set<Integer> getDistinctDependencyIDs() throws SQLException
      Gets distinct association-ids of all edges.
      Specified by:
      getDistinctDependencyIDs in class EntityGraph
      Returns:
      set of distinct dependency IDs
      Throws:
      SQLException
    • markIndependentEntities

      public 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.
      Specified by:
      markIndependentEntities in class EntityGraph
      Parameters:
      table - the table
      Throws:
      SQLException
    • markRoots

      public void markRoots(Table table) throws SQLException
      Marks all rows which are not target of a dependency.
      Specified by:
      markRoots in class EntityGraph
      Parameters:
      table - the table
      Throws:
      SQLException
    • readMarkedEntities

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

      public 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.
      Specified by:
      readMarkedEntities in class EntityGraph
      Parameters:
      table - the table
      reader - for reading the result-set
      orderByPK - if true, result will be ordered by primary keys
      Throws:
      SQLException
    • readEntities

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

      public 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.
      Specified by:
      readUnfilteredEntityColumns in class EntityGraph
      Parameters:
      table - the table
      columns - the columns
      reader - to read
      Returns:
      number of rows read
      Throws:
      SQLException
    • updateEntities

      public void updateEntities(Table table, Set<Column> columns, OutputStreamWriter scriptFileWriter, DBMS targetConfiguration, boolean inSourceSchema, String reason) throws SQLException
      Updates columns of a table.
      Specified by:
      updateEntities in class EntityGraph
      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
    • deleteIndependentEntities

      public void deleteIndependentEntities(Table table) throws SQLException
      Deletes all entities which are marked as independent.
      Specified by:
      deleteIndependentEntities in class EntityGraph
      Parameters:
      table - the table
      Throws:
      SQLException
    • deleteEntities

      public long deleteEntities(Table table) throws SQLException
      Deletes all entities from a given table.
      Specified by:
      deleteEntities in class EntityGraph
      Parameters:
      table - the table
      Returns:
      number of deleted entities
      Throws:
      SQLException
    • countEntities

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

      public 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.
      Specified by:
      removeAssociatedDestinations in class EntityGraph
      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 void readDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Session.ResultSetReader reader, Map<String,Integer> theTypeCache, String selectionSchema, String originalPKAliasPrefix) throws SQLException
      Reads all entities which depend on a given entity.
      Specified by:
      readDependentEntities in class EntityGraph
      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
      theTypeCache - cache for column type lookups
      selectionSchema - the selection schema
      originalPKAliasPrefix - prefix for original primary key aliases
      Throws:
      SQLException
    • markDependentEntitiesAsTraversed

      public 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.
      Specified by:
      markDependentEntitiesAsTraversed in class EntityGraph
      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 void readNonTraversedDependencies(Table table, Session.ResultSetReader reader) throws SQLException
      Reads all non-traversed dependencies.
      Specified by:
      readNonTraversedDependencies in class EntityGraph
      Parameters:
      table - the source of dependencies to look for
      reader - reads the entities
      Throws:
      SQLException
    • removeReflexiveDependencies

      public void removeReflexiveDependencies(Table table) throws SQLException
      Removes all reflexive dependencies of given table.
      Specified by:
      removeReflexiveDependencies in class EntityGraph
      Parameters:
      table - the table
      Throws:
      SQLException
    • getTotalRowcount

      public long getTotalRowcount()
      Gets total row-count.
      Specified by:
      getTotalRowcount in class EntityGraph
      Returns:
      total row-count
    • getUniversalPrimaryKey

      public PrimaryKey getUniversalPrimaryKey()
      Gets the universal primary key.
      Specified by:
      getUniversalPrimaryKey in class EntityGraph
      Returns:
      the universal primary key
    • shutDown

      public void shutDown() throws SQLException
      Shuts down statement-executor.
      Specified by:
      shutDown in class EntityGraph
      Throws:
      SQLException
    • getSession

      public Session getSession()
      Gets the session.
      Specified by:
      getSession in class EntityGraph
      Returns:
      the local session
    • getDatamodel

      public DataModel getDatamodel()
      Gets the data model.
      Specified by:
      getDatamodel in class EntityGraph
      Returns:
      the data model
    • getTargetSession

      public Session getTargetSession()
      Gets the target session.
      Specified by:
      getTargetSession in class EntityGraph
      Returns:
      the remote session