use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateEdge method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLCreateEdge 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);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
parserRequiredKeyword("CREATE");
parserRequiredKeyword("EDGE");
String className = null;
String tempLower = parseOptionalWord(false);
String temp = tempLower == null ? null : tempLower.toUpperCase();
while (temp != null) {
if (temp.equals("CLUSTER")) {
clusterName = parserRequiredWord(false);
} else if (temp.equals(KEYWORD_FROM)) {
from = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
} else if (temp.equals("TO")) {
to = parserRequiredWord(false, "Syntax error", " =><,\r\n", true);
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_CONTENT)) {
parseContent();
} else if (temp.equals(KEYWORD_BATCH)) {
temp = parserNextWord(true);
if (temp != null)
batch = Integer.parseInt(temp);
} else if (className == null && temp.length() > 0) {
className = tempLower;
OrientBaseGraph graph = OrientBaseGraph.getActiveGraph();
if (graph != null && graph.isUseClassForEdgeLabel()) {
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(temp);
} else {
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass("E");
}
}
temp = parseOptionalWord(true);
if (parserIsEnded())
break;
}
if (className == null) {
// ASSIGN DEFAULT CLASS
className = OrientEdgeType.CLASS_NAME;
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
}
// GET/CHECK CLASS NAME
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
edgeLabel = className;
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateVertex method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLCreateVertex parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
String className = null;
parserRequiredKeyword("CREATE");
parserRequiredKeyword("VERTEX");
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.equals("CLUSTER")) {
clusterName = parserRequiredWord(false);
} else if (temp.equals(KEYWORD_SET)) {
fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
} else if (temp.equals(KEYWORD_CONTENT)) {
parseContent();
} else if (className == null && temp.length() > 0) {
className = temp;
if (className == null)
// ASSIGN DEFAULT CLASS
className = OrientVertexType.CLASS_NAME;
// GET/CHECK CLASS NAME
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
if (className == null) {
// ASSIGN DEFAULT CLASS
className = OrientVertexType.CLASS_NAME;
// GET/CHECK CLASS NAME
clazz = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(className);
if (clazz == null)
throw new OCommandSQLParsingException("Class '" + className + "' was not found");
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText 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.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateFunction method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLCreateFunction parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
init((OCommandRequestText) iRequest);
parserRequiredKeyword("CREATE");
parserRequiredKeyword("FUNCTION");
name = parserNextWord(false);
code = OIOUtils.getStringContent(parserNextWord(false));
String temp = parseOptionalWord(true);
while (temp != null) {
if (temp.equals("IDEMPOTENT")) {
parserNextWord(false);
idempotent = Boolean.parseBoolean(parserGetLastWord());
} else if (temp.equals("LANGUAGE")) {
parserNextWord(false);
language = parserGetLastWord();
} else if (temp.equals("PARAMETERS")) {
parserNextWord(false);
parameters = new ArrayList<String>();
OStringSerializerHelper.getCollection(parserGetLastWord(), 0, parameters);
if (parameters.size() == 0)
throw new OCommandExecutionException("Syntax Error. Missing function parameter(s): " + getSyntax());
}
temp = parserOptionalWord(true);
if (parserIsEnded())
break;
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateProperty method parse.
public OCommandExecutorSQLCreateProperty parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
queryText = preParse(queryText, iRequest);
textRequest.setText(queryText);
init((OCommandRequestText) iRequest);
final StringBuilder word = new StringBuilder();
int oldPos = 0;
int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_CREATE))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_CREATE + " not found", parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_PROPERTY))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_PROPERTY + " not found", parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Expected <class>.<property>", parserText, oldPos);
String[] parts = split(word);
if (parts.length != 2)
throw new OCommandSQLParsingException("Expected <class>.<property>", parserText, oldPos);
className = decodeClassName(parts[0]);
if (className == null)
throw new OCommandSQLParsingException("Class not found", parserText, oldPos);
fieldName = decodeClassName(parts[1]);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Missed property type", parserText, oldPos);
if ("IF".equalsIgnoreCase(word.toString())) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Missed property type", parserText, oldPos);
if (!"NOT".equalsIgnoreCase(word.toString())) {
throw new OCommandSQLParsingException("Expected NOT EXISTS after IF", parserText, oldPos);
}
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Missed property type", parserText, oldPos);
if (!"EXISTS".equalsIgnoreCase(word.toString())) {
throw new OCommandSQLParsingException("Expected EXISTS after IF NOT", parserText, oldPos);
}
this.ifNotExists = true;
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
}
type = OType.valueOf(word.toString());
// Use a REGEX for the rest because we know exactly what we are looking for.
// If we are in strict mode, the parser took care of strict matching.
String rest = parserText.substring(pos).trim();
String pattern = "(`[^`]*`|[^\\(]\\S*)?\\s*(\\(.*\\))?\\s*(UNSAFE)?";
Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = r.matcher(rest.trim());
if (m.matches()) {
// Linked Type / Class
if (m.group(1) != null && !m.group(1).equalsIgnoreCase("UNSAFE")) {
linked = m.group(1);
if (linked.startsWith("`") && linked.endsWith("`") && linked.length() > 1) {
linked = linked.substring(1, linked.length() - 1);
}
}
// Attributes
if (m.group(2) != null) {
String raw = m.group(2);
String atts = raw.substring(1, raw.length() - 1);
processAtts(atts);
}
// UNSAFE
if (m.group(3) != null) {
this.unsafe = true;
}
} else {
// Syntax Error
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
Aggregations