Search in sources :

Example 51 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OCommandExecutorSQLMoveVertex method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLMoveVertex parse(final OCommandRequest iRequest) {
    final ODatabaseDocument database = getDatabase();
    init((OCommandRequestText) iRequest);
    parserRequiredKeyword("MOVE");
    parserRequiredKeyword("VERTEX");
    source = parserRequiredWord(false, "Syntax error", " =><,\r\n");
    if (source == null)
        throw new OCommandSQLParsingException("Cannot find source");
    parserRequiredKeyword("TO");
    String temp = parseOptionalWord(true);
    while (temp != null) {
        if (temp.startsWith("CLUSTER:")) {
            if (className != null)
                throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
            clusterName = temp.substring("CLUSTER:".length());
            if (database.getClusterIdByName(clusterName) == -1)
                throw new OCommandSQLParsingException("Cluster '" + clusterName + "' was not found");
        } else if (temp.startsWith("CLASS:")) {
            if (clusterName != null)
                throw new OCommandSQLParsingException("Cannot define multiple sources. Found both cluster and class.");
            className = temp.substring("CLASS:".length());
            clazz = database.getMetadata().getSchema().getClass(className);
            if (clazz == null)
                throw new OCommandSQLParsingException("Class '" + className + "' was not found");
        } else if (temp.equals(KEYWORD_SET)) {
            fields = new ArrayList<OPair<String, Object>>();
            parseSetFields(clazz, fields);
        } else if (temp.equals(KEYWORD_MERGE)) {
            merge = parseJSON();
        } else if (temp.equals(KEYWORD_BATCH)) {
            temp = parserNextWord(true);
            if (temp != null)
                batch = Integer.parseInt(temp);
        }
        temp = parserOptionalWord(true);
        if (parserIsEnded())
            break;
    }
    return this;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OPair(com.orientechnologies.common.util.OPair)

Example 52 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OrientEdgeIterator method createGraphElement.

@Override
public OrientEdge createGraphElement(final Object iObject) {
    if (iObject instanceof OrientEdge)
        return (OrientEdge) iObject;
    final OIdentifiable rec = (OIdentifiable) iObject;
    if (rec == null) {
        // SKIP IT
        OLogManager.instance().warn(this, "Record (%s) is null", iObject);
        return null;
    }
    final ORecord record = rec.getRecord();
    if (record == null) {
        // SKIP IT
        OLogManager.instance().warn(this, "Record (%s) is null", rec);
        return null;
    }
    if (!(record instanceof ODocument)) {
        // SKIP IT
        OLogManager.instance().warn(this, "Found a record (%s) that is not an edge. Source vertex : %s, Target vertex : %s, Database : %s", rec, sourceVertex != null ? sourceVertex.getIdentity() : null, targetVertex != null ? targetVertex.getIdentity() : null, record.getDatabase().getURL());
        return null;
    }
    final ODocument value = rec.getRecord();
    if (value == null) {
        return null;
    }
    OImmutableClass immutableSchema = ODocumentInternal.getImmutableSchemaClass(value);
    if (immutableSchema == null) {
        ODatabaseDocument db = value.getDatabaseIfDefined();
        if (db == null) {
            return null;
        }
        db.getMetadata().reload();
        immutableSchema = ODocumentInternal.getImmutableSchemaClass(value);
        if (immutableSchema == null) {
            return null;
        }
    }
    final OrientEdge edge;
    if (immutableSchema.isVertexType()) {
        // DIRECT VERTEX, CREATE DUMMY EDGE
        OrientBaseGraph graph = this.sourceVertex.getGraph();
        boolean newGraph = false;
        if (graph == null) {
            newGraph = true;
            ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
            if (db != null) {
                graph = new OrientGraphNoTx((ODatabaseDocumentTx) db);
            }
        }
        if (connection.getKey() == Direction.OUT) {
            edge = graph.getEdgeInstance(this.sourceVertex.getIdentity(), rec.getIdentity(), connection.getValue());
        } else {
            edge = graph.getEdgeInstance(rec.getIdentity(), this.sourceVertex.getIdentity(), connection.getValue());
        }
        if (newGraph) {
            graph.shutdown(false, false);
        }
    } else if (immutableSchema.isEdgeType()) {
        // EDGE
        edge = new OrientEdge(this.sourceVertex.getGraph(), rec.getIdentity(), connection.getValue());
    } else
        throw new IllegalStateException("Invalid content found while iterating edges, value '" + value + "' is not an edge");
    if (this.sourceVertex.settings.isUseVertexFieldsForEdgeLabels() || edge.isLabeled(labels))
        return edge;
    return null;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ORecord(com.orientechnologies.orient.core.record.ORecord) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 53 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OrientBaseGraph method makeActive.

public void makeActive() {
    if (database == null) {
        throw new ODatabaseException("Database is closed");
    }
    activeGraph.set(this);
    final ODatabaseDocument tlDb = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (tlDb != database)
        ODatabaseRecordThreadLocal.INSTANCE.set(getDatabase());
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException)

Example 54 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class OGraphCommandExecutorSQLFactory method getGraphNoTx.

/**
   * @return a Non Transactional OrientGraph implementation from the current database in thread local.
   */
public static OrientGraphNoTx getGraphNoTx(final OModifiableBoolean shouldBeShutDown) {
    final ODatabaseDocument database = ODatabaseRecordThreadLocal.INSTANCE.get();
    final OrientBaseGraph result = OrientBaseGraph.getActiveGraph();
    if (result != null && (result instanceof OrientGraphNoTx)) {
        final ODatabaseDocumentTx graphDb = result.getRawGraph();
        // CHECK IF THE DATABASE + USER IN TL IS THE SAME IN ORDER TO USE IT
        if (canReuseActiveGraph(graphDb, database)) {
            if (!graphDb.isClosed()) {
                ODatabaseRecordThreadLocal.INSTANCE.set(graphDb);
                shouldBeShutDown.setValue(false);
                return (OrientGraphNoTx) result;
            }
        }
    }
    // Set it again on ThreadLocal because the getRawGraph() may have set a closed db in the thread-local
    shouldBeShutDown.setValue(true);
    ODatabaseRecordThreadLocal.INSTANCE.set((ODatabaseDocumentInternal) database);
    return (OrientGraphNoTx) OrientGraphFactory.getNoTxGraphImplFactory().getGraph((ODatabaseDocumentTx) database);
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 55 with ODatabaseDocument

use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.

the class IndexTest method testDictionary.

public void testDictionary() {
    ODatabaseDocument db = new ODatabaseDocumentTx(database.getURL());
    db.open("admin", "admin");
    OClass pClass = db.getMetadata().getSchema().createClass("Person2", 1, null);
    pClass.createProperty("firstName", OType.STRING);
    pClass.createProperty("lastName", OType.STRING);
    pClass.createProperty("age", OType.INTEGER);
    pClass.createIndex("testIdx", INDEX_TYPE.DICTIONARY, "firstName", "lastName");
    ODocument person = new ODocument("Person2");
    person.field("firstName", "foo").field("lastName", "bar").save();
    person = new ODocument("Person2");
    person.field("firstName", "foo").field("lastName", "bar").field("age", 32).save();
    db.close();
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)187 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)81 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)68 Test (org.testng.annotations.Test)53 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)23 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)16 ORecord (com.orientechnologies.orient.core.record.ORecord)14 Test (org.junit.Test)14 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)12 ORID (com.orientechnologies.orient.core.id.ORID)11 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)10 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)9 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)9 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 ArrayList (java.util.ArrayList)9 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)8 HashSet (java.util.HashSet)8