use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateClass method parse.
public OCommandExecutorSQLCreateClass 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 ODatabaseDocumentInternal database = getDatabase();
init((OCommandRequestText) iRequest);
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. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_CLASS))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_CLASS + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Expected <class>", parserText, oldPos);
className = word.toString();
if (this.preParsedStatement != null) {
className = ((OCreateClassStatement) preParsedStatement).name.getStringValue();
}
if (className == null)
throw new OCommandSQLParsingException("Expected <class>", parserText, oldPos);
oldPos = pos;
while ((pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true)) > -1) {
final String k = word.toString();
if (k.equals(KEYWORD_EXTENDS)) {
boolean hasNext;
boolean newParser = this.preParsedStatement != null;
OClass superClass;
do {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, pos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Syntax error after EXTENDS for class " + className + ". Expected the super-class name. Use " + getSyntax(), parserText, oldPos);
String superclassName = decodeClassName(word.toString());
if (!database.getMetadata().getSchema().existsClass(superclassName) && !newParser)
throw new OCommandSQLParsingException("Super-class " + word + " not exists", parserText, oldPos);
superClass = database.getMetadata().getSchema().getClass(superclassName);
superClasses.add(superClass);
hasNext = false;
for (; pos < parserText.length(); pos++) {
char ch = parserText.charAt(pos);
if (ch == ',')
hasNext = true;
else if (Character.isLetterOrDigit(ch))
break;
}
} while (hasNext);
if (newParser) {
OCreateClassStatement statement = (OCreateClassStatement) this.preParsedStatement;
List<OIdentifier> superclasses = statement.getSuperclasses();
this.superClasses.clear();
for (OIdentifier superclass : superclasses) {
String superclassName = superclass.getStringValue();
if (!database.getMetadata().getSchema().existsClass(superclassName))
throw new OCommandSQLParsingException("Super-class " + word + " not exists", parserText, oldPos);
superClass = database.getMetadata().getSchema().getClass(superclassName);
this.superClasses.add(superClass);
}
}
} else if (k.equals(KEYWORD_CLUSTER)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false, " =><()");
if (pos == -1)
throw new OCommandSQLParsingException("Syntax error after CLUSTER for class " + className + ". Expected the cluster id or name. Use " + getSyntax(), parserText, oldPos);
final String[] clusterIdsAsStrings = word.toString().split(",");
if (clusterIdsAsStrings.length > 0) {
clusterIds = new int[clusterIdsAsStrings.length];
for (int i = 0; i < clusterIdsAsStrings.length; ++i) {
if (Character.isDigit(clusterIdsAsStrings[i].charAt(0)))
// GET CLUSTER ID FROM NAME
clusterIds[i] = Integer.parseInt(clusterIdsAsStrings[i]);
else
// GET CLUSTER ID
clusterIds[i] = database.getStorage().getClusterIdByName(clusterIdsAsStrings[i]);
if (clusterIds[i] == -1)
throw new OCommandSQLParsingException("Cluster with id " + clusterIds[i] + " does not exists", parserText, oldPos);
try {
database.getStorage().getClusterById(clusterIds[i]);
} catch (Exception e) {
throw new OCommandSQLParsingException("Cluster with id " + clusterIds[i] + " does not exists", parserText, oldPos);
}
}
}
} else if (k.equals(KEYWORD_CLUSTERS)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false, " =><()");
if (pos == -1)
throw new OCommandSQLParsingException("Syntax error after CLUSTERS for class " + className + ". Expected the number of clusters. Use " + getSyntax(), parserText, oldPos);
clusters = Integer.parseInt(word.toString());
} else if (k.equals(KEYWORD_ABSTRACT)) {
clusterIds = new int[] { -1 };
} else if (k.equals(KEYWORD_IF)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false, " =><()");
if (!word.toString().equalsIgnoreCase(KEYWORD_NOT)) {
throw new OCommandSQLParsingException("Syntax error after IF for class " + className + ". Expected NOT. Use " + getSyntax(), parserText, oldPos);
}
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false, " =><()");
if (!word.toString().equalsIgnoreCase(KEYWORD_EXISTS)) {
throw new OCommandSQLParsingException("Syntax error after IF NOT for class " + className + ". Expected EXISTS. Use " + getSyntax(), parserText, oldPos);
}
ifNotExists = true;
} else
throw new OCommandSQLParsingException("Invalid keyword: " + k);
oldPos = pos;
}
if (clusterIds == null) {
final int clusterId = database.getStorage().getClusterIdByName(className);
if (clusterId > -1) {
clusterIds = new int[] { clusterId };
}
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLDelegate method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLDelegate parse(final OCommandRequest iCommand) {
if (iCommand instanceof OCommandRequestText) {
final OCommandRequestText textRequest = (OCommandRequestText) iCommand;
final String text = textRequest.getText();
if (text == null)
throw new IllegalArgumentException("Command text is null");
final String textUpperCase = upperCase(text);
delegate = OSQLEngine.getInstance().getCommand(textUpperCase);
if (delegate == null)
throw new OCommandExecutorNotFoundException("Cannot find a command executor for the command request: " + iCommand);
delegate.setContext(context);
delegate.setLimit(iCommand.getLimit());
delegate.parse(iCommand);
delegate.setProgressListener(progressListener);
if (delegate.getFetchPlan() != null)
textRequest.setFetchPlan(delegate.getFetchPlan());
} else
throw new OCommandExecutionException("Cannot find a command executor for the command request: " + iCommand);
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropIndex method parse.
public OCommandExecutorSQLDropIndex 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_DROP))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_DROP + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_INDEX))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_INDEX + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Expected index name. Use " + getSyntax(), parserText, oldPos);
name = word.toString();
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method parse.
public OCommandExecutorSQLDropProperty 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_DROP))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_DROP + " not found. Use " + getSyntax(), parserText, oldPos);
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_PROPERTY))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_PROPERTY + " not found. Use " + getSyntax(), parserText, oldPos);
pos = nextWord(parserText, parserTextUpperCase, pos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Expected <class>.<property>. Use " + getSyntax(), parserText, pos);
String[] parts = word.toString().split("\\.");
if (parts.length != 2)
throw new OCommandSQLParsingException("Expected <class>.<property>. Use " + getSyntax(), parserText, pos);
className = decodeClassName(parts[0]);
if (className == null)
throw new OCommandSQLParsingException("Class not found", parserText, pos);
fieldName = decodeClassName(parts[1]);
pos = nextWord(parserText, parserTextUpperCase, pos, word, false);
if (pos != -1) {
final String forceParameter = word.toString();
if ("FORCE".equals(forceParameter)) {
force = true;
} else if ("IF".equals(word.toString())) {
pos = nextWord(parserText, parserTextUpperCase, pos, word, false);
if ("EXISTS".equals(word.toString())) {
this.ifExists = true;
} else {
throw new OCommandSQLParsingException("Wrong query parameter, expecting EXISTS after IF", parserText, pos);
}
} else {
throw new OCommandSQLParsingException("Wrong query parameter", parserText, pos);
}
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropSequence method parse.
@Override
public OCommandExecutorSQLDropSequence parse(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 ODatabaseDocumentInternal database = getDatabase();
final StringBuilder word = new StringBuilder();
parserRequiredKeyword("DROP");
parserRequiredKeyword("SEQUENCE");
this.sequenceName = parserRequiredWord(false, "Expected <sequence name>");
} finally {
textRequest.setText(originalQuery);
}
return this;
}
Aggregations