Search in sources :

Example 6 with OCommandSQLParsingException

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

the class OCommandExecutorSQLDeleteVertex method parse.

@SuppressWarnings("unchecked")
public OCommandExecutorSQLDeleteVertex 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);
        database = getDatabase();
        init((OCommandRequestText) iRequest);
        parserRequiredKeyword("DELETE");
        parserRequiredKeyword("VERTEX");
        OClass clazz = null;
        String where = null;
        int limit = -1;
        String word = parseOptionalWord(true);
        while (word != null) {
            if (word.startsWith("#")) {
                rid = new ORecordId(word);
            } else if (word.equalsIgnoreCase("from")) {
                final StringBuilder q = new StringBuilder();
                final int newPos = OStringSerializerHelper.getEmbedded(parserText, parserGetCurrentPosition(), -1, q);
                query = database.command(new OSQLAsynchQuery<ODocument>(q.toString(), this));
                parserSetCurrentPosition(newPos);
            } else if (word.equals(KEYWORD_WHERE)) {
                if (clazz == null)
                    // ASSIGN DEFAULT CLASS
                    clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(OrientVertexType.CLASS_NAME);
                where = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetPreviousPosition()) : "";
                query = database.command(new OSQLAsynchQuery<ODocument>("select from `" + clazz.getName() + "`" + where, this));
                break;
            } else if (word.equals(KEYWORD_LIMIT)) {
                word = parseOptionalWord(true);
                try {
                    limit = Integer.parseInt(word);
                } catch (Exception e) {
                    throw OException.wrapException(new OCommandSQLParsingException("Invalid LIMIT: " + word), e);
                }
            } else if (word.equals(KEYWORD_RETURN)) {
                returning = parseReturn();
            } else if (word.equals(KEYWORD_BATCH)) {
                word = parserNextWord(true);
                if (word != null)
                    batch = Integer.parseInt(word);
            } else if (word.length() > 0) {
                // GET/CHECK CLASS NAME
                clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(word);
                if (clazz == null)
                    throw new OCommandSQLParsingException("Class '" + word + "' was not found");
            }
            word = parseOptionalWord(true);
            if (parserIsEnded())
                break;
        }
        if (where == null)
            where = "";
        else
            where = " WHERE " + where;
        if (query == null && rid == null) {
            StringBuilder queryString = new StringBuilder();
            queryString.append("select from `");
            if (clazz == null) {
                queryString.append(OrientVertexType.CLASS_NAME);
            } else {
                queryString.append(clazz.getName());
            }
            queryString.append("`");
            queryString.append(where);
            if (limit > -1) {
                queryString.append(" LIMIT ").append(limit);
            }
            query = database.command(new OSQLAsynchQuery<ODocument>(queryString.toString(), this));
        }
    } finally {
        textRequest.setText(originalQuery);
    }
    return this;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OMetadataInternal(com.orientechnologies.orient.core.metadata.OMetadataInternal) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 7 with OCommandSQLParsingException

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

the class IndexManagerTest method testCreateSimpleKeyInvalidNameIndex.

@Test
public void testCreateSimpleKeyInvalidNameIndex() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    try {
        indexManager.createIndex("simple:key", OClass.INDEX_TYPE.UNIQUE.toString(), new OSimpleKeyIndexDefinition(-1, OType.INTEGER), null, null, null);
        fail();
    } catch (Exception e) {
        Throwable cause = e;
        while (cause.getCause() != null) cause = cause.getCause();
        assertTrue((cause instanceof IllegalArgumentException) || (cause instanceof OCommandSQLParsingException));
    }
}
Also used : OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) Test(org.testng.annotations.Test)

Example 8 with OCommandSQLParsingException

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

the class OSQLPredicate method text.

