/*
* If the key has a corresponding value in the cache, return it
* and save a disk access.
*/
if (cache != null) {
Entry entry = cache.getEntry(this, key);
if (entry != null) {
if (log.isTraceEnabled()) {
log.trace(localDebugHeader + "Returning cached: " + entry.getValue());
}
return entry;
}
}
Record record = filer.readRecord(key);
if (record == null) {
return null;
}
Value value;
boolean isDocument;
if (inlineMetaService == null) {
value = record.getValue();
isDocument = true;
if (log.isTraceEnabled()) {
log.trace(localDebugHeader + "Type is not available, Length=" + value.getLength());
}
} else {
InlineMetaService.DatabaseEntry databaseEntry = inlineMetaService.readDatabaseEntry(record.getValue());
Object type = databaseEntry.map.get("type");
value = databaseEntry.value;
isDocument = type.equals(ResourceTypeReader.XML);
if (log.isTraceEnabled()) {
log.trace(localDebugHeader + "Type=" + type + ", Length=" + value.getLength());
}
}
Map entryMeta = Entry.createMetaMap(record);
if (isDocument) {
Document document;
if (compressed) {
document = new DocumentImpl(value.getData(), symbols, new NodeSource(this, key));
if (log.isTraceEnabled()) {
log.trace(localDebugHeader +
"Compressed XML document=<" + TextWriter.toString(document) + ">");
}
} else {
// FIXME There should be no reason here to re-compress the document & flush symbols table?
document = parseDocument(key, value.toString());
if (log.isTraceEnabled()) {
log.trace(localDebugHeader +
"Uncompressed XML document=<" + TextWriter.toString(document) + ">");
}
}
// Symbol table could have been updated above, flush it to the disk.
flushSymbolTable();
if (cache != null) {
cache.putEntry(this, key,
compressed ? DocumentCache.COMPRESSED : DocumentCache.UNCOMPRESSED,
value, entryMeta);
}
DBObserver.getInstance().loadDocument(this, record, document);
return new Entry(key, document, entryMeta);
} else {
if (log.isTraceEnabled()) {
log.trace(localDebugHeader + "Binary document");
}
if (cache != null) {
cache.putEntry(this, key, DocumentCache.BINARY, value, entryMeta);
}
return new Entry(key, value.getData(), entryMeta);
}
}
}