Class LocalEntityGraph
java.lang.Object
net.sf.jailer.entitygraph.EntityGraph
net.sf.jailer.entitygraph.local.LocalEntityGraph
Persistent graph of entities.
Persists the graph in a local database.
- Author:
- Ralf Wisser
-
Field Summary
Fields inherited from class net.sf.jailer.entitygraph.EntityGraph
dataModel, DEPENDENCY, ENTITY, ENTITY_GRAPH, ENTITY_SET_ELEMENT, executionContext, graphID, importFilterManager, inDeleteMode, isTruncated -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDependencies(Table from, String fromAlias, Table to, String toAlias, String condition, int aggregationId, int dependencyId, boolean isAssociationReversed) Adds dependencies.longaddEntities(Table table, String condition, int today) Adds entities to the graph.longaddEntities(Table table, String condition, int today, SubjectLimitDefinition limitDefinition, boolean joinWithEntity) Adds limited number of entities to the graph.voidclose()Closes the graph.Copies an entity-graph.longcountEntities(Table table) Counts the entities of a given table in this graph.static LocalEntityGraphcreate(DataModel dataModel, int graphID, Session remoteSession, ExecutionContext executionContext) Creates a new entity-graph.Creates a new entity-graph of same type and session.voiddelete(boolean forced) Deletes the graph.longdeleteEntities(Table table) Deletes all entities from a given table.voiddeleteIndependentEntities(Table table) Deletes all entities which are marked as independent.intgetAge()Gets the age of the graph.Gets the data model.Gets distinct association-ids of all edges.Gets the session.longgetSize()Gets the number of entities in the graph.Gets the target session.longGets total row-count.Gets the universal primary key.voidmarkDependentEntitiesAsTraversed(Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Map<String, Integer> typeCache) Marks all entities which depend on a given entity as traversed.voidmarkIndependentEntities(Table table) Marks all entities of a given table which don't dependent on other entities, s.t.voidMarks all rows which are not target of a dependency.voidreadDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Session.ResultSetReader reader, Map<String, Integer> theTypeCache, String selectionSchema, String originalPKAliasPrefix) Reads all entities which depend on a given entity.voidreadEntities(Table table, boolean orderByPK) Reads all entities of a given table.voidreadMarkedEntities(Table table, boolean orderByPK) Reads all entities of a given table which are marked as independent or as roots.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.voidreadNonTraversedDependencies(Table table, Session.ResultSetReader reader) Reads all non-traversed dependencies.longreadUnfilteredEntityColumns(Table table, List<Column> columns, Session.ResultSetReader reader) Reads some columns of all entities of a given table without using filters.longremoveAssociatedDestinations(Association association, boolean deletedEntitiesAreMarked, Set<Table> allTables) Removes all entities from this graph which are associated with an entity outside the graph.voidremoveReflexiveDependencies(Table table) Removes all reflexive dependencies of given table.longresolveAssociation(Table table, Association association, int today) Resolves an association.longresolveAssociation(Table table, Association association, EntityGraph otherGraph, EntityGraph universum, boolean forDelete) Resolves an association.voidsetAge(int age) Sets the age of the graph.voidsetBirthdayOfSubject(int birthdayOfSubject) Sets birthday of subject rows.voidshutDown()Shuts down statement-executor.voidupdateEntities(Table table, Set<Column> columns, OutputStreamWriter scriptFileWriter, DBMS targetConfiguration, boolean inSourceSchema, String reason) Updates columns of a table.Methods inherited from class net.sf.jailer.entitygraph.EntityGraph
addExportedCount, checkExist, copy, createUniqueGraphID, delete, deleteRows, dmlTableReference, dropMappingTables, fillAndWriteMappingTables, getExportedCount, getImportFilterManager, getSelectionClause, getSize, getTransformerFactory, incLobCount, removeDependencies, setDeleteMode, setImportFilterManager, setTransformerFactory, truncate, typeName
-
Method Details
-
close
Closes the graph. Deletes the local database.- Specified by:
closein classEntityGraph- Throws:
SQLException
-
setBirthdayOfSubject
public void setBirthdayOfSubject(int birthdayOfSubject) Sets birthday of subject rows.- Specified by:
setBirthdayOfSubjectin classEntityGraph- 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 graphremoteSession- for executing SQL-Statements- Returns:
- the newly created entity-graph
- Throws:
IOExceptionSQLException
-
copy
Copies an entity-graph.- Specified by:
copyin classEntityGraph- 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
Creates a new entity-graph of same type and session.- Specified by:
createNewGraphin classEntityGraph- Returns:
- the newly created entity-graph
- Throws:
SQLException
-
getAge
Gets the age of the graph.- Specified by:
getAgein classEntityGraph- Returns:
- the age of the graph
- Throws:
SQLException
-
setAge
Sets the age of the graph.- Specified by:
setAgein classEntityGraph- Parameters:
age- the age of the graph- Throws:
SQLException
-
getSize
Gets the number of entities in the graph.- Specified by:
getSizein classEntityGraph- Returns:
- the number of entities in the graph
- Throws:
SQLException
-
delete
public void delete(boolean forced) Deletes the graph.- Specified by:
deletein classEntityGraph- Parameters:
forced- iftrue, force deletion and don't allow optimization
-
addEntities
Adds entities to the graph.- Specified by:
addEntitiesin classEntityGraph- 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 long addEntities(Table table, String condition, int today, SubjectLimitDefinition limitDefinition, boolean joinWithEntity) throws SQLException Adds limited number of entities to the graph.- Specified by:
addEntitiesin classEntityGraph- 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
Resolves an association. Retrieves and adds all entities associated with an entity born yesterday in the graph and adds the dependencies.- Specified by:
resolveAssociationin classEntityGraph- 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 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:
resolveAssociationin classEntityGraph- 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 void addDependencies(Table from, String fromAlias, Table to, String toAlias, String condition, int aggregationId, int dependencyId, boolean isAssociationReversed) throws SQLException Adds dependencies.- Specified by:
addDependenciesin classEntityGraph- 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.- Specified by:
getDistinctDependencyIDsin classEntityGraph- 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.- Specified by:
markIndependentEntitiesin classEntityGraph- Parameters:
table- the table- Throws:
SQLException
-
markRoots
Marks all rows which are not target of a dependency.- Specified by:
markRootsin classEntityGraph- Parameters:
table- the table- Throws:
SQLException
-
readMarkedEntities
Reads all entities of a given table which are marked as independent or as roots.- Specified by:
readMarkedEntitiesin classEntityGraph- Parameters:
table- the tableorderByPK- iftrue, 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:
readMarkedEntitiesin classEntityGraph- 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.- Specified by:
readEntitiesin classEntityGraph- Parameters:
table- the tableorderByPK- iftrue, 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:
readUnfilteredEntityColumnsin classEntityGraph- Parameters:
table- the tablecolumns- the columnsreader- 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:
updateEntitiesin classEntityGraph- 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
-
deleteIndependentEntities
Deletes all entities which are marked as independent.- Specified by:
deleteIndependentEntitiesin classEntityGraph- Parameters:
table- the table- Throws:
SQLException
-
deleteEntities
Deletes all entities from a given table.- Specified by:
deleteEntitiesin classEntityGraph- Parameters:
table- the table- Returns:
- number of deleted entities
- Throws:
SQLException
-
countEntities
Counts the entities of a given table in this graph.- Specified by:
countEntitiesin classEntityGraph- 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:
removeAssociatedDestinationsin classEntityGraph- 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 void readDependentEntities(Table table, Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Session.ResultSetReader reader, Map<String, Integer> theTypeCache, String selectionSchema, String originalPKAliasPrefix) throws SQLExceptionReads all entities which depend on a given entity.- Specified by:
readDependentEntitiesin classEntityGraph- 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 entitiestheTypeCache- cache for column type lookupsselectionSchema- the selection schemaoriginalPKAliasPrefix- prefix for original primary key aliases- Throws:
SQLException
-
markDependentEntitiesAsTraversed
public void markDependentEntitiesAsTraversed(Association association, ResultSet resultSet, ResultSetMetaData resultSetMetaData, Map<String, Integer> typeCache) throws SQLExceptionMarks all entities which depend on a given entity as traversed.- Specified by:
markDependentEntitiesAsTraversedin classEntityGraph- 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 void readNonTraversedDependencies(Table table, Session.ResultSetReader reader) throws SQLException Reads all non-traversed dependencies.- Specified by:
readNonTraversedDependenciesin classEntityGraph- Parameters:
table- the source of dependencies to look forreader- reads the entities- Throws:
SQLException
-
removeReflexiveDependencies
Removes all reflexive dependencies of given table.- Specified by:
removeReflexiveDependenciesin classEntityGraph- Parameters:
table- the table- Throws:
SQLException
-
getTotalRowcount
public long getTotalRowcount()Gets total row-count.- Specified by:
getTotalRowcountin classEntityGraph- Returns:
- total row-count
-
getUniversalPrimaryKey
Gets the universal primary key.- Specified by:
getUniversalPrimaryKeyin classEntityGraph- Returns:
- the universal primary key
-
shutDown
Shuts down statement-executor.- Specified by:
shutDownin classEntityGraph- Throws:
SQLException
-
getSession
Gets the session.- Specified by:
getSessionin classEntityGraph- Returns:
- the local session
-
getDatamodel
Gets the data model.- Specified by:
getDatamodelin classEntityGraph- Returns:
- the data model
-
getTargetSession
Gets the target session.- Specified by:
getTargetSessionin classEntityGraph- Returns:
- the remote session
-