public OSQLFilterItemParameter addParameter(final String iName) { final String name; if (iName.charAt(0) == OStringSerializerHelper.PARAMETER_NAMED) { name = iName.substring(1); // CHECK THE PARAMETER NAME IS CORRECT if (!OStringSerializerHelper.isAlphanumeric(name)) { throw new OQueryParsingException("Parameter name '" + name + "' is invalid, only alphanumeric characters are allowed"); } } else name = iName; final OSQLFilterItemParameter param = new OSQLFilterItemParameter(name); if (parameterItems == null) parameterItems = new ArrayList<OSQLFilterItemParameter>(); parameterItems.add(param); return param; }
public OSQLTarget(final String iText, final OCommandContext iContext) { super(); context = iContext; parserText = iText; parserTextUpperCase = upperCase(iText); try { empty = !extractTargets(); } 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(OCommandExecutionException ex){ throw ex; }catch (Exception e) { throw OException.wrapException(new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), e); } }
public OQueryParsingException(final String iMessage, final String iText, final int iPosition) { super(makeMessage(iPosition, iText, iMessage)); text = iText; position = iPosition; }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] iParams, OCommandContext iContext) { final Supplier<String> paramsPrettyPrint = () -> Arrays.stream(iParams).map(p -> p + " [ " + p.getClass().getName() + " ]") .collect(Collectors.joining(", ", "(", ")")); Method method = pickMethod(iParams); if (method == null) { throw new OQueryParsingException("Unable to find a function for " + name + paramsPrettyPrint.get()); } try { return method.invoke(null, iParams); } catch (ReflectiveOperationException e) { throw OException.wrapException(new OQueryParsingException("Error executing function " + name + paramsPrettyPrint.get()), e); } catch (IllegalArgumentException x) { OLogManager.instance().error(this, "Error executing function %s", x, name); return null; //if a function fails for given input, just return null to avoid breaking the query execution } }
public OSQLFilter(final String iText, final OCommandContext iContext, final String iFilterKeyword) { super(); if (iText == null) { throw new IllegalArgumentException("Filter expression is null"); } context = iContext; parserText = iText; parserTextUpperCase = iText.toUpperCase(Locale.ENGLISH); try { final int lastPos = parserGetCurrentPosition(); final String lastText = parserText; final String lastTextUpperCase = parserTextUpperCase; text(parserText.substring(lastPos)); parserText = lastText; parserTextUpperCase = lastTextUpperCase; parserMoveCurrentPosition(lastPos); } 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 e) { throw OException.wrapException(new OQueryParsingException("Error on parsing query", parserText, parserGetCurrentPosition()), e); } this.rootCondition = resetOperatorPrecedence(rootCondition); }
@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(Locale.ENGLISH).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; }
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; }
protected int parseFields() { int currentPos = 0; final StringBuilder word = new StringBuilder(); currentPos = nextWord(parserText, parserTextUpperCase, currentPos, word, true); if (!word.toString().equals(KEYWORD_TRAVERSE)) return -1; int fromPosition = parserTextUpperCase.indexOf(KEYWORD_FROM_2FIND, currentPos); if (fromPosition == -1) throw new OQueryParsingException("Missed " + KEYWORD_FROM, parserText, currentPos); Set<Object> fields = new HashSet<Object>(); final String fieldString = parserText.substring(currentPos, fromPosition).trim(); if (fieldString.length() > 0) { // EXTRACT PROJECTIONS final List<String> items = OStringSerializerHelper.smartSplit(fieldString, ','); for (String field : items) { final String fieldName = field.trim(); if (fieldName.contains("(")) fields.add(OSQLHelper.parseValue(null, fieldName, context)); else fields.add(fieldName); } } else throw new OQueryParsingException("Missed field list to cross in TRAVERSE. Use " + getSyntax(), parserText, currentPos); currentPos = fromPosition + KEYWORD_FROM.length() + 1; traverse.fields(fields); return currentPos; }
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, final Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { if (iParams.length == 0) return date; if (iParams[0] == null) return null; if (iParams[0] instanceof Number) return new Date(((Number) iParams[0]).longValue()); if (format == null) { if (iParams.length > 1) { format = new SimpleDateFormat((String) iParams[1]); format.setTimeZone(ODateHelper.getDatabaseTimeZone()); } else format = ODatabaseRecordThreadLocal.instance().get().getStorage().getConfiguration().getDateTimeFormatInstance(); if (iParams.length == 3) format.setTimeZone(TimeZone.getTimeZone(iParams[2].toString())); } try { return format.parse((String) iParams[0]); } catch (ParseException e) { throw OException.wrapException(new OQueryParsingException("Error on formatting date '" + iParams[0] + "' using the format: " + format.toPattern()), e); } }
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);
@Override protected boolean assignTarget(Map<Object, Object> iArgs) { if (!super.assignTarget(iArgs)) { if (parsedTarget.getTargetIndex() != null) { searchInIndex(); } else { throw new OQueryParsingException( "No source found in query: specify class, cluster(s), index or single record(s). Use " + getSyntax()); } } return true; }
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); throw OException.wrapException(new OQueryParsingException("Syntax error using the operator '" + op.toString() + "'. Syntax is: " + op.getSyntax()), e);
((String) iValue).length() > config.getDateFormat().length() ? config.getDateTimeFormat() : config.getDateFormat(); throw OException.wrapException( new OQueryParsingException("Error on conversion of date '" + iValue + "' using the format: " + dateFormat), pe);
throw new OQueryParsingException("No query target found", parserText, 0); .getConfiguration().getIndexMgrRecordId())); } else throw new OQueryParsingException("Metadata element not supported: " + metadataTarget);
/** * Delegates to the OQueryExecutor the query execution. */ @SuppressWarnings("unchecked") public List<T> run(final Object... iArgs) { final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.instance().get(); if (database == null) throw new OQueryParsingException("No database configured"); ((OMetadataInternal) database.getMetadata()).makeThreadLocalSchemaSnapshot(); try { setParameters(iArgs); Object o = database.getStorage().command(this); if (o instanceof List) { return (List<T>) o; } else { return (List<T>) Collections.singletonList(o); } } finally { ((OMetadataInternal) database.getMetadata()).clearThreadLocalSchemaSnapshot(); } }
public Object execute(final Map<Object, Object> iArgs) { context.beginExecution(timeoutMs, timeoutStrategy); if (!assignTarget(iArgs)) throw new OQueryParsingException("No source found in query: specify class, cluster(s) or single record(s)"); try { // BROWSE ALL THE RECORDS AND COLLECTS RESULT final List<OIdentifiable> result = traverse.execute(); for (OIdentifiable r : result) if (!handleResult(r, context)) // LIMIT REACHED break; return getResult(); } finally { request.getResultListener().end(); } }
if (arguments.length < method.getMinParams() || (method.getMaxParams() > -1 && arguments.length > method.getMaxParams())) throw new OQueryParsingException(iQueryToParse.parserText, "Syntax error: field operator '" + method.getName() + "' needs " throw new OQueryParsingException(iQueryToParse.parserText, "Syntax error: function or field operator not recognized between the supported ones: " + OSQLEngine.getMethodNames(), 0); arguments = OStringSerializerHelper.getParameters(part).toArray(); if (arguments.length + 1 < f.getMinParams() || (f.getMaxParams() > -1 && arguments.length + 1 > f.getMaxParams())) throw new OQueryParsingException(iQueryToParse.parserText, "Syntax error: function '" + f.getName() + "' needs " + (f.getMinParams() == f.getMaxParams() ? f.getMinParams() : f.getMinParams() + "-" + f.getMaxParams()) + " argument(s) while has been received " + arguments.length, 0);
clazz = database.getMetadata().getSchema().getClass(className); if (clazz == null) throw new OQueryParsingException("Class '" + className + "' was not found");
{if (true) throw new OQueryParsingException("MATCH sub-pattern with no square brackets");}