Пример #1
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);
 }
Пример #2
0
 private void readLongWrapperArray(Document document, String key) {
   ValueList tempList = valueList.getNextList();
   if (tempList == null) {
     document.put(key, null);
     return;
   }
   int len = tempList.length();
   Long[] array = new Long[len];
   for (int i = 0; i < len; i++) {
     array[i] = tempList.getNextLong();
   }
   document.put(key, array);
 }
Пример #3
0
 private void readDoubleArray(Document document, String key) {
   ValueList tempList = valueList.getNextList();
   if (tempList == null) {
     document.put(key, null);
     return;
   }
   int len = tempList.length();
   double[] array = new double[len];
   for (int i = 0; i < len; i++) {
     array[i] = tempList.getNextDouble();
   }
   document.put(key, array);
 }
Пример #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 void readDatatypeArray(int type, Document document, String key) {
   ValueList tempList = valueList.getNextList();
   if (tempList == null) {
     document.put(key, null);
     return;
   }
   int len = tempList.length();
   Object[] array = null;
   if (type == ElementType.TYPE_STRING_ARRAY) {
     array = new String[len];
     for (int i = 0; i < len; i++) {
       array[i] = tempList.getNextString();
     }
   } else if (type == ElementType.TYPE_INTEGER_ARRAY) {
     array = new Integer[len];
     for (int i = 0; i < len; i++) {
       array[i] = tempList.getNextInt();
     }
   } else if (type == ElementType.TYPE_LONG_ARRAY) {
     array = new Long[len];
     for (int i = 0; i < len; i++) {
       array[i] = tempList.getNextLong();
     }
   } else if (type == ElementType.TYPE_DOUBLE_ARRAY) {
     array = new Double[len];
     for (int i = 0; i < len; i++) {
       array[i] = tempList.getNextDouble();
     }
   }
   document.put(key, array);
 }
Пример #7
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);
 }
Пример #8
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);
       }
     }
   }
 }
Пример #9
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();
 }
Пример #10
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);
     }
   }
 }
Пример #11
0
 private void writeDocument(
     String key, Document doc, DocumentType type, ValueList valueList, ValueList scratch) {
   scratch.clear();
   write(key, doc, type, scratch);
   valueList.append(scratch);
 }
Пример #12
0
 private void read(Document document, ValueList valueList, DocumentType documentType) {
   Set<String> keySet = documentType.types.keySet();
   for (String key : keySet) {
     ElementType eType = documentType.types.get(key);
     int type = eType.type;
     if (type == ElementType.TYPE_STRING) {
       document.put(key, valueList.getNextString());
     } else if (type == ElementType.TYPE_INTEGER) {
       document.put(key, valueList.getNextInt());
     } else if (type == ElementType.TYPE_DOUBLE) {
       document.put(key, valueList.getNextDouble());
     } else if (type == ElementType.TYPE_LONG) {
       document.put(key, valueList.getNextLong());
     } else if (type == ElementType.TYPE_INTEGER_WRAPPER) {
       document.put(key, valueList.getNextInt());
     } else if (type == ElementType.TYPE_DOUBLE_WRAPPER) {
       document.put(key, valueList.getNextDouble());
     } else if (type == ElementType.TYPE_LONG_WRAPPER) {
       document.put(key, valueList.getNextLong());
     } else if (type == ElementType.TYPE_EMBEDDED) {
       ValueList tempList = valueList.getNextList();
       Document nestedDoc = new Document();
       read(nestedDoc, tempList, eType.nestedType);
       document.put(key, nestedDoc);
     } else if (type == ElementType.TYPE_EMBEDDED_ARRAY) {
       // } TODO else if (type == DocumentType.TYPE_REFERENCE_ARRAY) {
       ValueList tempList = valueList.getNextList();
       if (tempList == null) {
         document.put(key, null);
         continue;
       }
       int listLen = tempList.length();
       Document[] references = new Document[listLen];
       for (int j = 0; j < listLen; j++) {
         references[j] = new Document();
         ValueList tList = tempList.getNextList();
         read(references[j], tList, eType.nestedType);
       }
       document.put(key, references);
     } else if (type == ElementType.TYPE_REFERENCE) {
       String address = valueList.getNextString();
       if (address.equals("")) {
         document.put(key, null);
         continue;
       }
       Document reference = readReference(address, eType.reference, eType.nestedType);
       document.put(key, reference);
     } else if (type == ElementType.TYPE_STRING_ARRAY) {
       readStringArray(document, key);
     } else if (type == ElementType.TYPE_INTEGER_ARRAY) {
       readIntArray(document, key);
     } else if (type == ElementType.TYPE_INTEGER_WRAPPER_ARRAY) {
       readIntegerWrapperArray(document, key);
     } else if (type == ElementType.TYPE_LONG_ARRAY) {
       readLongArray(document, key);
     } else if (type == ElementType.TYPE_LONG_WRAPPER_ARRAY) {
       readLongWrapperArray(document, key);
     } else if (type == ElementType.TYPE_DOUBLE_ARRAY) {
       readDoubleArray(document, key);
     } else if (type == ElementType.TYPE_DOUBLE_WRAPPER_ARRAY) {
       readDoubleWrapperArray(document, key);
     } else if (type == ElementType.TYPE_BYTE_ARRAY) {
       document.put(key, valueList.getNextBytes());
     } else {
       document.put(key, valueList.getNextObject());
     }
   }
 }