use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateIndex method parse.
public OCommandExecutorSQLCreateIndex 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. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, 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);
indexName = decodeClassName(word.toString());
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Index type requested. Use " + getSyntax(), parserText, oldPos + 1);
if (word.toString().equals(KEYWORD_ON)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Expected class name. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
oClass = findClass(decodeClassName(word.toString()));
if (oClass == null)
throw new OCommandExecutionException("Class " + word + " not found");
pos = parserTextUpperCase.indexOf(")");
if (pos == -1) {
throw new OCommandSQLParsingException("No right bracket found. Use " + getSyntax(), parserText, oldPos);
}
final String props = parserText.substring(oldPos, pos).trim().substring(1);
List<String> propList = new ArrayList<String>();
Collections.addAll(propList, OPatternConst.PATTERN_COMMA_SEPARATED.split(props.trim()));
fields = new String[propList.size()];
propList.toArray(fields);
for (int i = 0; i < fields.length; i++) {
final String fieldName = fields[i];
final int collatePos = fieldName.toUpperCase().indexOf(" COLLATE ");
if (collatePos > 0) {
if (collates == null)
collates = new String[fields.length];
collates[i] = fieldName.substring(collatePos + " COLLATE ".length()).toLowerCase().trim();
fields[i] = fieldName.substring(0, collatePos);
} else {
if (collates != null)
collates[i] = null;
}
fields[i] = decodeClassName(fields[i]);
}
for (String propToIndex : fields) {
checkMapIndexSpecifier(propToIndex, parserText, oldPos);
propList.add(propToIndex);
}
oldPos = pos + 1;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Index type requested. Use " + getSyntax(), parserText, oldPos + 1);
} else {
if (indexName.indexOf('.') > 0) {
final String[] parts = indexName.split("\\.");
oClass = findClass(parts[0]);
if (oClass == null)
throw new OCommandExecutionException("Class " + parts[0] + " not found");
fields = new String[] { parts[1] };
}
}
indexType = OClass.INDEX_TYPE.valueOf(word.toString());
if (indexType == null)
throw new OCommandSQLParsingException("Index type is null", parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (word.toString().equals(KEYWORD_ENGINE)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
oldPos = pos;
engine = word.toString().toUpperCase();
} else
parserGoBack();
final int configPos = parserTextUpperCase.indexOf(KEYWORD_METADATA, oldPos);
if (configPos > -1) {
final String configString = parserText.substring(configPos + KEYWORD_METADATA.length()).trim();
metadataDoc = new ODocument().fromJSON(configString);
}
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos != -1 && !word.toString().equalsIgnoreCase("NULL") && !word.toString().equalsIgnoreCase(KEYWORD_METADATA)) {
final String typesString;
if (configPos > -1)
typesString = parserTextUpperCase.substring(oldPos, configPos).trim();
else
typesString = parserTextUpperCase.substring(oldPos).trim();
if (word.toString().equalsIgnoreCase("RUNTIME")) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
serializerKeyId = Byte.parseByte(word.toString());
} else {
ArrayList<OType> keyTypeList = new ArrayList<OType>();
for (String typeName : OPatternConst.PATTERN_COMMA_SEPARATED.split(typesString)) {
keyTypeList.add(OType.valueOf(typeName));
}
keyTypes = new OType[keyTypeList.size()];
keyTypeList.toArray(keyTypes);
if (fields != null && fields.length != 0 && fields.length != keyTypes.length) {
throw new OCommandSQLParsingException("Count of fields does not match with count of property types. " + "Fields: " + Arrays.toString(fields) + "; Types: " + Arrays.toString(keyTypes), parserText, oldPos);
}
}
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateLink method parse.
public OCommandExecutorSQLCreateLink 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);
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_LINK))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_LINK + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Keyword " + KEYWORD_FROM + " not found. Use " + getSyntax(), parserText, oldPos);
if (!word.toString().equalsIgnoreCase(KEYWORD_FROM)) {
// GET THE LINK NAME
linkName = word.toString();
if (OStringSerializerHelper.contains(linkName, ' '))
throw new OCommandSQLParsingException("Link name '" + linkName + "' contains not valid characters", parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
}
if (word.toString().equalsIgnoreCase(KEYWORD_TYPE)) {
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Link type missed. Use " + getSyntax(), parserText, oldPos);
linkType = OType.valueOf(word.toString().toUpperCase(Locale.ENGLISH));
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
}
if (pos == -1 || !word.toString().equals(KEYWORD_FROM))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_FROM + " 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);
sourceClassName = parts[0];
if (sourceClassName == null)
throw new OCommandSQLParsingException("Class not found", parserText, pos);
sourceField = parts[1];
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_TO))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_TO + " 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);
parts = word.toString().split("\\.");
if (parts.length != 2)
throw new OCommandSQLParsingException("Expected <class>.<property>. Use " + getSyntax(), parserText, pos);
destClassName = parts[0];
if (destClassName == null)
throw new OCommandSQLParsingException("Class not found", parserText, pos);
destField = parts[1];
pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
if (pos == -1)
return this;
if (!word.toString().equalsIgnoreCase("INVERSE"))
throw new OCommandSQLParsingException("Missed 'INVERSE'. Use " + getSyntax(), parserText, pos);
inverse = true;
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLTraverse method parse.
/**
* Compile the filter conditions only the first time.
*/
public OCommandExecutorSQLTraverse 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);
super.parse(iRequest);
final int pos = parseFields();
if (pos == -1)
throw new OCommandSQLParsingException("Traverse must have the field list. Use " + getSyntax());
parserSetCurrentPosition(pos);
int endPosition = parserText.length();
parsedTarget = OSQLEngine.getInstance().parseTarget(parserText.substring(pos, endPosition), getContext());
if (parsedTarget.parserIsEnded())
parserSetCurrentPosition(endPosition);
else
parserMoveCurrentPosition(parsedTarget.parserGetCurrentPosition());
if (!parserIsEnded()) {
parserNextWord(true);
if (parserGetLastWord().equalsIgnoreCase(KEYWORD_WHERE))
// // TODO Remove the additional management of WHERE for TRAVERSE after a while
warnDeprecatedWhere();
if (parserGetLastWord().equalsIgnoreCase(KEYWORD_WHERE) || parserGetLastWord().equalsIgnoreCase(KEYWORD_WHILE)) {
compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition(), endPosition), getContext(), KEYWORD_WHILE);
traverse.predicate(compiledFilter);
optimize();
parserSetCurrentPosition(compiledFilter.parserIsEnded() ? endPosition : compiledFilter.parserGetCurrentPosition() + parserGetCurrentPosition());
} else
parserGoBack();
}
parserSkipWhiteSpaces();
while (!parserIsEnded()) {
if (parserOptionalKeyword(KEYWORD_LIMIT, KEYWORD_SKIP, KEYWORD_OFFSET, KEYWORD_TIMEOUT, KEYWORD_MAXDEPTH, KEYWORD_STRATEGY)) {
final String w = parserGetLastWord();
if (w.equals(KEYWORD_LIMIT))
parseLimit(w);
else if (w.equals(KEYWORD_SKIP) || w.equals(KEYWORD_OFFSET))
parseSkip(w);
else if (w.equals(KEYWORD_TIMEOUT))
parseTimeout(w);
else if (w.equals(KEYWORD_MAXDEPTH))
parseMaxDepth(w);
else if (w.equals(KEYWORD_STRATEGY))
parseStrategy(w);
}
}
if (limit == 0 || limit < -1)
throw new IllegalArgumentException("Limit must be > 0 or = -1 (no limit)");
else
traverse.limit(limit);
traverse.getContext().setParent(iRequest.getContext());
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OClientConnectionManager method shutdown.
public void shutdown() {
timerTask.cancel();
final Iterator<Entry<Integer, OClientConnection>> iterator = connections.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<Integer, OClientConnection> entry = iterator.next();
final ONetworkProtocol protocol = entry.getValue().getProtocol();
if (protocol != null)
protocol.sendShutdown();
OLogManager.instance().debug(this, "Sending shutdown to thread %s", protocol);
OCommandRequestText command = entry.getValue().getData().command;
if (command != null && command.isIdempotent()) {
protocol.interrupt();
} else {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == OChannelBinaryProtocol.REQUEST_SHUTDOWN) {
continue;
}
final Socket socket;
if (protocol == null || protocol.getChannel() == null)
socket = null;
else
socket = protocol.getChannel().socket;
if (socket != null && !socket.isClosed() && !socket.isInputShutdown()) {
try {
OLogManager.instance().debug(this, "Closing input socket of thread %s", protocol);
if (// An SSLSocket will throw an UnsupportedOperationException.
!(socket instanceof SSLSocket))
socket.shutdownInput();
} catch (IOException e) {
OLogManager.instance().debug(this, "Error on closing connection of %s client during shutdown", e, entry.getValue().getRemoteAddress());
}
}
if (protocol.isAlive()) {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == -1) {
try {
OLogManager.instance().debug(this, "Closing socket of thread %s", protocol);
protocol.getChannel().close();
} catch (Exception e) {
OLogManager.instance().debug(this, "Error during chanel close at shutdown", e);
}
OLogManager.instance().debug(this, "Sending interrupt signal to thread %s", protocol);
protocol.interrupt();
}
// protocol.join();
}
}
}
}
use of com.orientechnologies.orient.core.command.OCommandRequestText in project orientdb by orientechnologies.
the class OCommandExecutorSQLAlterCluster method parse.
public OCommandExecutorSQLAlterCluster 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);
StringBuilder word = new StringBuilder();
int oldPos = 0;
int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_ALTER))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_ALTER + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1 || !word.toString().equals(KEYWORD_CLUSTER))
throw new OCommandSQLParsingException("Keyword " + KEYWORD_CLUSTER + " not found. Use " + getSyntax(), parserText, oldPos);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, false);
if (pos == -1)
throw new OCommandSQLParsingException("Expected <cluster-name>. Use " + getSyntax(), parserText, oldPos);
clusterName = word.toString();
clusterName = decodeClassName(clusterName);
final Pattern p = Pattern.compile("([0-9]*)");
final Matcher m = p.matcher(clusterName);
if (m.matches())
clusterId = Integer.parseInt(clusterName);
oldPos = pos;
pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
if (pos == -1)
throw new OCommandSQLParsingException("Missing cluster attribute to change. Use " + getSyntax(), parserText, oldPos);
final String attributeAsString = word.toString();
try {
attribute = OCluster.ATTRIBUTES.valueOf(attributeAsString.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
throw new OCommandSQLParsingException("Unknown class attribute '" + attributeAsString + "'. Supported attributes are: " + Arrays.toString(OCluster.ATTRIBUTES.values()), parserText, oldPos);
}
value = parserText.substring(pos + 1).trim();
value = decodeClassName(value);
if (attribute == ATTRIBUTES.NAME) {
//no spaces in cluster names
value = value.replaceAll(" ", "");
}
if (value.length() == 0)
throw new OCommandSQLParsingException("Missing property value to change for attribute '" + attribute + "'. Use " + getSyntax(), parserText, oldPos);
if (value.equalsIgnoreCase("null"))
value = null;
} finally {
textRequest.setText(originalQuery);
}
return this;
}
Aggregations