Search in sources :

Example 6 with OQueryParsingException

use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.

the class OSQLFilterCondition method getDate.

protected Date getDate(final Object value) {
    if (value == null) {
        return null;
    }
    final OStorageConfiguration config = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration();
    if (value instanceof Long) {
        Calendar calendar = Calendar.getInstance(config.getTimeZone());
        calendar.setTimeInMillis(((Long) value));
        return calendar.getTime();
    }
    String stringValue = value.toString();
    if (NULL_VALUE.equals(stringValue)) {
        return null;
    }
    if (stringValue.length() <= 0) {
        return null;
    }
    if (Pattern.matches("^\\d+$", stringValue)) {
        return new Date(Long.valueOf(stringValue).longValue());
    }
    SimpleDateFormat formatter = config.getDateFormatInstance();
    if (stringValue.length() > config.dateFormat.length()) // ASSUMES YOU'RE USING THE DATE-TIME FORMATTE
    {
        formatter = config.getDateTimeFormatInstance();
    }
    try {
        return formatter.parse(stringValue);
    } catch (ParseException pe) {
        try {
            return new Date(new Double(stringValue).longValue());
        } catch (Exception pe2) {
            throw OException.wrapException(new OQueryParsingException("Error on conversion of date '" + stringValue + "' using the format: " + formatter.toPattern()), pe2);
        }
    }
}
Also used : OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) ParseException(java.text.ParseException) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ParseException(java.text.ParseException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException)

Example 7 with OQueryParsingException

use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.

the class OrientSql method MultiMatchPathItemArrows.

public final OMatchPathItem MultiMatchPathItemArrows() throws ParseException {
    /*@bgen(jjtree) MultiMatchPathItemArrows */
    OMultiMatchPathItemArrows jjtn000 = new OMultiMatchPathItemArrows(JJTMULTIMATCHPATHITEMARROWS);
    boolean jjtc000 = true;
    jjtree.openNodeScope(jjtn000);
    jjtn000.jjtSetFirstToken(getToken(1));
    OMatchPathItem prevItem = null;
    OMatchPathItem nextItem = null;
    try {
        jj_consume_token(DOT);
        jj_consume_token(LPAREN);
        label_44: while (true) {
            if (jj_2_128(2147483647)) {
                nextItem = OutPathItemOpt();
                jjtn000.items.add(nextItem);
            } else if (jj_2_129(2147483647)) {
                nextItem = InPathItemOpt();
                jjtn000.items.add(nextItem);
            } else if (jj_2_130(2147483647)) {
                nextItem = BothPathItemOpt();
                jjtn000.items.add(nextItem);
            } else {
                jj_consume_token(-1);
                throw new ParseException();
            }
            if (prevItem != null && prevItem.filter == null) {
                {
                    if (true)
                        throw new OQueryParsingException("MATCH sub-pattern with no square brackets");
                }
            }
            prevItem = nextItem;
            switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
                case LT:
                case DECR:
                case MINUS:
                    ;
                    break;
                default:
                    jj_la1[245] = jj_gen;
                    break label_44;
            }
        }
        jj_consume_token(RPAREN);
        switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
            case LBRACE:
                jjtn000.filter = MatchFilter();
                break;
            default:
                jj_la1[246] = jj_gen;
                ;
        }
        jjtree.closeNodeScope(jjtn000, true);
        jjtc000 = false;
        jjtn000.jjtSetLastToken(getToken(0));
        {
            if (true)
                return jjtn000;
        }
    } catch (Throwable jjte000) {
        if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
        } else {
            jjtree.popNode();
        }
        if (jjte000 instanceof RuntimeException) {
            {
                if (true)
                    throw (RuntimeException) jjte000;
            }
        }
        if (jjte000 instanceof ParseException) {
            {
                if (true)
                    throw (ParseException) jjte000;
            }
        }
        {
            if (true)
                throw (Error) jjte000;
        }
    } finally {
        if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
            jjtn000.jjtSetLastToken(getToken(0));
        }
    }
    throw new Error("Missing return statement in function");
}
Also used : OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException)

