svn commit: r594628 - in /xml/xindice/trunk/java: src/org/apache/xindice/core/Collection.java tests/src/org/apache/xindice/core/CollectionTest.java

[email protected]
Newsgroups gmane.text.xml.xindice.devel
Message-ID <[email protected]>
Author: vgritsenko
Date: Tue Nov 13 12:16:05 2007
New Revision: 594628

URL: http://svn.apache.org/viewvc?rev=594628&view=rev
Log:
some refactoring

Modified:
    xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
    xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.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=594628&r1=594627&r2=594628&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 Tue Nov 13 12:16:05 2007
@@ -21,6 +21,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.xindice.core.cache.DocumentCache;
 import org.apache.xindice.core.data.DocumentSet;
 import org.apache.xindice.core.data.EmptyDocumentSet;
 import org.apache.xindice.core.data.EmptyNodeSet;
@@ -38,7 +39,6 @@
 import org.apache.xindice.core.meta.inline.InlineMetaService;
 import org.apache.xindice.core.meta.inline.ResourceTypeReader;
 import org.apache.xindice.core.query.QueryEngine;
-import org.apache.xindice.core.cache.DocumentCache;
 import org.apache.xindice.util.Configurable;
 import org.apache.xindice.util.Configuration;
 import org.apache.xindice.util.Named;
@@ -783,6 +783,24 @@
 
     // -- Core Collection API Public Methods: Data Management ---------------
 
+    private Record writeRecord(Key key, boolean isDocument, byte[] bytes) throws DBException {
+        // Construct the Value object that is stored in the BTree.
+        Value value;
+        if (inlineMetaService == null) {
+            value = new Value(bytes);
+        } else {
+            InlineMetaMap map = inlineMetaService.getEmptyMap();
+            if (isDocument) {
+                map.put("type", ResourceTypeReader.XML);
+            } else {
+                map.put("type", ResourceTypeReader.BINARY);
+            }
+            value = inlineMetaService.createValue(map, bytes, 0, bytes.length);
+        }
+
+        return filer.writeRecord(key, value);
+    }
+
     /**
      * createNewOID allocates a new Object ID to be used as a Key in the
      * Collection.
@@ -835,14 +853,9 @@
 
         Key key = getIdentityKey(createNewKey(id));
         synchronized (key) {
-
             /*
              * If the key has a corresponding value in the cache, return it
              * and save a disk access.
-             *
-             * At some point the current document-centric cache implementation
-             * needs to be converted to an entry cache which can hold both
-             * Document and byte[].
              */
             if (cache != null) {
                 Entry entry = cache.getEntry(this, key);
@@ -871,12 +884,12 @@
                 }
             } else {
                 InlineMetaService.DatabaseEntry databaseEntry = inlineMetaService.readDatabaseEntry(record.getValue());
-                InlineMetaMap metaMap = databaseEntry.map;
+                Object type = databaseEntry.map.get("type");
                 value = databaseEntry.value;
-                isDocument = metaMap.get("type").equals(ResourceTypeReader.XML);
+                isDocument = type.equals(ResourceTypeReader.XML);
 
                 if (log.isTraceEnabled()) {
-                    log.trace(localDebugHeader + "Type=" + metaMap.get("type") + ", Length=" + value.getLength());
+                    log.trace(localDebugHeader + "Type=" + type + ", Length=" + value.getLength());
                 }
             }
 
@@ -889,27 +902,24 @@
                         log.trace(localDebugHeader +
                                   "Compressed XML document=<" + TextWriter.toString(document) + ">");
                     }
-
-                    if (cache != null) {
-                        cache.putEntry(this, key, DocumentCache.COMPRESSED, value, entryMeta);
-                    }
                 } else {
-                    String documentChars = value.toString();
-                    if (log.isTraceEnabled()) {
-                        log.trace(localDebugHeader + "Pre parseDocument(): value=<" + documentChars + ">");
-                    }
-
                     // FIXME There should be no reason here to re-compress the document & flush symbols table?
-                    document = parseDocument(key, documentChars);
-
-                    if (cache != null) {
-                        cache.putEntry(this, key, DocumentCache.UNCOMPRESSED, value, entryMeta);
+                    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 {
@@ -1316,24 +1326,14 @@
             }
             indexManager.addDocument(key, document);
 
-            // Construct the Value object that is stored in the BTree.
-            Value value;
-            if (inlineMetaService == null) {
-                value = new Value(documentBytes);
-            } else {
-                InlineMetaMap map = inlineMetaService.getEmptyMap();
-                map.put("type", ResourceTypeReader.XML);
-                value = inlineMetaService.createValue(map, documentBytes, 0, documentBytes.length);
-            }
-            Record record = filer.writeRecord(key, value);
+            // Construct the Value object and store in the filer.
+            Record record = writeRecord(key, true, documentBytes);
 
             // Cache Stuff
             if (cache != null) {
-                if (compressed) {
-                    cache.putEntry(this, key, DocumentCache.COMPRESSED, new Value(documentBytes), Entry.createMetaMap(record));
-                } else {
-                    cache.putEntry(this, key, DocumentCache.UNCOMPRESSED, new Value(documentBytes), Entry.createMetaMap(record));
-                }
+                cache.putEntry(this, key,
+                               compressed ? DocumentCache.COMPRESSED : DocumentCache.UNCOMPRESSED,
+                               new Value(documentBytes), Entry.createMetaMap(record));
             }
 
             // Update the meta for this document
@@ -1396,10 +1396,8 @@
                 indexManager.removeDocument(key, (Document) entry.getValue());
             }
 
-            InlineMetaMap map = inlineMetaService.getEmptyMap();
-            map.put("type", ResourceTypeReader.BINARY);
-            Value value = inlineMetaService.createValue(map, bytes, 0, bytes.length);
-            Record record = filer.writeRecord(key, value);
+            // Construct the Value object and store in the filer.
+            Record record = writeRecord(key, false, bytes);
 
             if (cache != null) {
                 cache.putEntry(this, key, DocumentCache.BINARY, new Value(bytes), Entry.createMetaMap(record));

Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java?rev=594628&r1=594627&r2=594628&view=diff
==============================================================================
--- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java (original)
+++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java Tue Nov 13 12:16:05 2007
@@ -138,7 +138,7 @@
     }
 
     public void testCompressedDocument() throws Exception {
-        // Compress the document with own symbol table
+        // Compress the document with its own symbol table
         Document document = DOMParser.toDocument(XML);
         SymbolTable symbols = new SymbolTable();
         byte[] data = DOMCompressor.compress(document, symbols);
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.