use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.
the class OSQLTarget method extractTargets.
@SuppressWarnings("unchecked")
private boolean extractTargets() {
parserSkipWhiteSpaces();
if (parserIsEnded())
throw new OQueryParsingException("No query target found", parserText, 0);
final char c = parserGetCurrentChar();
if (c == '$') {
targetVariable = parserRequiredWord(false, "No valid target");
targetVariable = targetVariable.substring(1);
} else if (c == OStringSerializerHelper.LINK || Character.isDigit(c)) {
// UNIQUE RID
targetRecords = new ArrayList<OIdentifiable>();
((List<OIdentifiable>) targetRecords).add(new ORecordId(parserRequiredWord(true, "No valid RID")));
} else if (c == OStringSerializerHelper.EMBEDDED_BEGIN) {
// SUB QUERY
final StringBuilder subText = new StringBuilder(256);
parserSetCurrentPosition(OStringSerializerHelper.getEmbedded(parserText, parserGetCurrentPosition(), -1, subText) + 1);
final OCommandSQL subCommand = new OCommandSQLResultset(subText.toString());
final OCommandExecutorSQLResultsetDelegate executor = (OCommandExecutorSQLResultsetDelegate) OCommandManager.instance().getExecutor(subCommand);
executor.setProgressListener(subCommand.getProgressListener());
executor.parse(subCommand);
OCommandContext childContext = executor.getContext();
if (childContext != null) {
childContext.setParent(context);
}
if (!(executor instanceof Iterable<?>))
throw new OCommandSQLParsingException("Sub-query cannot be iterated because doesn't implement the Iterable interface: " + subCommand);
targetQuery = subText.toString();
targetRecords = executor;
} else if (c == OStringSerializerHelper.LIST_BEGIN) {
// COLLECTION OF RIDS
final List<String> rids = new ArrayList<String>();
parserSetCurrentPosition(OStringSerializerHelper.getCollection(parserText, parserGetCurrentPosition(), rids));
targetRecords = new ArrayList<OIdentifiable>();
for (String rid : rids) ((List<OIdentifiable>) targetRecords).add(new ORecordId(rid));
parserMoveCurrentPosition(1);
} else {
while (!parserIsEnded() && (targetClasses == null && targetClusters == null && targetIndex == null && targetIndexValues == null && targetRecords == null)) {
String originalSubjectName = parserRequiredWord(false, "Target not found");
String subjectName = originalSubjectName.toUpperCase();
final String alias;
if (subjectName.equals("AS"))
alias = parserRequiredWord(true, "Alias not found");
else
alias = subjectName;
final String subjectToMatch = subjectName;
if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.CLUSTER_PREFIX)) {
// REGISTER AS CLUSTER
if (targetClusters == null)
targetClusters = new HashMap<String, String>();
final String clusterNames = subjectName.substring(OCommandExecutorSQLAbstract.CLUSTER_PREFIX.length());
if (clusterNames.startsWith("[") && clusterNames.endsWith("]")) {
final Collection<String> clusters = new HashSet<String>(3);
OStringSerializerHelper.getCollection(clusterNames, 0, clusters);
for (String cl : clusters) {
targetClusters.put(cl, cl);
}
} else
targetClusters.put(clusterNames, alias);
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.INDEX_PREFIX)) {
// REGISTER AS INDEX
targetIndex = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_PREFIX.length());
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.METADATA_PREFIX)) {
// METADATA
final String metadataTarget = subjectName.substring(OCommandExecutorSQLAbstract.METADATA_PREFIX.length());
targetRecords = new ArrayList<OIdentifiable>();
if (metadataTarget.equals(OCommandExecutorSQLAbstract.METADATA_SCHEMA)) {
((ArrayList<OIdentifiable>) targetRecords).add(new ORecordId(ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration().schemaRecordId));
} else if (metadataTarget.equals(OCommandExecutorSQLAbstract.METADATA_INDEXMGR)) {
((ArrayList<OIdentifiable>) targetRecords).add(new ORecordId(ODatabaseRecordThreadLocal.INSTANCE.get().getStorage().getConfiguration().indexMgrRecordId));
} else
throw new OQueryParsingException("Metadata element not supported: " + metadataTarget);
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.DICTIONARY_PREFIX)) {
// DICTIONARY
final String key = originalSubjectName.substring(OCommandExecutorSQLAbstract.DICTIONARY_PREFIX.length());
targetRecords = new ArrayList<OIdentifiable>();
final OIdentifiable value = ODatabaseRecordThreadLocal.INSTANCE.get().getDictionary().get(key);
if (value != null)
((List<OIdentifiable>) targetRecords).add(value);
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.INDEX_VALUES_PREFIX)) {
targetIndexValues = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_VALUES_PREFIX.length());
targetIndexValuesAsc = true;
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.INDEX_VALUES_ASC_PREFIX)) {
targetIndexValues = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_VALUES_ASC_PREFIX.length());
targetIndexValuesAsc = true;
} else if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.INDEX_VALUES_DESC_PREFIX)) {
targetIndexValues = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_VALUES_DESC_PREFIX.length());
targetIndexValuesAsc = false;
} else {
if (subjectToMatch.startsWith(OCommandExecutorSQLAbstract.CLASS_PREFIX))
// REGISTER AS CLASS
subjectName = subjectName.substring(OCommandExecutorSQLAbstract.CLASS_PREFIX.length());
// REGISTER AS CLASS
if (targetClasses == null)
targetClasses = new HashMap<String, String>();
final OClass cls = ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata().getSchema().getClass(subjectName);
if (cls == null)
throw new OCommandExecutionException("Class '" + subjectName + "' was not found in database '" + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + "'");
targetClasses.put(cls.getName(), alias);
}
}
}
return !parserIsEnded();
}
use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.
the class OCommandExecutorSQLLiveUnsubscribe method parse.
@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().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;
}
use of com.orientechnologies.orient.core.exception.OQueryParsingException in project orientdb by orientechnologies.
the class OrientJdbcStatement method execute.
@Override
public boolean execute(final String sqlCommand) throws SQLException {
// System.out.println("sqlCommand = " + sqlCommand);
if ("".equals(sqlCommand))
return false;
sql = mayCleanForSpark(sqlCommand);
if (sql.equalsIgnoreCase("select 1")) {
documents = new ArrayList<ODocument>(1);
documents.add(new ODocument().field("1", 1));
} else {
query = new OCommandSQL(sql);
try {
rawResult = executeCommand(query);
if (rawResult instanceof List<?>) {
documents = (List<ODocument>) rawResult;
} else if (rawResult instanceof OIdentifiable) {
documents = new ArrayList<ODocument>(1);
documents.add((ODocument) ((OIdentifiable) rawResult).getRecord());
} else {
return false;
}
} catch (OQueryParsingException e) {
throw new SQLSyntaxErrorException("Error while parsing query", e);
} catch (OException e) {
throw new SQLException("Error while executing query", e);
}
}
resultSet = new OrientJdbcResultSet(this, documents, resultSetType, resultSetConcurrency, resultSetHoldability);
return true;
}
Aggregations