Search in sources :

Example 36 with OCommandRequestText

use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.

the class OCommandExecutorSQLTruncateRecord method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLTruncateRecord parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        queryText = preParse(queryText, iRequest);
        textRequest.setText(queryText);
        init((OCommandRequestText) iRequest);
        StringBuilder word = new StringBuilder();
        int oldPos = 0;
        int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_TRUNCATE))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_TRUNCATE + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_RECORD))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_RECORD + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserText, oldPos, word, true);
        if (pos == -1)
            throw new OCommandSQLParsingException("Expected one or more records. Use " + getSyntax(), parserText, oldPos);
        if (word.charAt(0) == '[')
            // COLLECTION
            OStringSerializerHelper.getCollection(parserText, oldPos, records);
        else {
            records.add(word.toString());
        }
        if (records.isEmpty())
            throw new OCommandSQLParsingException("Missed record(s). Use " + getSyntax(), parserText, oldPos);
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText)

Example 37 with OCommandRequestText

use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.

the class OCommandExecutorSQLLiveUnsubscribe method parse.

@Override
public OCommandExecutorSQLLiveUnsubscribe parse(OCommandRequest iRequest) {
    OCommandRequestText requestText = (OCommandRequestText) iRequest;
    String originalText = requestText.getText();
    String remainingText = requestText.getText().trim().substring(5).trim();
    requestText.setText(remainingText);
    try {
        if (remainingText.toLowerCase().startsWith("unsubscribe")) {
            remainingText = remainingText.substring("unsubscribe".length()).trim();
            if (remainingText.contains(" ")) {
                throw new OQueryParsingException("invalid unsubscribe token for live query: " + remainingText);
            }
            this.unsubscribeToken = remainingText;
        }
    } finally {
        requestText.setText(originalText);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException)

Example 38 with OCommandRequestText

use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.

the class OCommandExecutorSQLOptimizeDatabase method parse.

public OCommandExecutorSQLOptimizeDatabase parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        queryText = preParse(queryText, iRequest);
        textRequest.setText(queryText);
        init((OCommandRequestText) iRequest);
        StringBuilder word = new StringBuilder();
        int oldPos = 0;
        int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_OPTIMIZE))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_OPTIMIZE + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_DATABASE))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_DATABASE + " not found. Use " + getSyntax(), parserText, oldPos);
        while (!parserIsEnded() && word.length() > 0) {
            oldPos = pos;
            pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
            if (word.toString().equals(KEYWORD_EDGE))
                optimizeEdges = true;
            else if (word.toString().equals(KEYWORD_NOVERBOSE))
                verbose = false;
        }
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText)

Example 39 with OCommandRequestText

use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.

the class OCommandExecutorSQLRebuildIndex method parse.

public OCommandExecutorSQLRebuildIndex parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        queryText = preParse(queryText, iRequest);
        textRequest.setText(queryText);
        init((OCommandRequestText) iRequest);
        final StringBuilder word = new StringBuilder();
        int oldPos = 0;
        int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_REBUILD))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_REBUILD + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
        if (pos == -1 || !word.toString().equals(KEYWORD_INDEX))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_INDEX + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
        if (pos == -1)
            throw new OCommandSQLParsingException("Expected index name", parserText, oldPos);
        name = word.toString();
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText)

Example 40 with OCommandRequestText

use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelect method parse.

/**
   * Compile the filter conditions only the first time.
   */
public OCommandExecutorSQLSelect parse(final OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    String queryText = textRequest.getText();
    String originalQuery = queryText;
    try {
        // System.out.println("NEW PARSER FROM: " + queryText);
        queryText = preParse(queryText, iRequest);
        // System.out.println("NEW PARSER TO: " + queryText);
        textRequest.setText(queryText);
        super.parse(iRequest);
        initContext();
        final int pos = parseProjections();
        if (pos == -1) {
            return this;
        }
        final int endPosition = parserText.length();
        parserNextWord(true);
        if (parserGetLastWord().equalsIgnoreCase(KEYWORD_FROM)) {
            // FROM
            parsedTarget = OSQLEngine.getInstance().parseTarget(parserText.substring(parserGetCurrentPosition(), endPosition), getContext());
            parserSetCurrentPosition(parsedTarget.parserIsEnded() ? endPosition : parsedTarget.parserGetCurrentPosition() + parserGetCurrentPosition());
        } else {
            parserGoBack();
        }
        if (!parserIsEnded()) {
            parserSkipWhiteSpaces();
            while (!parserIsEnded()) {
                final String w = parserNextWord(true);
                if (!w.isEmpty()) {
                    if (w.equals(KEYWORD_WHERE)) {
                        compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition(), endPosition), getContext(), KEYWORD_WHERE);
                        optimize();
                        parserSetCurrentPosition(compiledFilter.parserIsEnded() ? endPosition : compiledFilter.parserGetCurrentPosition() + parserGetCurrentPosition());
                    } else if (w.equals(KEYWORD_LET)) {
                        parseLet();
                    } else if (w.equals(KEYWORD_GROUP)) {
                        parseGroupBy();
                    } else if (w.equals(KEYWORD_ORDER)) {
                        parseOrderBy();
                    } else if (w.equals(KEYWORD_UNWIND)) {
                        parseUnwind();
                    } else if (w.equals(KEYWORD_LIMIT)) {
                        parseLimit(w);
                    } else if (w.equals(KEYWORD_SKIP) || w.equals(KEYWORD_OFFSET)) {
                        parseSkip(w);
                    } else if (w.equals(KEYWORD_FETCHPLAN)) {
                        parseFetchplan(w);
                    } else if (w.equals(KEYWORD_NOCACHE)) {
                        parseNoCache(w);
                    } else if (w.equals(KEYWORD_TIMEOUT)) {
                        parseTimeout(w);
                    } else if (w.equals(KEYWORD_LOCK)) {
                        final String lock = parseLock();
                        if (lock.equalsIgnoreCase("DEFAULT")) {
                            lockingStrategy = LOCKING_STRATEGY.DEFAULT;
                        } else if (lock.equals("NONE")) {
                            lockingStrategy = LOCKING_STRATEGY.NONE;
                        } else if (lock.equals("RECORD")) {
                            lockingStrategy = LOCKING_STRATEGY.EXCLUSIVE_LOCK;
                        } else if (lock.equals("SHARED")) {
                            lockingStrategy = LOCKING_STRATEGY.SHARED_LOCK;
                        }
                    } else if (w.equals(KEYWORD_PARALLEL)) {
                        parallel = parseParallel(w);
                    } else {
                        if (preParsedStatement == null) {
                            throwParsingException("Invalid keyword '" + w + "'");
                        }
                    //if the pre-parsed statement is OK, then you can go on with the rest, the SQL is valid and this is probably a space in a backtick
                    }
                }
            }
        }
        if (limit == 0 || limit < -1) {
            throw new IllegalArgumentException("Limit must be > 0 or = -1 (no limit)");
        }
        validateQuery();
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText)

Aggregations

OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)44 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)12 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)7 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)5 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)4 OSQLAsynchQuery (com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery)4 OException (com.orientechnologies.common.exception.OException)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OCommandExecutor (com.orientechnologies.orient.core.command.OCommandExecutor)2 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)2 OIdentifier (com.orientechnologies.orient.core.sql.parser.OIdentifier)2 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)2 IOException (java.io.IOException)2 Socket (java.net.Socket)2 Entry (java.util.Map.Entry)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2