use of com.bakdata.conquery.models.identifiable.IdMutex in project conquery by bakdata.
the class Column method createSharedDictionaryReplacement.
/**
* Creates an id-replacement mapping for shared dictionaries for an {@link Import}.
* Because Imports are bound to a {@link com.bakdata.conquery.models.worker.Namespace} but the {@link com.bakdata.conquery.models.preproc.Preprocessed} files are not
* they contain dummy-{@link NsIdRef}. These References are mapped to actual object with valid ids through this
* generated mapping.
* <p>
* In this method for shared dictionaries, it is ensured, that the shared dictionary exists in the storage and it is
* created if not.
*
* @param dicts The mapping of column names in the Import to dictionaries in the Import
* @param storage The {@link NamespaceStorage} that backs the dictionaries
* @param out The collection for the generated replacement, that are needed during the deserialization of the next
* part of the {@link com.bakdata.conquery.models.preproc.Preprocessed}-file
* @param sharedDictionaryLocks A collection of locks used for the synchronized creation of shared dictionaries.
*/
public void createSharedDictionaryReplacement(Map<String, Dictionary> dicts, NamespaceStorage storage, Map<DictionaryId, Dictionary> out, IdMutex<DictionaryId> sharedDictionaryLocks) {
Preconditions.checkArgument(type.equals(MajorTypeId.STRING), "Not a STRING Column.");
Preconditions.checkArgument(sharedDictionary != null, "Can only be used for Shared Dictionary based Columns");
// If the column is based on a shared dict. We reference a new empty dictionary or the existing one
// but without updated entries. The entries are updated later on, see ImportJob#applyDictionaryMappings.
Dictionary sharedDict = null;
final DictionaryId sharedDictId = new DictionaryId(table.getDataset().getId(), getSharedDictionary());
try (IdMutex.Locked lock = sharedDictionaryLocks.acquire(sharedDictId)) {
sharedDict = storage.getDictionary(sharedDictId);
// Create dictionary if not yet present
if (sharedDict == null) {
sharedDict = new MapDictionary(table.getDataset(), getSharedDictionary());
storage.updateDictionary(sharedDict);
}
}
out.put(new DictionaryId(Dataset.PLACEHOLDER.getId(), dicts.get(getName()).getName()), sharedDict);
}
Aggregations