Class EntityGraph
java.lang.Object
net.sf.jailer.entitygraph.EntityGraph
- Direct Known Subclasses:
LocalEntityGraph,RemoteEntityGraph
Persistent graph of entities.
- Author:
- Ralf Wisser
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal DataModelstatic final StringName of the dependency-table.static final StringName of the entity-table.static final StringName of the graph-table.static final StringName of the (helper) set-table.protected final ExecutionContextThe execution context.final intThe unique ID of the graph.protected ImportFilterManagerTheImportFilterManager.protected booleanprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEntityGraph(int graphID, DataModel dataModel, ExecutionContext executionContext) -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddDependencies(Table from, String fromAlias, Table to, String toAlias, String condition, int aggregationId, int dependencyId, boolean isAssociationReversed) Adds dependencies.abstract longaddEntities(Table table, String condition, int today) Adds entities to the graph.abstract longaddEntities(Table table, String condition, int today, SubjectLimitDefinition limitDefinition, boolean joinWithEntity) Adds limited number of entities to the graph.protected voidaddExportedCount(long count) voidcheckExist(ExecutionContext executionContext) Checks if the graph still exists.abstract voidclose()Closes the graph.abstract EntityGraphCopies an entity-graph.Copies some tables.abstract longcountEntities(Table table) Counts the entities of a given table in this graph.abstract EntityGraphCreates a new entity-graph of same type and session.static intCreates a unique ID for a new graph.final voiddelete()Deletes the graph.abstract voiddelete(boolean forced) Deletes the graph.abstract longdeleteEntities(Table table) Deletes all entities from a given table.abstract voiddeleteIndependentEntities(Table table) Deletes all entities which are marked as independent.protected longdeleteRows(Session session, String table, String where) Deletes rows from table.protected StringdmlTableReference(String tableName, Session session) Gets table reference for DML statements for a given working table.voiddropMappingTables(OutputStreamWriter result, DBMS targetDBMSConfiguration) Creates the DROP-statements for the mapping tables.voidfillAndWriteMappingTables(JobManager jobManager, OutputStreamWriter dmlResultWriter, int numberOfEntities, Session targetSession, DBMS targetDBMSConfiguration, DBMS dbmsConfiguration) Inserts the values of columns with non-derived import-filters into the local database.abstract intgetAge()Gets the age of the graph.abstract DataModelGets the data model.Gets distinct association-ids of all edges.longGets the total number of exported rows.Gets theImportFilterManagergetSelectionClause(Table table) Gets all non-virtual columns of the table in the order in which they are selected.abstract SessionGets the session.abstract longgetSize()Gets the number of entities in the graph.longGets the number of entities from given tables in the graph.abstract SessionGets the target session.abstract longGets total row-count.Gets theTransformerFactory.abstract PrimaryKeyGets the universal primary key.intIncrements lob-counter and returns new value.abstract voidmarkDependentEntitiesAsTraversed(Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Map<String, Integer> typeCache) Marks all entities which depend on a given entity as traversed.abstract voidmarkIndependentEntities(Table table) Marks all entities of a given table which don't dependent on other entities, s.t.abstract voidMarks all rows which are not target of a dependency.abstract voidreadDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Session.ResultSetReader reader, Map<String, Integer> typeCache, String selectionSchema, String originalPKAliasPrefix) Reads all entities which depend on a given entity.abstract voidreadEntities(Table table, boolean orderByPK) Reads all entities of a given table.abstract voidreadMarkedEntities(Table table, boolean orderByPK) Reads all entities of a given table which are marked as independent or as roots.abstract voidreadMarkedEntities(Table table, Session.ResultSetReader reader, String selectionSchema, String originalPKAliasPrefix, boolean orderByPK) Reads all entities of a given table which are marked as independent or as roots.abstract voidreadNonTraversedDependencies(Table table, Session.ResultSetReader reader) Reads all non-traversed dependencies.abstract longreadUnfilteredEntityColumns(Table table, List<Column> columns, Session.ResultSetReader reader) Reads some columns of all entities of a given table without using filters.abstract longremoveAssociatedDestinations(Association association, boolean deletedEntitiesAreMarked, Set<Table> allTables) Removes all entities from this graph which are associated with an entity outside the graph.voidremoveDependencies(Association association) Removes all dependencies for a given association.abstract voidremoveReflexiveDependencies(Table table) Removes all reflexive dependencies of given table.abstract longresolveAssociation(Table table, Association association, int today) Resolves an association.abstract longresolveAssociation(Table table, Association association, EntityGraph otherGraph, EntityGraph universum, boolean forDelete) Resolves an association.abstract voidsetAge(int age) Sets the age of the graph.abstract voidsetBirthdayOfSubject(int birthdayOfSubject) Sets birthday of subject rows.voidsetDeleteMode(boolean deleteMode) Sets the delete mode.voidsetImportFilterManager(ImportFilterManager importFilterManager) Sets theImportFilterManagervoidsetTransformerFactory(TransformerFactory transformerFactory) Sets theTransformerFactory.abstract voidshutDown()Shuts down statement-executor.voidtruncate(ExecutionContext executionContext, boolean checkExist) Tries to delete this graph using "truncate".protected intabstract voidupdateEntities(Table table, Set<Column> columns, OutputStreamWriter scriptFileWriter, DBMS targetConfiguration, boolean inSourceSchema, String reason) Updates columns of a table.
-
Field Details
-
ENTITY_GRAPH
-
ENTITY_SET_ELEMENT
-
ENTITY
-
DEPENDENCY
-
dataModel
-
isTruncated
protected boolean isTruncated -
executionContext
The execution context. -
inDeleteMode
protected boolean inDeleteMode -
graphID
public final int graphIDThe unique ID of the graph. -
importFilterManager
TheImportFilterManager.
-
-
Constructor Details
-
EntityGraph
-
-
Method Details
-
setBirthdayOfSubject
public abstract void setBirthdayOfSubject(int birthdayOfSubject) Sets birthday of subject rows.- Parameters:
birthdayOfSubject- birthday of subject rows
-
copy
Copies an entity-graph.- Parameters:
graphID- the unique ID of the graphsession- for executing SQL-Statements- Returns:
- the newly created entity-graph
- Throws:
SQLException
-
createNewGraph
Creates a new entity-graph of same type and session.- Returns:
- the newly created entity-graph
- Throws:
SQLException
-
copy
Copies some tables.- Parameters:
tables- tables to copy- Throws:
SQLException
-
getAge
Gets the age of the graph.- Returns:
- the age of the graph
- Throws:
SQLException
-
setAge
Sets the age of the graph.- Parameters:
age- the age of the graph- Throws:
SQLException
-
getSize
Gets the number of entities in the graph.- Returns:
- the number of entities in the graph
- Throws:
SQLException
-
getSize
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
-
delete
public abstract void delete(boolean forced) Deletes the graph.- Parameters:
forced- iftrue, force deletion and don't allow optimization
-
addEntities
Adds entities to the graph.- Parameters:
table- the tablecondition- the condition in SQL that the entities must fulfilltoday- 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 tablecondition- the condition in SQL that the entities must fulfilltoday- the birthday of the new entitieslimitDefinition- limitjoinWithEntity- iftrue, 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 tableassociation- the association to resolvetoday- 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 tableassociation- the association to resolveotherGraph- the target entity-graph to add resolved entities intouniversum- the universe entity-graph used to filter candidatesforDelete- iftrue, 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 dependencyfromAlias- alias for from-tableto- destination of dependencytoAlias- alias for to-tablecondition- condition of dependencyaggregationId- id of aggregation association (for XML export), 0 if not applicabledependencyId- id of dependencyisAssociationReversed- iftrue, the association is used in reverse direction- Throws:
SQLException
-
getDistinctDependencyIDs
Gets distinct association-ids of all edges.- Returns:
- set of distinct dependency IDs
- Throws:
SQLException
-
markIndependentEntities
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
Marks all rows which are not target of a dependency.- Throws:
SQLException
-
readMarkedEntities
Reads all entities of a given table which are marked as independent or as roots.- Parameters:
table- the tableorderByPK- iftrue, 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 tablereader- for reading the result-setorderByPK- iftrue, result will be ordered by primary keys- Throws:
SQLException
-
readEntities
Reads all entities of a given table.- Parameters:
table- the tableorderByPK- iftrue, 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 tablecolumns- the columnsscriptFileWriter- writer for the SQL script outputtargetConfiguration- the target DBMS configurationinSourceSchema- iftrue, use source-schema-mapping, else use schema-mappingreason- 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 tablecolumns- the columnsreader- to read- Throws:
SQLException
-
deleteIndependentEntities
Deletes all entities which are marked as independent.- Throws:
SQLException
-
deleteEntities
Deletes all entities from a given table.- Throws:
SQLException
-
countEntities
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 associationdeletedEntitiesAreMarked- if true, consider entity as deleted if its birthday is negativeallTables- 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 SQLExceptionReads all entities which depend on a given entity.- Parameters:
table- the table from which to read entitiesassociation- the dependencyresultSet- current row is the given entityresultSetMetaData- meta data of the result setreader- reads the entitiestypeCache- cache for column type lookupsselectionSchema- the selection schemaoriginalPKAliasPrefix- prefix for original primary key aliases- Throws:
SQLException
-
markDependentEntitiesAsTraversed
public abstract void markDependentEntitiesAsTraversed(Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Map<String, Integer> typeCache) throws SQLExceptionMarks all entities which depend on a given entity as traversed.- Parameters:
association- the dependencyresultSet- current row is the given entityresultSetMetaData- meta data of the result settypeCache- 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 forreader- reads the entities- Throws:
SQLException
-
removeReflexiveDependencies
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
Gets the universal primary key.- Returns:
- the universal primary key
-
shutDown
Shuts down statement-executor.- Throws:
SQLException
-
getSession
-
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
-
close
Closes the graph. Deletes the local database.- Throws:
SQLException
-
removeDependencies
Removes all dependencies for a given association.- Parameters:
association- the association- Throws:
SQLException
-
getTargetSession
-
setDeleteMode
public void setDeleteMode(boolean deleteMode) Sets the delete mode.- Parameters:
deleteMode- iftrue, the graph operates in delete mode
-
typeName
-
setTransformerFactory
Sets theTransformerFactory.- Parameters:
transformerFactory- the factory
-
getTransformerFactory
-
setImportFilterManager
Sets theImportFilterManager- Parameters:
importFilterManager- theImportFilterManager
-
getImportFilterManager
Gets theImportFilterManager- 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 paralleldmlResultWriter- writer for the DML result outputnumberOfEntities- the number of entities to processtargetSession- the session for the target databasetargetDBMSConfiguration- the target DBMS configurationdbmsConfiguration- the source DBMS configuration- Throws:
SQLExceptionIOException
-
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 outputtargetDBMSConfiguration- the target DBMS configuration- Throws:
IOExceptionSQLException
-
dmlTableReference
Gets table reference for DML statements for a given working table.- Parameters:
tableName- the working tablesession- holds connection to DBMS- Returns:
- table reference for the working table
- Throws:
SQLException
-
deleteRows
Deletes rows from table. Applies DBMS-specific deletion strategies, if available.- Parameters:
session- the sessiontable- the tablewhere- the "where" condition- Returns:
- row count
- Throws:
SQLException
-
truncate
Tries to delete this graph using "truncate".- Parameters:
executionContext- the execution contextcheckExist- iftrue, checks existence of each graph- Throws:
SQLException
-
checkExist
Checks if the graph still exists.- Parameters:
executionContext- the execution context- Throws:
RuntimeException- if the graph no longer existsSQLException
-
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
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
-