Package com.orientechnologies.orient.core.exception

Examples of com.orientechnologies.orient.core.exception.OSerializationException


        param.field("params", parameters);
        buffer.add(param.toStream());
      }

    } catch (IOException e) {
      throw new OSerializationException("Error while marshalling OSQLQuery", e);
    }

    return buffer.toByteArray();
  }
View Full Code Here


      byte[] buffer = new byte[size];
      segment.getFile().read(OConstants.SIZE_INT, buffer, size);

      fromStream(buffer);
    } catch (Exception e) {
      throw new OSerializationException("Can't load database's configuration. The database seems to be corrupted.");
    }
    return this;
  }
View Full Code Here

      segment.getFile().allocateSpace(buffer.length + OConstants.SIZE_INT);
      segment.getFile().writeInt(0, buffer.length);
      segment.getFile().write(OConstants.SIZE_INT, buffer);
    } catch (Exception e) {
      throw new OSerializationException("Error on update storage configuration", e);
    }
  }
View Full Code Here

      byte protocolVersion = stream.peek();
      if (protocolVersion != -1) {
        // @COMPATIBILITY BEFORE 0.9.25
        stream.getAsByte();
        if (protocolVersion != CURRENT_PROTOCOL_VERSION)
          throw new OSerializationException(
              "The index has been created with a previous version of OrientDB. Soft transitions between version is a featured supported since 0.9.25. In order to use it with this version of OrientDB you need to export and import your database. "
                  + protocolVersion + "<->" + CURRENT_PROTOCOL_VERSION);
      }

      rootRid.fromStream(stream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));
View Full Code Here

      record.fromStream(stream.getByteArray());
      return record.toStream();

    } catch (IOException e) {
      throw new OSerializationException("Error on marshalling RB+Tree", e);
    } finally {
      marshalledRecords.remove(identityRecord);

      OProfiler.getInstance().stopChrono("OMVRBTreePersistent.toStream", timer);
    }
View Full Code Here

      byte protocolVersion = stream.peek();
      if (protocolVersion != -1) {
        // @COMPATIBILITY BEFORE 0.9.25
        stream.getAsByte();
        if (protocolVersion != CURRENT_PROTOCOL_VERSION)
          throw new OSerializationException(
              "The index has been created with a previous version of OrientDB. Soft transitions between version is a featured supported since 0.9.25. In order to use it with this version of OrientDB you need to export and import your database. "
                  + protocolVersion + "<->" + CURRENT_PROTOCOL_VERSION);
      }

      rootRid.fromStream(stream.getAsByteArrayFixed(ORecordId.PERSISTENT_SIZE));
View Full Code Here

      record.fromStream(stream.getByteArray());
      return record.toStream();

    } catch (IOException e) {
      throw new OSerializationException("Error on marshalling RB+Tree", e);
    } finally {
      marshalledRecords.remove(identityRecord);

      OProfiler.getInstance().stopChrono("OMVRBTreePersistent.toStream", timer);
    }