Example 8 with OQueryParsingException

use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.

the class ODocumentHelper method convertField.

@SuppressWarnings("unchecked")
public static <RET> RET convertField(final ODocument iDocument, final String iFieldName, OType type, Class<?> iFieldType, Object iValue) {
    if (iFieldType == null && type != null)
        iFieldType = type.getDefaultJavaType();
    if (iFieldType == null)
        return (RET) iValue;
    if (ORID.class.isAssignableFrom(iFieldType)) {
        if (iValue instanceof ORID) {
            return (RET) iValue;
        } else if (iValue instanceof String) {
            return (RET) new ORecordId((String) iValue);
        } else if (iValue instanceof ORecord) {
            return (RET) ((ORecord) iValue).getIdentity();
        }
    } else if (OIdentifiable.class.isAssignableFrom(iFieldType)) {
        if (iValue instanceof ORID || iValue instanceof ORecord) {
            return (RET) iValue;
        } else if (iValue instanceof String) {
            return (RET) new ORecordId((String) iValue);
        }
    } else if (Set.class.isAssignableFrom(iFieldType)) {
        if (!(iValue instanceof Set)) {
            // CONVERT IT TO SET
            final Collection<?> newValue;
            if (type.isLink())
                newValue = new ORecordLazySet(iDocument);
            else
                newValue = new OTrackedSet<Object>(iDocument);
            if (iValue instanceof Collection<?>) {
                ((Collection<Object>) newValue).addAll((Collection<Object>) iValue);
                return (RET) newValue;
            } else if (iValue instanceof Map) {
                ((Collection<Object>) newValue).addAll(((Map<String, Object>) iValue).values());
                return (RET) newValue;
            } else if (iValue instanceof String) {
                final String stringValue = (String) iValue;
                if (stringValue != null && !stringValue.isEmpty()) {
                    final String[] items = stringValue.split(",");
                    for (String s : items) {
                        ((Collection<Object>) newValue).add(s);
                    }
                }
                return (RET) newValue;
            } else if (OMultiValue.isMultiValue(iValue)) {
                // GENERIC MULTI VALUE
                for (Object s : OMultiValue.getMultiValueIterable(iValue, false)) {
                    ((Collection<Object>) newValue).add(s);
                }
                return (RET) newValue;
            }
        } else {
            return (RET) iValue;
        }
    } else if (List.class.isAssignableFrom(iFieldType)) {
        if (!(iValue instanceof List)) {
            // CONVERT IT TO LIST
            final Collection<?> newValue;
            if (type.isLink())
                newValue = new ORecordLazyList(iDocument);
            else
                newValue = new OTrackedList<Object>(iDocument);
            if (iValue instanceof Collection) {
                ((Collection<Object>) newValue).addAll((Collection<Object>) iValue);
                return (RET) newValue;
            } else if (iValue instanceof Map) {
                ((Collection<Object>) newValue).addAll(((Map<String, Object>) iValue).values());
                return (RET) newValue;
            } else if (iValue instanceof String) {
                final String stringValue = (String) iValue;
                if (stringValue != null && !stringValue.isEmpty()) {
                    final String[] items = stringValue.split(",");
                    for (String s : items) {
                        ((Collection<Object>) newValue).add(s);
                    }
                }
                return (RET) newValue;
            } else if (OMultiValue.isMultiValue(iValue)) {
                // GENERIC MULTI VALUE
                for (Object s : OMultiValue.getMultiValueIterable(iValue)) {
                    ((Collection<Object>) newValue).add(s);
                }
                return (RET) newValue;
            }
        } else {
            return (RET) iValue;
        }
    } else if (iValue instanceof Enum) {
        // ENUM
        if (Number.class.isAssignableFrom(iFieldType))
            iValue = ((Enum<?>) iValue).ordinal();
        else
            iValue = iValue.toString();
        if (!(iValue instanceof String) && !iFieldType.isAssignableFrom(iValue.getClass()))
            throw new IllegalArgumentException("Property '" + iFieldName + "' of type '" + iFieldType + "' cannot accept value of type: " + iValue.getClass());
    } else if (Date.class.isAssignableFrom(iFieldType)) {
        if (iValue instanceof String && ODatabaseRecordThreadLocal.INSTANCE.isDefined()) {
            final OStorageConfiguration config = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration();
            DateFormat formatter = config.getDateFormatInstance();
            if (((String) iValue).length() > config.dateFormat.length()) {
                // ASSUMES YOU'RE USING THE DATE-TIME FORMATTE
                formatter = config.getDateTimeFormatInstance();
            }
            try {
                Date newValue = formatter.parse((String) iValue);
                // _fieldValues.put(iFieldName, newValue);
                return (RET) newValue;
            } catch (ParseException pe) {
                final String dateFormat = ((String) iValue).length() > config.dateFormat.length() ? config.dateTimeFormat : config.dateFormat;
                throw OException.wrapException(new OQueryParsingException("Error on conversion of date '" + iValue + "' using the format: " + dateFormat), pe);
            }
        }
    }
    iValue = OType.convert(iValue, iFieldType);
    return (RET) iValue;
}
Also used : OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORecord(com.orientechnologies.orient.core.record.ORecord) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) OQueryParsingException(com.orientechnologies.orient.core.exception.OQueryParsingException) ORID(com.orientechnologies.orient.core.id.ORID) ParseException(java.text.ParseException)

