public class DocumentIDRegistry
extends java.lang.Object
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
DocumentIDRegistry.MODE
Enumeration representing the two modes of storing an ID => resolved and unresolved.
|
| Constructor and Description |
|---|
DocumentIDRegistry()
Creates 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.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addID(java.lang.String qualifier,
java.lang.String documentID,
long pk,
DocumentIDRegistry.MODE mode)
Adds a new mapping ID<->PK to the registry.
|
protected java.lang.String |
calculateNextID(java.lang.String qualifier)
Generates a new unused ID containing the given qualifier name.
|
void |
closeStreams()
Closes all used streams (for import and export).
|
boolean |
containsID(java.lang.String qualifier,
java.lang.String documentID)
Checks whether the registry contains an mapping with the given ID in scope of the qualifier.
|
boolean |
containsPK(java.lang.String qualifier,
long pk)
Checks whether the registry contains an mapping with the given PK in scope of the qualifier.
|
protected void |
exportID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
Exports an existing mapping to the local writer.
|
protected java.lang.String |
getID(java.lang.String qualifier,
long pk,
DocumentIDRegistry.MODE mode)
Gets the ID to which the given PK is mapped.
|
protected long |
getPK(java.lang.String qualifier,
java.lang.String documentID,
DocumentIDRegistry.MODE mode)
Gets the PK to which the given ID is mapped.
|
protected java.util.Map<java.lang.String,<any>> |
getQualifiersMap(DocumentIDRegistry.MODE mode)
Returns the storage related to the given mode.
|
boolean |
hasUnresolvedIDs()
Checks whether there are unresolved IDs in registry.
|
void |
importIDs(CSVReader documentIDReader)
Imports a set of ID<->PK mappings from given reader.
|
boolean |
isResolved(java.lang.String qualifier,
java.lang.String documentID)
Checks a given ID if it is in resolved mode.
|
boolean |
isUnresolved(java.lang.String qualifier,
java.lang.String documentID)
Checks a given ID if it is in unresolved mode.
|
long |
lookupID(java.lang.String qualifier,
java.lang.String documentID)
Gets the PK to which the given ID is mapped.
|
java.lang.String |
lookupPK(java.lang.String qualifier,
long pk)
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.
|
java.util.List<java.lang.String> |
printUnresolvedIDs(java.lang.String separator)
Gathers all unresolved IDs and prints each one in a list entry.
|
java.lang.String |
registerID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
Registers a new mapping ID<->PK to the registry.
|
java.lang.String |
registerPK(java.lang.String qualifier,
long pk)
Registers a new mapping ID<->PK to the registry.
|
protected void |
resolveID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
Resloves an unresolved ID.
|
public DocumentIDRegistry()
importIDs(CSVReader) later.public DocumentIDRegistry(CSVWriter documentIDWriter)
closeStreams() before usage of the exported stream data. You can start an import manually using
importIDs(CSVReader) later.documentIDWriter - writer to which new mappings will be exported.public DocumentIDRegistry(CSVReader documentIDReader)
documentIDReader - the reader from which mappings will be read and imported when instantiating.public DocumentIDRegistry(CSVReader documentIDReader, CSVWriter documentIDWriter)
closeStreams() before usage of the exported stream data.documentIDReader - the reader from which mappings will be read and imported when instantiating.documentIDWriter - writer to which new mappings will be exported.public void importIDs(CSVReader documentIDReader)
documentIDReader - the reader with which the mappings will be readprotected void exportID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
qualifier - the qualifier to which the ID is relateddocumentID - the IDpk - the PK to which the ID is mappedpublic java.lang.String registerID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
throws ImpExException
qualifier - the qualifier to which the ID is relateddocumentID - the new IDpk - the PK to which the ID will be mappedImpExException - the ID already exists and maps to another PKpublic java.lang.String registerPK(java.lang.String qualifier,
long pk)
qualifier - qualifier in whose scope the ID will be generatedpk - the pk for which an ID mapping is neededpublic java.lang.String lookupPK(java.lang.String qualifier,
long pk)
qualifier - qualifier in whose scope the ID will be generatedpk - the pk for which an ID mapping is neededpublic long lookupID(java.lang.String qualifier,
java.lang.String documentID)
qualifier - scope of the IDdocumentID - ID for which the PK will be returnedpublic boolean containsID(java.lang.String qualifier,
java.lang.String documentID)
qualifier - the scope in which the ID is validdocumentID - the ID which will be checkedpublic boolean containsPK(java.lang.String qualifier,
long pk)
qualifier - the scope which will be searchedpk - the PK which will be checked for an IDpublic boolean hasUnresolvedIDs()
public boolean isUnresolved(java.lang.String qualifier,
java.lang.String documentID)
qualifier - the scope which will be searcheddocumentID - the ID which will be checkedpublic boolean isResolved(java.lang.String qualifier,
java.lang.String documentID)
qualifier - the scope which will be searcheddocumentID - the ID which will be checkedpublic java.util.List<java.lang.String> printUnresolvedIDs(java.lang.String separator)
qualifier+separator+id+separator+pk.separator - the separator symbol used between the attributes of a documentID in resulting listpublic void closeStreams()
protected java.lang.String getID(java.lang.String qualifier,
long pk,
DocumentIDRegistry.MODE mode)
qualifier - scope in which will be searchedpk - the PK for which the ID will be returnedmode - defines the ID storage in which will be searchedprotected long getPK(java.lang.String qualifier,
java.lang.String documentID,
DocumentIDRegistry.MODE mode)
qualifier - scope of the IDdocumentID - ID for which the PK will be returnedmode - defines the ID storage in which will be searchedprotected java.lang.String calculateNextID(java.lang.String qualifier)
qualifier - text which will be part of the generated idqualifier+numberprotected void addID(java.lang.String qualifier,
java.lang.String documentID,
long pk,
DocumentIDRegistry.MODE mode)
throws ImpExException
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 addedImpExException - the ID already exists and maps to another OKprotected void resolveID(java.lang.String qualifier,
java.lang.String documentID,
long pk)
qualifier - the qualifier to which the ID is relateddocumentID - the id which will be moved from unresolved to resolvedpk - the mapped pk of the IDprotected java.util.Map<java.lang.String,<any>> getQualifiersMap(DocumentIDRegistry.MODE mode)
mode - the mode to which the associated storage is neededCopyright © 2018 SAP SE. All Rights Reserved.