Search in sources :

Example 56 with ODatabaseDocument

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

the class OCommandExecutorSQLAlterSequence method execute.

@Override
public Object execute(Map<Object, Object> iArgs) {
    if (this.sequenceName == null) {
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    }
    final ODatabaseDocument database = getDatabase();
    OSequence sequence = database.getMetadata().getSequenceLibrary().getSequence(this.sequenceName);
    boolean result = sequence.updateParams(this.params);
    sequence.reset();
    return result;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 57 with ODatabaseDocument

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

the class OCommandExecutorSQLDelete method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLDelete parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        queryText = preParse(queryText, iRequest);
        textRequest.setText(queryText);
        final ODatabaseDocument database = getDatabase();
        init((OCommandRequestText) iRequest);
        query = null;
        recordCount = 0;
        if (parserTextUpperCase.endsWith(KEYWORD_UNSAFE)) {
            unsafe = true;
            parserText = parserText.substring(0, parserText.length() - KEYWORD_UNSAFE.length() - 1);
            parserTextUpperCase = parserTextUpperCase.substring(0, parserTextUpperCase.length() - KEYWORD_UNSAFE.length() - 1);
        }
        parserRequiredKeyword(OCommandExecutorSQLDelete.KEYWORD_DELETE);
        parserRequiredKeyword(OCommandExecutorSQLDelete.KEYWORD_FROM);
        String subjectName = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
        if (subjectName == null)
            throwSyntaxErrorException("Invalid subject name. Expected cluster, class, index or sub-query");
        if (OStringParser.startsWithIgnoreCase(subjectName, OCommandExecutorSQLAbstract.INDEX_PREFIX)) {
            // INDEX
            indexName = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_PREFIX.length());
            if (!parserIsEnded()) {
                while (!parserIsEnded()) {
                    final String word = parserGetLastWord();
                    if (word.equals(KEYWORD_LOCK))
                        lockStrategy = parseLock();
                    else if (word.equals(KEYWORD_RETURN))
                        returning = parseReturn();
                    else if (word.equals(KEYWORD_UNSAFE))
                        unsafe = true;
                    else if (word.equalsIgnoreCase(KEYWORD_WHERE))
                        compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition()), getContext(), KEYWORD_WHERE);
                    parserNextWord(true);
                }
            } else
                parserSetCurrentPosition(-1);
        } else if (subjectName.startsWith("(")) {
            subjectName = subjectName.trim();
            query = database.command(new OSQLAsynchQuery<ODocument>(subjectName.substring(1, subjectName.length() - 1), this));
            parserNextWord(true);
            if (!parserIsEnded()) {
                while (!parserIsEnded()) {
                    final String word = parserGetLastWord();
                    if (word.equals(KEYWORD_LOCK))
                        lockStrategy = parseLock();
                    else if (word.equals(KEYWORD_RETURN))
                        returning = parseReturn();
                    else if (word.equals(KEYWORD_UNSAFE))
                        unsafe = true;
                    else if (word.equalsIgnoreCase(KEYWORD_WHERE))
                        compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition()), getContext(), KEYWORD_WHERE);
                    parserNextWord(true);
                }
            }
        } else {
            parserNextWord(true);
            while (!parserIsEnded()) {
                final String word = parserGetLastWord();
                if (word.equals(KEYWORD_LOCK))
                    lockStrategy = parseLock();
                else if (word.equals(KEYWORD_RETURN))
                    returning = parseReturn();
                else {
                    parserGoBack();
                    break;
                }
                parserNextWord(true);
            }
            final String condition = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetCurrentPosition()) : "";
            query = database.command(new OSQLAsynchQuery<ODocument>("select from " + getSelectTarget(subjectName) + condition, this));
        }
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 58 with ODatabaseDocument

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

the class OCommandExecutorSQLDropClass method execute.

/**
   * Execute the DROP CLASS.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (className == null) {
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    }
    final ODatabaseDocument database = getDatabase();
    if (ifExists && !database.getMetadata().getSchema().existsClass(className)) {
        return true;
    }
    final OClass cls = database.getMetadata().getSchema().getClass(className);
    if (cls == null) {
        return null;
    }
    final long records = cls.count(true);
    if (records > 0 && !unsafe) {
        // NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES
        if (cls.isSubClassOf("V")) {
            // FOUND VERTEX CLASS
            throw new OCommandExecutionException("'DROP CLASS' command cannot drop class '" + className + "' because it contains Vertices. Use 'DELETE VERTEX' command first to avoid broken edges in a database, or apply the 'UNSAFE' keyword to force it");
        } else if (cls.isSubClassOf("E")) {
            // FOUND EDGE CLASS
            throw new OCommandExecutionException("'DROP CLASS' command cannot drop class '" + className + "' because it contains Edges. Use 'DELETE EDGE' command first to avoid broken vertices in a database, or apply the 'UNSAFE' keyword to force it");
        }
    }
    database.getMetadata().getSchema().dropClass(className);
    if (records > 0 && unsafe) {
        // NOT EMPTY, CHECK IF CLASS IS OF VERTEX OR EDGES
        if (cls.isSubClassOf("V")) {
            // FOUND VERTICES
            if (unsafe)
                OLogManager.instance().warn(this, "Dropped class '%s' containing %d vertices using UNSAFE mode. Database could contain broken edges", className, records);
        } else if (cls.isSubClassOf("E")) {
            // FOUND EDGES
            OLogManager.instance().warn(this, "Dropped class '%s' containing %d edges using UNSAFE mode. Database could contain broken vertices", className, records);
        }
    }
    return true;
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 59 with ODatabaseDocument

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

the class OCommandExecutorSQLDropProperty method execute.

/**
   * Execute the CREATE PROPERTY.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (fieldName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
    final ODatabaseDocument database = getDatabase();
    final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
    if (sourceClass == null)
        throw new OCommandExecutionException("Source class '" + className + "' not found");
    if (ifExists && !sourceClass.existsProperty(fieldName)) {
        return null;
    }
    final List<OIndex<?>> indexes = relatedIndexes(fieldName);
    if (!indexes.isEmpty()) {
        if (force) {
            dropRelatedIndexes(indexes);
        } else {
            final StringBuilder indexNames = new StringBuilder();
            boolean first = true;
            for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(fieldName)) {
                if (!first) {
                    indexNames.append(", ");
                } else {
                    first = false;
                }
                indexNames.append(index.getName());
            }
            throw new OCommandExecutionException("Property used in indexes (" + indexNames.toString() + "). Please drop these indexes before removing property or use FORCE parameter.");
        }
    }
    // REMOVE THE PROPERTY
    sourceClass.dropProperty(fieldName);
    return null;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl)

Example 60 with ODatabaseDocument

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

the class OCommandExecutorSQLDropProperty method relatedIndexes.

private List<OIndex<?>> relatedIndexes(final String fieldName) {
    final List<OIndex<?>> result = new ArrayList<OIndex<?>>();
    final ODatabaseDocument database = getDatabase();
    for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) {
        if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) {
            result.add(oIndex);
        }
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ArrayList(java.util.ArrayList) OCaseInsentiveComparator(com.orientechnologies.common.comparator.OCaseInsentiveComparator)

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