Search in sources :

Example 11 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OrientVertexIterator method getGraphElementRecord.

@Override
public OIdentifiable getGraphElementRecord(final Object iObject) {
    final ORecord rec = ((OIdentifiable) iObject).getRecord();
    if (rec == null || !(rec instanceof ODocument))
        return null;
    final ODocument value = (ODocument) rec;
    final OIdentifiable v;
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(value);
    if (immutableClass.isVertexType()) {
        // DIRECT VERTEX
        v = value;
    } else if (immutableClass.isEdgeType()) {
        // EDGE
        if (vertex.settings.isUseVertexFieldsForEdgeLabels() || OrientEdge.isLabeled(OrientEdge.getRecordLabel(value), iLabels))
            v = OrientEdge.getConnection(value, connection.getKey().opposite());
        else
            v = null;
    } else
        throw new IllegalStateException("Invalid content found between connections: " + value);
    return v;
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 12 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OrientVertexIterator method isVertex.

private boolean isVertex(final OIdentifiable iObject) {
    final ORecord rec = iObject.getRecord();
    if (rec == null || !(rec instanceof ODocument))
        return false;
    final ODocument value = (ODocument) rec;
    final OIdentifiable v;
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(value);
    if (immutableClass.isVertexType()) {
        // DIRECT VERTEX
        return true;
    } else if (immutableClass.isEdgeType()) {
        return false;
    }
    throw new IllegalStateException("Invalid content found between connections: " + value);
}
Also used : ORecord(com.orientechnologies.orient.core.record.ORecord) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OSQLFunctionMove method v2e.

protected Object v2e(final OrientBaseGraph graph, final OIdentifiable iRecord, final Direction iDirection, final String[] iLabels) {
    final ODocument rec = iRecord.getRecord();
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
    if (immutableClass != null && immutableClass.isVertexType()) {
        // VERTEX
        final OrientVertex vertex = graph.getVertex(rec);
        if (vertex != null)
            return vertex.getEdges(iDirection, iLabels);
    }
    return null;
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 14 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OClassTrigger method onTrigger.

public RESULT onTrigger(final TYPE iType, final ORecord iRecord) {
    if (database.getStatus() != STATUS.OPEN)
        return RESULT.RECORD_NOT_CHANGED;
    if (!(iRecord instanceof ODocument))
        return RESULT.RECORD_NOT_CHANGED;
    final ODocument document = (ODocument) iRecord;
    OImmutableClass immutableSchemaClass = ODocumentInternal.getImmutableSchemaClass(document);
    if (immutableSchemaClass != null && immutableSchemaClass.isTriggered())
        return super.onTrigger(iType, iRecord);
    return RESULT.RECORD_NOT_CHANGED;
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 15 with OImmutableClass

use of com.orientechnologies.orient.core.metadata.schema.OImmutableClass in project orientdb by orientechnologies.

the class OClassTrigger method checkClzAttribute.

private Object checkClzAttribute(final ODocument iDocument, String attr) {
    final OImmutableClass clz = ODocumentInternal.getImmutableSchemaClass(iDocument);
    if (clz != null && clz.isTriggered()) {
        OFunction func = null;
        String fieldName = clz.getCustom(attr);
        OClass superClz = clz.getSuperClass();
        while (fieldName == null || fieldName.length() == 0) {
            if (superClz == null || superClz.getName().equals(CLASSNAME))
                break;
            fieldName = superClz.getCustom(attr);
            superClz = superClz.getSuperClass();
        }
        if (fieldName != null && fieldName.length() > 0) {
            // check if it is reflection or not
            final Object[] clzMethod = this.checkMethod(fieldName);
            if (clzMethod != null)
                return clzMethod;
            func = database.getMetadata().getFunctionLibrary().getFunction(fieldName);
            if (func == null) {
                // check if it is rid
                if (OStringSerializerHelper.contains(fieldName, ORID.SEPARATOR)) {
                    try {
                        ODocument funcDoc = database.load(new ORecordId(fieldName));
                        if (funcDoc != null) {
                            func = database.getMetadata().getFunctionLibrary().getFunction((String) funcDoc.field("name"));
                        }
                    } catch (Exception ex) {
                        OLogManager.instance().error(this, "illegal record id : ", ex.getMessage());
                    }
                }
            }
        } else {
            final Object funcProp = iDocument.field(attr);
            if (funcProp != null) {
                final String funcName = funcProp instanceof ODocument ? (String) ((ODocument) funcProp).field("name") : funcProp.toString();
                func = database.getMetadata().getFunctionLibrary().getFunction(funcName);
            }
        }
        return func;
    }
    return null;
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OCommandScriptException(com.orientechnologies.orient.core.command.script.OCommandScriptException) OFunction(com.orientechnologies.orient.core.metadata.function.OFunction) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OImmutableClass (com.orientechnologies.orient.core.metadata.schema.OImmutableClass)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 ORecord (com.orientechnologies.orient.core.record.ORecord)6 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 Vertex (com.tinkerpop.blueprints.Vertex)2 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)2 OException (com.orientechnologies.common.exception.OException)1 OCommandScriptException (com.orientechnologies.orient.core.command.script.OCommandScriptException)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORecordOperation (com.orientechnologies.orient.core.db.record.ORecordOperation)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 ORID (com.orientechnologies.orient.core.id.ORID)1