View Full Code Here

  }

  @Override
  public ORecordInternal<?> fromString(final ODatabaseRecord iDatabase, String iSource, ORecordInternal<?> iRecord) {
    if (iSource == null)
      throw new OSerializationException("Error on unmarshalling JSON content: content is null");

    iSource = iSource.trim();
    if (!iSource.startsWith("{") || !iSource.endsWith("}"))
      throw new OSerializationException("Error on unmarshalling JSON content: content must be between { }");

    if (iRecord != null)
      // RESET ALL THE FIELDS
      iRecord.reset();

    iSource = iSource.substring(1, iSource.length() - 1).trim();

    String[] fields = OStringParser.getWords(iSource, ":,", true);

    String fieldName;
    String fieldValue;
    String fieldValueAsString;
    Map<String, Character> fieldTypes = null;

    // SEARCH FOR FIELD TYPES IF ANY
    if (fields != null && fields.length > 0) {
      for (int i = 0; i < fields.length; i += 2) {
        fieldName = fields[i];
        fieldName = fieldName.substring(1, fieldName.length() - 1);
        fieldValue = fields[i + 1];
        fieldValueAsString = fieldValue.length() >= 2 ? fieldValue.substring(1, fieldValue.length() - 1) : fieldValue;

        if (fieldName.equals(ATTRIBUTE_FIELD_TYPES) && iRecord instanceof ODocument) {
          // LOAD THE FIELD TYPE MAP
          final String[] fieldTypesParts = fieldValueAsString.split(",");
          if (fieldTypesParts.length > 0) {
            fieldTypes = new HashMap<String, Character>();
            String[] part;
            for (String f : fieldTypesParts) {
              part = f.split("=");
              if (part.length == 2)
                fieldTypes.put(part[0], part[1].charAt(0));
            }
          }
        } else if (fieldName.equals(ATTRIBUTE_TYPE)) {
          if (iRecord == null || iRecord.getRecordType() != fieldValueAsString.charAt(0)) {
            // CREATE THE RIGHT RECORD INSTANCE
            iRecord = ORecordFactory.newInstance((byte) fieldValueAsString.charAt(0));
            iRecord.setDatabase(iDatabase);
          }
        }
      }

      try {
        for (int i = 0; i < fields.length; i += 2) {
          fieldName = fields[i];
          fieldName = fieldName.substring(1, fieldName.length() - 1);
          fieldValue = fields[i + 1].trim();
          fieldValueAsString = fieldValue.length() >= 2 ? fieldValue.substring(1, fieldValue.length() - 1) : fieldValue;

          // RECORD ATTRIBUTES
          if (fieldName.equals(ATTRIBUTE_ID))
            iRecord.setIdentity(new ORecordId(fieldValueAsString));

          else if (fieldName.equals(ATTRIBUTE_VERSION))
            iRecord.setVersion(Integer.parseInt(fieldValue));

          else if (fieldName.equals(ATTRIBUTE_TYPE)) {
            continue;
          } else if (fieldName.equals(ATTRIBUTE_CLASS) && iRecord instanceof ODocument)
            ((ODocument) iRecord).setClassNameIfExists("null".equals(fieldValueAsString) ? null : fieldValueAsString);
          else if (fieldName.equals(ATTRIBUTE_FIELD_TYPES) && iRecord instanceof ODocument)
            // JUMP IT
            continue;

          // RECORD VALUE(S)
          else if (fieldName.equals("value") && !(iRecord instanceof ODocument)) {
            if ("null".equals(fieldValue))
              iRecord.fromStream(new byte[] {});
            else if (iRecord instanceof ORecordBytes) {
              // BYTES
              iRecord.fromStream(OBase64Utils.decode(fieldValueAsString));
            } else if (iRecord instanceof ORecordStringable) {
              ((ORecordStringable) iRecord).value(fieldValueAsString);
            }
          } else {
            if (iRecord instanceof ODocument) {
              final Object v = getValue((ODocument) iRecord, fieldName, fieldValue, fieldValueAsString, null, null, fieldTypes);

              if (v != null)
                if (v instanceof Collection<?> && ((Collection<?>) v).size() > 0) {
                  if (v instanceof ORecordLazySet)
                    ((ORecordLazySet) v).setAutoConvertToRecord(false);
                  else if (v instanceof ORecordLazyList)
                    ((ORecordLazyList) v).setAutoConvertToRecord(false);

                  // CHECK IF THE COLLECTION IS EMBEDDED
                  Object first = ((Collection<?>) v).iterator().next();
                  if (first != null && first instanceof ORecord<?> && !((ORecord<?>) first).getIdentity().isValid()) {
                    ((ODocument) iRecord).field(fieldName, v, v instanceof Set<?> ? OType.EMBEDDEDSET : OType.EMBEDDEDLIST);
                    continue;
                  }
                } else if (v instanceof Map<?, ?> && ((Map<?, ?>) v).size() > 0) {
                  // CHECK IF THE MAP IS EMBEDDED
                  Object first = ((Map<?, ?>) v).values().iterator().next();
                  if (first != null && first instanceof ORecord<?> && !((ORecord<?>) first).getIdentity().isValid()) {
                    ((ODocument) iRecord).field(fieldName, v, OType.EMBEDDEDMAP);
                    continue;
                  }
                }

              ((ODocument) iRecord).field(fieldName, v);
            }
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
        throw new OSerializationException("Error on unmarshalling JSON content for record " + iRecord.getIdentity(), e);
      }
    }
    return iRecord;
  }
View Full Code Here

        if (c == COLLECTION_BEGIN)
          insideCollection++;
        else if (c == COLLECTION_END) {
          if (!isCharPresent(c, iRecordSeparator)) {
            if (insideCollection == 0)
              throw new OSerializationException("Found invalid " + COLLECTION_END
                  + " character. Assure to open and close correctly.");
            insideCollection--;
          }

        } else if (c == PARENTHESIS_BEGIN) {
          insideParenthesis++;
        } else if (c == PARENTHESIS_END) {
          if (!isCharPresent(c, iRecordSeparator)) {
            if (insideParenthesis == 0)
              throw new OSerializationException("Found invalid " + PARENTHESIS_END
                  + " character. Assure to open and close correctly.");
            insideParenthesis--;
          }

        } else if (c == MAP_BEGIN) {
          insideMap++;
        } else if (c == MAP_END) {
          if (!isCharPresent(c, iRecordSeparator)) {
            if (insideMap == 0)
              throw new OSerializationException("Found invalid " + MAP_END + " character. Assure to open and close correctly.");
            insideMap--;
          }
        }

        else if (c == LINK)
View Full Code Here

      if (hasTypeField(fields))
        // OBJECT
        return fromString(iRecord.getDatabase(), iFieldValue, null);
      else {
        if (fields.length % 2 == 1)
          throw new OSerializationException("Bad JSON format on map. Expected pairs of field:value but received '"
              + iFieldValueAsString + "'");

        // MAP
        final Map<String, Object> embeddedMap = new LinkedHashMap<String, Object>();

        for (int i = 0; i < fields.length; i += 2) {
          iFieldName = fields[i];
          if (iFieldName.length() >= 2)
            iFieldName = iFieldName.substring(1, iFieldName.length() - 1);
          iFieldValue = fields[i + 1];
          iFieldValueAsString = iFieldValue.length() >= 2 ? iFieldValue.substring(1, iFieldValue.length() - 1) : iFieldValue;

          embeddedMap.put(iFieldName, getValue(iRecord, null, iFieldValue, iFieldValueAsString, iLinkedType, null, iFieldTypes));
        }
        return embeddedMap;
      }
    } else if (iFieldValue.startsWith("[") && iFieldValue.endsWith("]")) {

      // EMBEDDED VALUES
      final Collection<?> embeddedCollection;
      if (iType == OType.LINKSET)
        embeddedCollection = new ORecordLazySet(iRecord);
      else if (iType == OType.EMBEDDEDSET)
        embeddedCollection = new OTrackedSet<Object>(iRecord);
      else if (iType == OType.LINKLIST)
        embeddedCollection = new ORecordLazyList(iRecord);
      else
        embeddedCollection = new OTrackedList<Object>(iRecord);

      iFieldValue = iFieldValue.substring(1, iFieldValue.length() - 1);

      if (iFieldValue.length() > 0) {
        // EMBEDDED VALUES
        List<String> items = OStringSerializerHelper.smartSplit(iFieldValue, ',');

        Object collectionItem;
        for (String item : items) {
          iFieldValue = item.trim();
          iFieldValueAsString = iFieldValue.length() >= 2 ? iFieldValue.substring(1, iFieldValue.length() - 1) : iFieldValue;

          collectionItem = getValue(iRecord, null, iFieldValue, iFieldValueAsString, iLinkedType, null, iFieldTypes);

          if (collectionItem instanceof ODocument && iRecord instanceof ODocument)
            // SET THE OWNER
            ((ODocument) collectionItem).addOwner(iRecord);

          ((Collection<Object>) embeddedCollection).add(collectionItem);
        }
      }

      return embeddedCollection;
    }

    if (iType == null)
      // TRY TO DETERMINE THE CONTAINED TYPE from THE FIRST VALUE
      if (iFieldValue.charAt(0) != '\"' && iFieldValue.charAt(0) != '\'') {
        if (iFieldValue.equalsIgnoreCase("false") || iFieldValue.equalsIgnoreCase("true"))
          iType = OType.BOOLEAN;
        else {
          Character c = null;
          if (iFieldTypes != null) {
            c = iFieldTypes.get(iFieldName);
            if (c != null)
              iType = ORecordSerializerStringAbstract.getType(iFieldValue + c);
          }

          if (c == null && iFieldValue.length() > 0) {
            // TRY TO AUTODETERMINE THE BEST TYPE
            if (iFieldValue.charAt(0) == ORID.PREFIX && iFieldValue.contains(":"))
              iType = OType.LINK;
            else if (OStringSerializerHelper.contains(iFieldValue, '.'))
              iType = OType.FLOAT;
            else
              iType = OType.INTEGER;
          }
        }
      } else if (iFieldValueAsString.length() >= 4 && iFieldValueAsString.charAt(0) == ORID.PREFIX
          && iFieldValueAsString.contains(":"))
        iType = OType.LINK;
      else if (iFieldValueAsString.startsWith("{") && iFieldValueAsString.endsWith("}"))
        iType = OType.EMBEDDED;
      else {
        if (iFieldValueAsString.length() == DEF_DATE_FORMAT.length())
          // TRY TO PARSE AS DATE
          try {
            synchronized (dateFormat) {
              return dateFormat.parseObject(iFieldValueAsString);
            }
          } catch (Exception e) {
          }

        iType = OType.STRING;
      }

    if (iType != null)
      switch (iType) {
      case STRING:
        return iFieldValueAsString;

      case LINK:
        final int pos = iFieldValueAsString.indexOf('@');
        if (pos > -1)
          // CREATE DOCUMENT
          return new ODocument(iRecord.getDatabase(), iFieldValueAsString.substring(1, pos), new ORecordId(
              iFieldValueAsString.substring(pos + 1)));
        else
          // CREATE SIMPLE RID
          return new ORecordId(iFieldValueAsString.substring(1));

      case EMBEDDED:
        return fromString(iRecord.getDatabase(), iFieldValueAsString);

      case DATE:
      case DATETIME:
        if (iFieldValueAsString == null || iFieldValueAsString.equals(""))
          return null;
        try {
          // TRY TO PARSE AS LONG
          return Long.parseLong(iFieldValueAsString);
        } catch (NumberFormatException e) {
          try {
            // TRY TO PARSE AS DATE
            return dateFormat.parseObject(iFieldValueAsString);
          } catch (ParseException ex) {
            throw new OSerializationException("Unable to unmarshall date: " + iFieldValueAsString, e);
          }
        }

      default:
        return OStringSerializerHelper.fieldTypeFromStream(iRecord, iType, iFieldValue);
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.exception.OSerializationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.