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;
}
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));
}
}
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;
}
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);
}
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;
}
Aggregations