예제 #1
0
 private void write(String key, Document document, DocumentType type, ValueList valueList) {
   Set<String> keySet = type.types.keySet();
   for (String keyName : keySet) {
     ElementType elType = type.types.get(keyName);
     Object value = document.get(keyName);
     if (value == null) {
       valueList.append((String) null);
       continue;
     }
     if (elType.isBasicType()) {
       valueList.append(value);
       // for now only datatypes can be indexed
       indexMap = allIndices.get(keyName);
       if (indexMap != null) {
         setIndex(keyName, value, key);
       }
     } else if ((elType.type == ElementType.TYPE_REFERENCE)
         || (elType.type == ElementType.TYPE_REFERENCE_ARRAY)) {
       String dbid =
           writeReference(
               key, (Document) value, elType.nestedType, elType.reference, elType.referenceKey);
       valueList.append(dbid);
     } else if (value instanceof Document) {
       writeDocument(key, (Document) value, elType.nestedType, valueList, scratchList);
     } else if (value instanceof Document[]) {
       scratchList.clear();
       writeList.clear();
       for (int j = 0; j < ((Document[]) value).length; j++) {
         writeDocument(key, ((Document[]) value)[j], elType.nestedType, scratchList, writeList);
       }
       valueList.append(scratchList);
     } else if (elType.type == ElementType.TYPE_STRING_ARRAY) {
       writeStringArray((String[]) value);
     } else if ((elType.type == ElementType.TYPE_INTEGER_ARRAY)
         || (elType.type == ElementType.TYPE_INTEGER_WRAPPER_ARRAY)) {
       writeIntArray(value, elType.type);
     } else if ((elType.type == ElementType.TYPE_LONG_ARRAY)
         || (elType.type == ElementType.TYPE_LONG_WRAPPER_ARRAY)) {
       writeLongArray(value, elType.type);
     } else if ((elType.type == ElementType.TYPE_DOUBLE_ARRAY)
         || (elType.type == ElementType.TYPE_DOUBLE_WRAPPER_ARRAY)) {
       writeDoubleArray(value, elType.type);
     } else { // if (type == ElementType.TYPE_BACK_REFERENCE) {
       valueList.append(value);
     }
   }
 }
예제 #2
0
 /**
  * Stores a Document. If store succeeds, the Document is also removed from the runtime memory.
  *
  * @param key key
  * @param value Document to store
  */
 public void store(String key, Document value) {
   // if (documentType == null) {
   //    setDocumentType(name);
   // }
   // TODO if DocumenType == null exception?
   valueList.clear();
   write(key, value, documentType, valueList);
   global.set(valueList, key);
 }
예제 #3
0
 private void writeStringArray(String[] value) {
   writeList.clear();
   int len = Array.getLength(value);
   if (len > 0) {
     for (int i = 0; i < len; i++) {
       writeList.append(value[i]);
     }
   }
   valueList.append(writeList);
 }
예제 #4
0
 private void writeIntArray(Object value, int type) {
   writeList.clear();
   int len = Array.getLength(value);
   if (len > 0) {
     if (type == ElementType.TYPE_INTEGER_ARRAY) {
       for (int i = 0; i < len; i++) {
         writeList.append(Array.getInt(value, i));
       }
     } else if (type == ElementType.TYPE_INTEGER_WRAPPER_ARRAY) {
       for (int i = 0; i < len; i++) {
         writeList.append(((Integer[]) value)[i]);
       }
     }
   }
   valueList.append(writeList);
 }
예제 #5
0
 private void writeDoubleArray(Object value, int type) {
   writeList.clear();
   int len = Array.getLength(value);
   if (len > 0) {
     if (type == ElementType.TYPE_DOUBLE_ARRAY) {
       for (int i = 0; i < len; i++) {
         writeList.append(Array.getDouble(value, i));
       }
     } else if (type == ElementType.TYPE_DOUBLE_WRAPPER_ARRAY) {
       for (int i = 0; i < len; i++) {
         writeList.append(((Double[]) value)[i]);
       }
     }
   }
   valueList.append(writeList);
 }
예제 #6
0
 private String writeReference(
     String key, Document document, DocumentType type, String reference, String refKey) {
   String referenceKey = document.get(refKey).toString();
   NodeReference refGlobal = getReferenceGlobal(reference);
   refGlobal.appendSubscript(referenceKey);
   if (refGlobal.exists()) {
     return referenceKey;
   }
   referenceTempList.clear();
   NodeReference oldIndexGlobal = indexGlobal;
   indexGlobal = getIndexGlobal(reference);
   write(key, document, type, referenceTempList);
   // document.setDBID(name,key);
   indexGlobal = oldIndexGlobal;
   refGlobal.set(referenceTempList);
   return referenceKey; // document.getDBID();
 }
예제 #7
0
 public void buildIndices() {
   if ((allIndices == null) || allIndices.isEmpty()) {
     return;
   }
   for (String indexName : allIndices.keySet()) {
     indexMap = allIndices.get(indexName);
     indexGlobal.setSubscriptCount(0);
     indexGlobal.appendSubscript(indexName);
     for (Object value : indexMap.keySet()) {
       Object key = indexMap.get(value);
       if (key instanceof ArrayList) {
         scratchList.clear();
         for (Object data : (ArrayList) key) {
           scratchList.append(data);
         }
         indexGlobal.set(scratchList, value);
       } else {
         indexGlobal.set((String) key, value);
       }
     }
   }
 }
예제 #8
0
 private void writeDocument(
     String key, Document doc, DocumentType type, ValueList valueList, ValueList scratch) {
   scratch.clear();
   write(key, doc, type, scratch);
   valueList.append(scratch);
 }