Author: vgritsenko
Date: Mon Nov 12 14:10:44 2007
New Revision: 594315
URL: http://svn.apache.org/viewvc?rev=594315&view=rev
Log:
binary data caching, and other minor changes
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?rev=594315&r1=594314&r2=594315&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Mon Nov 12 14:10:44 2007
@@ -812,29 +812,28 @@
* method returns Entry that identifies resource type and holds its
* value and metadata.
*
- * @param docKey identifying the desired database entry
+ * @param id identifying the desired database entry
* @return Entry containing the database entry and its metadata, or null
* if no matching entry is found
* @throws DBException in case of backing store error,
* and in case of header corruption
*/
- public final Entry getEntry(Object docKey) throws DBException {
-
+ public final Entry getEntry(Object id) throws DBException {
// I would prefer to throw an exception (NPE) in this case,
// but we have a test indicating a null return...
- if (docKey == null) {
+ if (id == null) {
return null;
}
String localDebugHeader = null;
if (log.isTraceEnabled()) {
- localDebugHeader = debugHeader() + "getEntry: docKey=<" + docKey + ">: ";
+ localDebugHeader = debugHeader() + "getEntry: id=<" + id + ">: ";
log.trace(localDebugHeader);
}
checkFiler(FaultCodes.COL_NO_FILER);
- Key key = getIdentityKey(createNewKey(docKey));
+ Key key = getIdentityKey(createNewKey(id));
synchronized (key) {
/*
@@ -862,17 +861,19 @@
}
Value value;
- InlineMetaMap metaMap = null;
+ 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());
- metaMap = databaseEntry.map;
+ InlineMetaMap metaMap = databaseEntry.map;
value = databaseEntry.value;
+ isDocument = metaMap.get("type").equals(ResourceTypeReader.XML);
if (log.isTraceEnabled()) {
log.trace(localDebugHeader + "Type=" + metaMap.get("type") + ", Length=" + value.getLength());
@@ -880,7 +881,7 @@
}
Map entryMeta = Entry.createMetaMap(record);
- if (inlineMetaService == null || metaMap.get("type").equals(ResourceTypeReader.XML)) {
+ if (isDocument) {
Document document;
if (compressed) {
document = new DocumentImpl(value.getData(), symbols, new NodeSource(this, key));
@@ -915,6 +916,10 @@
log.trace(localDebugHeader + "Binary document");
}
+ if (cache != null) {
+ cache.putBinaryEntry(this, key, value.getData(), entryMeta);
+ }
+
return new Entry(key, value.getData(), entryMeta);
}
}
@@ -1373,8 +1378,10 @@
* </ul>
*/
private boolean putBinary(Key key, byte[] bytes, byte action) throws DBException {
+ Entry entry;
+
synchronized (getIdentityKey(key)) {
- Entry entry = getEntry(key);
+ entry = getEntry(key);
if (action == ACTION_INSERT && entry != null) {
throw new DBException(FaultCodes.COL_DUPLICATE_RESOURCE,
"Error inserting binary resource '" + key + "' in '" + getCanonicalName() +
@@ -1386,10 +1393,7 @@
}
if (entry != null && entry.getEntryType() == Entry.DOCUMENT) {
- // binary resources aren't stored in cache or indexes
- if (cache != null) {
- cache.removeEntry(this, key);
- }
+ // binary resources aren't stored in indexes
indexManager.removeDocument(key, (Document) entry.getValue());
}
@@ -1398,29 +1402,32 @@
Value value = inlineMetaService.createValue(map, bytes, 0, bytes.length);
Record record = filer.writeRecord(key, value);
+ if (cache != null) {
+ cache.putBinaryEntry(this, key, bytes, Entry.createMetaMap(record));
+ }
+
// update the meta for this document
updateDocumentMeta(record);
- return entry == null;
}
+
+ return entry == null;
}
/**
* remove removes an object from the Collection based on its Key,
* regardless of it's type.
*
- * @param key The Object's Key
+ * @param id The Object's Key
* @throws DBException if operation failed
*/
- public final void remove(Object key) throws DBException {
+ public final void remove(Object id) throws DBException {
if (log.isInfoEnabled()) {
- log.info(debugHeader() + "Remove " + key);
+ log.info(debugHeader() + "Remove " + id);
}
checkFiler(FaultCodes.COL_NO_FILER);
- Key objKey = createNewKey(key);
-
- objKey = getIdentityKey(objKey);
+ Key objKey = getIdentityKey(createNewKey(id));
synchronized (objKey) {
Entry entry = getEntry(objKey);
if (entry != null && entry.getEntryType() == Entry.DOCUMENT) {
@@ -1436,13 +1443,15 @@
"Resource '" + objKey + "' does not exist in '" + getCanonicalName() + "'");
}
- // update the meta for this collection if necessary
- updateCollectionMeta();
// remove the document meta
if (isMetaEnabled()) {
getMetaSystemCollection().dropDocumentMeta(this, objKey.toString());
}
}
+
+ // update the meta for this collection if necessary
+ updateCollectionMeta();
+
DBObserver.getInstance().dropDocument(this, objKey);
}
@@ -1519,20 +1528,20 @@
* If no matching entry is found, null is returned, otherwise this method
* return Entry that holds metadata only.
*
- * @param docKey identifying the desired database entry
+ * @param id identifying the desired database entry
* @return Entry containing the metadata of the database entry, or null if no
* matching entry is found
* @throws DBException in case of backing store error,
* and in case of header corruption
*/
- public final Entry getEntryMeta(Object docKey) throws DBException {
- if (docKey == null) {
+ public final Entry getEntryMeta(Object id) throws DBException {
+ if (id == null) {
return null;
}
checkFiler(FaultCodes.COL_NO_FILER);
- Key key = getIdentityKey(createNewKey(docKey));
+ Key key = getIdentityKey(createNewKey(id));
synchronized (key) {
/*
* If the key has a corresponding value in the cache, return it
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java?rev=594315&r1=594314&r2=594315&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java Mon Nov 12 14:10:44 2007
@@ -91,7 +91,7 @@
}
/**
- * getData retrieves a <strong>copy</copy> of the data which is being stored
+ * getData retrieves a copy of the data which is being stored
* by this value as a byte array.
*
* <p>Data copying is performed in order to ensure immutability of the Value.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.