Example 9 with OQueryParsingException

use of com.orientechnologies.orient.core.exception.OQueryParsingException 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 10 with OQueryParsingException

use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.

the class OSQLPredicate method extractConditionOperator.

private OQueryOperator extractConditionOperator() {
    if (!parserSkipWhiteSpaces())
        // END OF PARSING: JUST RETURN
        return null;
    if (parserGetCurrentChar() == ')')
        // FOUND ')': JUST RETURN
        return null;
    final OQueryOperator[] operators = OSQLEngine.getInstance().getRecordOperators();
    final String[] candidateOperators = new String[operators.length];
    for (int i = 0; i < candidateOperators.length; ++i) candidateOperators[i] = operators[i].keyword;
    final int operatorPos = parserNextChars(true, false, candidateOperators);
    if (operatorPos == -1) {
        parserGoBack();
        return null;
    }
    final OQueryOperator op = operators[operatorPos];
    if (op.expectsParameters) {
        // PARSE PARAMETERS IF ANY
        parserGoBack();
        parserNextWord(true, " 0123456789'\"");
        final String word = parserGetLastWord();
        final List<String> params = new ArrayList<String>();
        // CHECK FOR PARAMETERS
        if (word.length() > op.keyword.length() && word.charAt(op.keyword.length()) == OStringSerializerHelper.EMBEDDED_BEGIN) {
            int paramBeginPos = parserGetCurrentPosition() - (word.length() - op.keyword.length());
            parserSetCurrentPosition(OStringSerializerHelper.getParameters(parserText, paramBeginPos, -1, params));
        } else if (!word.equals(op.keyword))
            throw new OQueryParsingException("Malformed usage of operator '" + op.toString() + "'. Parsed operator is: " + word);
        try {
            // CONFIGURE COULD INSTANTIATE A NEW OBJECT: ACT AS A FACTORY
            return op.configure(params);
        } catch (Exception e) {
            throw OException.wrapException(new OQueryParsingException("Syntax error using the operator '" + op.toString() + "'. Syntax is: " + op.getSyntax()), e);
        }
    } else
        parserMoveCurrentPosition(+1);
    return op;
}
Also used : 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) OQueryOperator(com.orientechnologies.orient.core.sql.operator.OQueryOperator)

Aggregations

OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)13 OException (com.orientechnologies.common.exception.OException)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)2 OStorageConfiguration (com.orientechnologies.orient.core.config.OStorageConfiguration)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)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 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)2 SQLException (java.sql.SQLException)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OPair (com.orientechnologies.common.util.OPair)1 OCommandContext (com.orientechnologies.orient.core.command.OCommandContext)1