Class DocumentIDRegistry
- Direct Known Subclasses:
PersistableDocumentIDRegistry
DocumentIDRegistry(CSVReader, CSVWriter)). For declaring a column holding ID's you have to use a
qualifier started with an &. The ID is unique within the scope of this qualifier.
Example script:
INSERT_UPDATE Customer; uid[unique=true]; defaultPaymentAddress( &payAddress ); defaultShipmentAddress( &delAddress )
; andy ; payAddress0 ; delAddress1 ;
; rigge; payAddress1 ; delAddress0 ;
INSERT Address; &payAddress; &delAddress ; owner( Customer.uid ) ; department
; payAddress0 ; delAddress0 ; andy ; a1
; payAddress1 ; delAddress1 ; andy ; a2
This script is used for importing a customer with referenced addresses. When importing, first the customer will be
created but marked as unresolved (here the unresolved of the ImpExImportReader is meant, because the
used document IDs can not be found in registry. When importing the addresses, the specified IDs will be registered
with the PKs of the addresses and in second import cycle the customers can be finished.
When using the example script for export (without value lines), the customers will be exported first. Because there
are no IDs used for the referenced addresses, new IDs will be generated, but stored in the storage with unresolved
IDs. When exporting the addresses the registry recognizes the already used but unresolved IDs for the addresses and
moves them to the resolved storage. So you can be sure, when you export an item A which references to an item B, that
item B is also exported by simply calling hasUnresolvedIDs after the export process.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration representing the two modes of storing an ID => resolved and unresolved. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a registry without import of mappings and without export of new mappings.DocumentIDRegistry(CSVReader documentIDReader) Creates a registry with import of mappings and without export of new mappings.DocumentIDRegistry(CSVReader documentIDReader, CSVWriter documentIDWriter) Creates a registry with import of mappings and with export of new mappings.DocumentIDRegistry(CSVWriter documentIDWriter) Creates a registry without import of mappings and with export of new mappings. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddID(String qualifier, String documentID, long pk, DocumentIDRegistry.MODE mode) Adds a new mapping ID<->PK to the registry.protected StringcalculateNextID(String qualifier) Generates a new unused ID containing the given qualifier name.voidCloses all used streams (for import and export).booleancontainsID(String qualifier, String documentID) Checks whether the registry contains an mapping with the given ID in scope of the qualifier.booleancontainsPK(String qualifier, long pk) Checks whether the registry contains an mapping with the given PK in scope of the qualifier.protected voidExports an existing mapping to the local writer.protected StringgetID(String qualifier, long pk, DocumentIDRegistry.MODE mode) Gets the ID to which the given PK is mapped.protected longgetPK(String qualifier, String documentID, DocumentIDRegistry.MODE mode) Gets the PK to which the given ID is mapped.Returns the storage related to the given mode.booleanChecks whether there are unresolved IDs in registry.voidImports a set of ID<->PK mappings from given reader.booleanisResolved(String qualifier, String documentID) Checks a given ID if it is in resolved mode.booleanisUnresolved(String qualifier, String documentID) Checks a given ID if it is in unresolved mode.longGets the PK to which the given ID is mapped.Checks if there is always an ID for the given PK in scope of the qualifier, if not, a new ID will be generated marked as unresolved.printUnresolvedIDs(String separator) Gathers all unresolved IDs and prints each one in a list entry.registerID(String qualifier, String documentID, long pk) Registers a new mapping ID<->PK to the registry.registerPK(String qualifier, long pk) Registers a new mapping ID<->PK to the registry.protected voidResloves an unresolved ID.
-
Constructor Details
-
DocumentIDRegistry
public DocumentIDRegistry()Creates a registry without import of mappings and without export of new mappings. You can start an import manually usingimportIDs(CSVReader)later. -
DocumentIDRegistry
Creates a registry without import of mappings and with export of new mappings. You have to callcloseStreams()before usage of the exported stream data. You can start an import manually usingimportIDs(CSVReader)later.- Parameters:
documentIDWriter- writer to which new mappings will be exported.
-
DocumentIDRegistry
Creates a registry with import of mappings and without export of new mappings.- Parameters:
documentIDReader- the reader from which mappings will be read and imported when instantiating.
-
DocumentIDRegistry
Creates a registry with import of mappings and with export of new mappings. You have to callcloseStreams()before usage of the exported stream data.- Parameters:
documentIDReader- the reader from which mappings will be read and imported when instantiating.documentIDWriter- writer to which new mappings will be exported.
-
-
Method Details
-
importIDs
Imports a set of ID<->PK mappings from given reader.- Parameters:
documentIDReader- the reader with which the mappings will be read
-
exportID
Exports an existing mapping to the local writer.- Parameters:
qualifier- the qualifier to which the ID is relateddocumentID- the IDpk- the PK to which the ID is mapped
-
registerID
Registers a new mapping ID<->PK to the registry. If the pair is already existent, it will be replaced. Used for import to register the ID of an item.- Parameters:
qualifier- the qualifier to which the ID is relateddocumentID- the new IDpk- the PK to which the ID will be mapped- Returns:
- the document ID mapped to the given PK (same ID as given one)
- Throws:
ImpExException- the ID already exists and maps to another PK
-
registerPK
Registers a new mapping ID<->PK to the registry. Checks if there is always an ID for the given PK in scope of the qualifier, if not, a new ID will be generated. Used for export to give each item a unique ID related to its PK.- Parameters:
qualifier- qualifier in whose scope the ID will be generatedpk- the pk for which an ID mapping is needed- Returns:
- the (new) ID mapped to the given PK
-
lookupPK
Checks if there is always an ID for the given PK in scope of the qualifier, if not, a new ID will be generated marked as unresolved. Used for export to use the correct ID for an item reference. Is the referenced item not exported the lookup will generate an unresolved ID and will be resolved when item is exported.- Parameters:
qualifier- qualifier in whose scope the ID will be generatedpk- the pk for which an ID mapping is needed- Returns:
- the (new) ID mapped to the given PK
-
lookupID
Gets the PK to which the given ID is mapped. Used while import for resolving an ID to an PK.- Parameters:
qualifier- scope of the IDdocumentID- ID for which the PK will be returned- Returns:
- the PK to the given ID or -1
-
containsID
Checks whether the registry contains an mapping with the given ID in scope of the qualifier. Checks within resolved and unresolved mappings.- Parameters:
qualifier- the scope in which the ID is validdocumentID- the ID which will be checked- Returns:
- true if a mapping with the given ID to a PK is existent
-
containsPK
Checks whether the registry contains an mapping with the given PK in scope of the qualifier. Checks within resolved and unresolved mappings.- Parameters:
qualifier- the scope which will be searchedpk- the PK which will be checked for an ID- Returns:
- true if a mapping with the given PK to a ID is existent within the qualifier
-
hasUnresolvedIDs
public boolean hasUnresolvedIDs()Checks whether there are unresolved IDs in registry. An ID is unresolved, if it is used while export and the item with mapped pk is not export until yet.- Returns:
- true if there are unresolved IDs, otherwise false
-
isUnresolved
Checks a given ID if it is in unresolved mode. An ID is unresolved, if it is used while export and the item with mapped pk is not exported until yet.- Parameters:
qualifier- the scope which will be searcheddocumentID- the ID which will be checked- Returns:
- true if the given ID in given scope is in unresolved mode, otherwise false
-
isResolved
Checks a given ID if it is in resolved mode. An ID is resolved, if it is used while import, or export and the item with mapped pk is already exported- Parameters:
qualifier- the scope which will be searcheddocumentID- the ID which will be checked- Returns:
- true if the given ID in given scope is in resolved mode, otherwise false
-
printUnresolvedIDs
Gathers all unresolved IDs and prints each one in a list entry. So one entry of the resulting list represents one unresolved ID with formatqualifier+separator+id+separator+pk.- Parameters:
separator- the separator symbol used between the attributes of a documentID in resulting list- Returns:
- list of all unresolved ID with one ID per entry
-
closeStreams
public void closeStreams()Closes all used streams (for import and export). -
getID
Gets the ID to which the given PK is mapped.- Parameters:
qualifier- scope in which will be searchedpk- the PK for which the ID will be returnedmode- defines the ID storage in which will be searched- Returns:
- the ID to the given PK or null
-
getPK
Gets the PK to which the given ID is mapped. Used while import for resolving an ID to an PK.- Parameters:
qualifier- scope of the IDdocumentID- ID for which the PK will be returnedmode- defines the ID storage in which will be searched- Returns:
- the PK to the given ID or -1
-
calculateNextID
Generates a new unused ID containing the given qualifier name. Generation uses the qualifier name concatenated with sum of sizes of the storages. Afterwards it increments the resulting number while the id is already used.- Parameters:
qualifier- text which will be part of the generated id- Returns:
- a new id in format
qualifier+number
-
addID
protected void addID(String qualifier, String documentID, long pk, DocumentIDRegistry.MODE mode) throws ImpExException Adds a new mapping ID<->PK to the registry. If the pair is already existent, it will be replaced. T- Parameters:
qualifier- the qualifier to which the ID is relateddocumentID- the new IDpk- the PK to which the ID will be mappedmode- defines the ID storage where the ID will be added- Throws:
ImpExException- the ID already exists and maps to another OK
-
resolveID
Resloves an unresolved ID. Tries to remove the ID from the unresolved ID storage and to add it to the resolved storage.- Parameters:
qualifier- the qualifier to which the ID is relateddocumentID- the id which will be moved from unresolved to resolvedpk- the mapped pk of the ID
-
getQualifiersMap
protected Map<String,org.apache.commons.collections4.bidimap.DualHashBidiMap<String, getQualifiersMapLong>> (DocumentIDRegistry.MODE mode) Returns the storage related to the given mode.- Parameters:
mode- the mode to which the associated storage is needed- Returns:
- storage associated to given mode
-