public OSQLPredicate text(final String iText) {
    if (iText == null)
        throw new OCommandSQLParsingException("Query text is null");
    try {
        parserText = iText;
        parserTextUpperCase = upperCase(parserText);
        parserSetCurrentPosition(0);
        parserSkipWhiteSpaces();
        rootCondition = (OSQLFilterCondition) extractConditions(null);
        optimize();
    } catch (OQueryParsingException e) {
        if (e.getText() == null)
            // QUERY EXCEPTION BUT WITHOUT TEXT: NEST IT
            throw OException.wrapException(new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), e);
        throw e;
    } catch (Exception t) {
        throw OException.wrapException(new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), t);
    }
    return this;
}
Also used : OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException)

Example 9 with OCommandSQLParsingException

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

the class OSQLFunctionRuntime method setRoot.

@Override
protected void setRoot(final OBaseParser iQueryToParse, final String iText) {
    final int beginParenthesis = iText.indexOf('(');
    // SEARCH FOR THE FUNCTION
    final String funcName = iText.substring(0, beginParenthesis);
    final List<String> funcParamsText = OStringSerializerHelper.getParameters(iText);
    function = OSQLEngine.getInstance().getFunction(funcName);
    if (function == null)
        throw new OCommandSQLParsingException("Unknown function " + funcName + "()");
    // PARSE PARAMETERS
    this.configuredParameters = new Object[funcParamsText.size()];
    for (int i = 0; i < funcParamsText.size(); ++i) this.configuredParameters[i] = funcParamsText.get(i);
    setParameters(configuredParameters, true);
}
Also used : OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException)

Example 10 with OCommandSQLParsingException

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

the class OMatchStatement method parse.

// ------------------------------------------------------------------
// query parsing and optimization
// ------------------------------------------------------------------
/**
   * this method parses the statement
   *
   * @param iRequest Command request implementation.
   * @param <RET>
   * @return
   */
@Override
public <RET extends OCommandExecutor> RET parse(OCommandRequest iRequest) {
    final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
    if (iRequest instanceof OSQLSynchQuery) {
        request = (OSQLSynchQuery<ODocument>) iRequest;
    } else if (iRequest instanceof OSQLAsynchQuery) {
        request = (OSQLAsynchQuery<ODocument>) iRequest;
    } else {
        // BUILD A QUERY OBJECT FROM THE COMMAND REQUEST
        request = new OSQLSynchQuery<ODocument>(textRequest.getText());
        if (textRequest.getResultListener() != null) {
            request.setResultListener(textRequest.getResultListener());
        }
    }
    String queryText = textRequest.getText();
    // please, do not look at this... refactor this ASAP with new executor structure
    final InputStream is = new ByteArrayInputStream(queryText.getBytes());
    final OrientSql osql = new OrientSql(is);
    try {
        OMatchStatement result = (OMatchStatement) osql.parse();
        this.matchExpressions = result.matchExpressions;
        this.returnItems = result.returnItems;
        this.returnAliases = result.returnAliases;
        this.limit = result.limit;
    } catch (ParseException e) {
        OCommandSQLParsingException ex = new OCommandSQLParsingException(e, queryText);
        OErrorCode.QUERY_PARSE_ERROR.throwException(ex.getMessage(), ex);
    }
    assignDefaultAliases(this.matchExpressions);
    pattern = new Pattern();
    for (OMatchExpression expr : this.matchExpressions) {
        pattern.addExpression(expr);
    }
    Map<String, OWhereClause> aliasFilters = new LinkedHashMap<String, OWhereClause>();
    Map<String, String> aliasClasses = new LinkedHashMap<String, String>();
    for (OMatchExpression expr : this.matchExpressions) {
        addAliases(expr, aliasFilters, aliasClasses, context);
    }
    this.aliasFilters = aliasFilters;
    this.aliasClasses = aliasClasses;
    rebindFilters(aliasFilters);
    pattern.validate();
    return (RET) this;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ByteArrayInputStream(java.io.ByteArrayInputStream) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)10 OSQLAsynchQuery (com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery)3 OException (com.orientechnologies.common.exception.OException)2 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)1 OPair (com.orientechnologies.common.util.OPair)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1