コード例 #1
0
ファイル: OrientElement.java プロジェクト: jango2015/orientdb
  protected void checkClass() {
    // FORCE EARLY UNMARSHALLING
    final ODocument doc = getRecord();
    doc.deserializeFields();

    final OClass cls = ODocumentInternal.getImmutableSchemaClass(doc);

    if (cls == null || !cls.isSubClassOf(getBaseClassName()))
      throw new IllegalArgumentException(
          "The document received is not a " + getElementType() + ". Found class '" + cls + "'");
  }
コード例 #2
0
ファイル: OrientElement.java プロジェクト: jango2015/orientdb
  /**
   * Returns a Property value.
   *
   * @param key Property name
   * @return Property value if any, otherwise NULL.
   */
  @Override
  public <T> T getProperty(final String key) {
    if (key == null) return null;

    final OrientBaseGraph graph = getGraph();
    if (key.equals("_class"))
      return (T) ODocumentInternal.getImmutableSchemaClass(getRecord()).getName();
    else if (key.equals("_version")) return (T) new Integer(getRecord().getVersion());
    else if (key.equals("_rid")) return (T) rawElement.getIdentity().toString();

    final Object fieldValue = getRecord().field(key);
    if (graph != null
        && fieldValue instanceof OIdentifiable
        && !(((OIdentifiable) fieldValue).getRecord() instanceof ORecordBytes))
      // CONVERT IT TO VERTEX/EDGE
      return (T) graph.getElement(fieldValue);
    else if (OMultiValue.isMultiValue(fieldValue)
        && OMultiValue.getFirstValue(fieldValue) instanceof OIdentifiable) {
      final OIdentifiable firstValue = (OIdentifiable) OMultiValue.getFirstValue(fieldValue);

      if (firstValue instanceof ODocument) {
        final ODocument document = (ODocument) firstValue;

        if (document.isEmbedded() || ODocumentInternal.getImmutableSchemaClass(document) == null)
          return (T) fieldValue;
      }

      if (graph != null)
        // CONVERT IT TO ITERABLE<VERTEX/EDGE>
        return (T)
            new OrientElementIterable<OrientElement>(
                graph, OMultiValue.getMultiValueIterable(fieldValue));
    }

    return (T) fieldValue;
  }
コード例 #3
0
  protected boolean filter(final ORecord iRecord, final OCommandContext iContext) {
    if (iRecord instanceof ODocument) {
      // CHECK THE TARGET CLASS
      final ODocument recordSchemaAware = (ODocument) iRecord;
      Map<String, String> targetClasses = parsedTarget.getTargetClasses();
      // check only classes that specified in query will go to result set
      if ((targetClasses != null) && (!targetClasses.isEmpty())) {
        for (String targetClass : targetClasses.keySet()) {
          if (!((OMetadataDefault) getDatabase().getMetadata())
              .getImmutableSchemaSnapshot()
              .getClass(targetClass)
              .isSuperClassOf(ODocumentInternal.getImmutableSchemaClass(recordSchemaAware)))
            return false;
        }
        iContext.updateMetric("documentAnalyzedCompatibleClass", +1);
      }
    }

    return evaluateRecord(iRecord, iContext);
  }