Class RemoteEntityGraph
java.lang.Object
net.sf.jailer.entitygraph.EntityGraph
net.sf.jailer.entitygraph.remote.RemoteEntityGraph
- Direct Known Subclasses:
IntraDatabaseEntityGraph
Persistent graph of entities in the remote database.
- Author:
- Ralf Wisser
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intBirthday of subject rows.protected final RowIdSupportfinal SessionFor executing SQL-Statements.protected final PrimaryKeyThe universal primary key.Fields inherited from class net.sf.jailer.entitygraph.EntityGraph
dataModel, DEPENDENCY, ENTITY, ENTITY_GRAPH, ENTITY_SET_ELEMENT, executionContext, graphID, importFilterManager, inDeleteMode, isTruncated -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRemoteEntityGraph(DataModel dataModel, int graphID, Session session, PrimaryKey universalPrimaryKey, Runnable updateStatistics, ExecutionContext executionContext) Constructor. -
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 RemoteEntityGraphcreate(DataModel dataModel, int graphID, Session session, PrimaryKey universalPrimaryKey, Runnable updateStatistics, ExecutionContext executionContext) Creates a new entity-graph.Creates a new entity-graph of same type and session.voiddelete(boolean force) Deletes the graph.longdeleteEntities(Table table) Deletes all entities from a given table.voiddeleteIndependentEntities(Table table) Deletes all entities which are marked as independent.protected StringfilteredSelectionClause(Table table, boolean applyImportFilter) Gets select clause for reading rows of given type with respect of the column filters.protected StringfilteredSelectionClause(Table table, String columnPrefix, Quoting quoting, boolean appylImportFilter) Gets select clause for reading rows of given type with respect of the column filters.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.longGets the number of entities from given tables in the graph.Gets the target session.longGets total row-count.Gets the universal primary key.protected static voidinit(int graphID, Session session, ExecutionContext executionContext) Initializes a new entity-graph.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.protected StringpkEqualsEntityID(Table table, String tableAlias, String entityAlias) Gets a SQL comparison expression for comparing rows with entities.protected StringprefixColumnName(String prefix, Quoting quoting, Column column) Adds a prefix to a column name.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.voidreadEntities(Table table, boolean orderByPK) Reads all entities of a given table.protected longreadEntities(Table table, boolean orderByPK, Session.ResultSetReader reader) 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, getTransformerFactory, incLobCount, removeDependencies, setDeleteMode, setImportFilterManager, setTransformerFactory, truncate, typeName
-
Field Details
-
session
For executing SQL-Statements. -
universalPrimaryKey
The universal primary key. -
birthdayOfSubject
protected int birthdayOfSubjectBirthday of subject rows. -
rowIdSupport
-
-
Constructor Details
-
RemoteEntityGraph
protected RemoteEntityGraph(DataModel dataModel, int graphID, Session session, PrimaryKey universalPrimaryKey, Runnable updateStatistics, ExecutionContext executionContext) throws SQLException Constructor.- Parameters:
graphID- the unique ID of the graphsession- for executing SQL-StatementsuniversalPrimaryKey- the universal primary key- Throws:
SQLException
-
-
Method Details
-
setBirthdayOfSubject
public void setBirthdayOfSubject(int birthdayOfSubject) Sets birthday of subject rows.- Specified by:
setBirthdayOfSubjectin classEntityGraph- Parameters:
birthdayOfSubject- birthday of subject rows
-
create
public static RemoteEntityGraph create(DataModel dataModel, int graphID, Session session, PrimaryKey universalPrimaryKey, Runnable updateStatistics, ExecutionContext executionContext) throws SQLException Creates a new entity-graph.- Parameters:
graphID- the unique ID of the graphsession- for executing SQL-StatementsuniversalPrimaryKey- the universal primary key- Returns:
- the newly created entity-graph
- Throws:
SQLException
-
init
Initializes a new entity-graph.- Parameters:
graphID- the unique ID of the graphsession- for executing SQL-Statements
-
copy
Copies an entity-graph.- Specified by:
copyin classEntityGraph- Parameters:
newGraphID- the unique ID of the new graphsession- for executing SQL-Statements- 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
-
getSize
Gets the number of entities from given tables in the graph.- Overrides:
getSizein classEntityGraph- Parameters:
tables- the tables to count entities for- Returns:
- the number of entities in the graph
- Throws:
SQLException- if a database access error occurs
-
delete
public void delete(boolean force) Deletes the graph.- Specified by:
deletein classEntityGraph- Parameters:
force- 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
-
readEntities
protected long readEntities(Table table, boolean orderByPK, Session.ResultSetReader reader) throws SQLException Reads all entities of a given table.- Parameters:
table- the tableorderByPK- iftrue, result will be ordered by primary keysreader- the result set reader to process each row- Returns:
- the 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
-
filteredSelectionClause
Gets select clause for reading rows of given type with respect of the column filters.- Parameters:
table- the table to read rows fromapplyImportFilter- iftrue, apply import filters to the selection clause- Returns:
- select clause
-
filteredSelectionClause
protected String filteredSelectionClause(Table table, String columnPrefix, Quoting quoting, boolean appylImportFilter) Gets select clause for reading rows of given type with respect of the column filters.- Parameters:
table- the table to read rows fromcolumnPrefix- optional prefix for column aliases, ornullfor no prefixquoting- quoting helper for unquoting of column names when a columnPrefix is givenapplyImportFilter- iftrue, apply import filters to the selection clause- Returns:
- select clause
-
prefixColumnName
-
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> typeCache, 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 entitiestypeCache- 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
-
pkEqualsEntityID
Gets a SQL comparison expression for comparing rows with entities.- Parameters:
table- the tabletableAlias- the alias for the table in the SQL expressionentityAlias- the alias for the entity table in the SQL expression- Returns:
- a SQL comparison expression for comparing rows of
tablewith entities
-
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 session
-
getDatamodel
Gets the data model.- Specified by:
getDatamodelin classEntityGraph- Returns:
- the data model
-
close
Closes the graph.- Specified by:
closein classEntityGraph- Throws:
SQLException
-
getTargetSession
Gets the target session.- Specified by:
getTargetSessionin classEntityGraph- Returns:
- the target session
-