public D get(ObjectIdentifiable objectId, VersionCorrection versionCorrection) {
ArgumentChecker.notNull(objectId, "objectId");
ArgumentChecker.notNull(versionCorrection, "versionCorrection");
// Search through attributes for specified oid, versions/corrections
Results results = getUidToDocumentCache().createQuery()
.includeKeys().includeValues()
.includeAttribute(getUidToDocumentCache().getSearchAttribute("ObjectId"))
.includeAttribute(getUidToDocumentCache().getSearchAttribute("VersionFromInstant"))
.includeAttribute(getUidToDocumentCache().getSearchAttribute("VersionToInstant"))
.includeAttribute(getUidToDocumentCache().getSearchAttribute("CorrectionFromInstant"))
.includeAttribute(getUidToDocumentCache().getSearchAttribute("CorrectionToInstant"))
.addCriteria(getUidToDocumentCache().getSearchAttribute("ObjectId").eq(objectId.toString()))
.addCriteria(getUidToDocumentCache().getSearchAttribute("VersionFromInstant")
.le(versionCorrection.withLatestFixed(InstantExtractor.MAX_INSTANT).getVersionAsOf().toString()))
.addCriteria(getUidToDocumentCache().getSearchAttribute("VersionToInstant")
.gt(versionCorrection.withLatestFixed(InstantExtractor.MAX_INSTANT.minusNanos(1)).getVersionAsOf().toString()))
.addCriteria(getUidToDocumentCache().getSearchAttribute("CorrectionFromInstant")
.le(versionCorrection.withLatestFixed(InstantExtractor.MAX_INSTANT).getCorrectedTo().toString()))
.addCriteria(getUidToDocumentCache().getSearchAttribute("CorrectionToInstant")
.gt(versionCorrection.withLatestFixed(InstantExtractor.MAX_INSTANT.minusNanos(1)).getCorrectedTo().toString()))
.execute();
// Found a matching cached document
if (results.size() == 1 && results.all().get(0).getValue() != null) {
@SuppressWarnings("unchecked")
D result = (D) results.all().get(0).getValue();
// Debug: check result against underlying
if (TEST_AGAINST_UNDERLYING) {
D check = getUnderlying().get(objectId, versionCorrection);
if (!result.equals(check)) {
s_logger.error(getUidToDocumentCache().getName() + " returned:\n" + result + "\nbut the underlying master returned:\n" + check);
}
}
// Return cached value
return result;
// No cached document found, fetch from underlying by oid/vc instead
// Note: no self-populating by oid/vc, and no caching of misses by oid/vc
} else if (results.size() == 0) {
// Get from underlying by oid/vc, throwing exception if not there
D result = _underlying.get(objectId, versionCorrection);
// Explicitly insert in cache
getUidToDocumentCache().put(new Element(result.getUniqueId(), result));