Search in sources :

Example 1 with OTruncateClusterStatement

use of com.orientechnologies.orient.core.sql.parser.OTruncateClusterStatement in project orientdb by orientechnologies.

the class OCommandExecutorSQLTruncateCluster method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLTruncateCluster 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_CLUSTER))
            throw new OCommandSQLParsingException("Keyword " + KEYWORD_CLUSTER + " not found. Use " + getSyntax(), parserText, oldPos);
        oldPos = pos;
        pos = nextWord(parserText, parserText, oldPos, word, true);
        if (pos == -1)
            throw new OCommandSQLParsingException("Expected cluster name. Use " + getSyntax(), parserText, oldPos);
        clusterName = decodeClusterName(word.toString());
        if (preParsedStatement != null) {
            // new parser, this will be removed and implemented with the new executor
            OIdentifier name = ((OTruncateClusterStatement) preParsedStatement).clusterName;
            if (name != null) {
                clusterName = name.getStringValue();
            }
        }
        final ODatabaseDocument database = getDatabase();
        if (database.getClusterIdByName(clusterName) == -1)
            throw new OCommandSQLParsingException("Cluster '" + clusterName + "' not found", parserText, oldPos);
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OTruncateClusterStatement(com.orientechnologies.orient.core.sql.parser.OTruncateClusterStatement) OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) OIdentifier(com.orientechnologies.orient.core.sql.parser.OIdentifier) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument)

Aggregations

OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)1 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)1 OIdentifier (com.orientechnologies.orient.core.sql.parser.OIdentifier)1 OTruncateClusterStatement (com.orientechnologies.orient.core.sql.parser.OTruncateClusterStatement)1