/** Compile the filter conditions only the first time. */ public OCommandExecutorSQLResultsetAbstract parse(final OCommandRequest iRequest) { final OCommandRequestText textRequest = (OCommandRequestText) iRequest; init(textRequest); 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()); } return this; }
public OCommandExecutorSQLDropClass 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 boolean strict = getDatabase().getStorage().getConfiguration().isStrictSql(); if (strict) { this.className = ((ODropClassStatement) this.preParsedStatement).name.getStringValue(); this.unsafe = ((ODropClassStatement) this.preParsedStatement).unsafe; this.ifExists = ((ODropClassStatement) this.preParsedStatement).ifExists; } else { oldParsing((OCommandRequestText) iRequest); } } finally { textRequest.setText(originalQuery); } return this; }
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; }
public OScriptTask(final OCommandRequestText iCommand) { text = iCommand.getText(); params = iCommand.getParameters(); }
/** Execute the command remotely and get the results back. */ public Object command(final OCommandRequestText iCommand) { checkConnection(); if (!(iCommand instanceof OSerializableStream)) throw new OCommandExecutionException( "Cannot serialize the command to be executed to the server side."); OSerializableStream command = iCommand; Object result = null; final ODatabaseRecord database = ODatabaseRecordThreadLocal.INSTANCE.get(); do { OStorageRemoteThreadLocal.INSTANCE.get().commandExecuting = true; try { final OCommandRequestText aquery = iCommand; final boolean asynch = iCommand instanceof OCommandRequestAsynch; OChannelBinaryClient network = null; try { network = beginRequest(OChannelBinaryProtocol.REQUEST_COMMAND); network.writeByte((byte) (asynch ? 'a' : 's')); // ASYNC / SYNC network.writeBytes(OStreamSerializerAnyStreamable.INSTANCE.toStream(command)); } finally { endRequest(network); } try { beginResponse(network); if (asynch) { byte status; // ASYNCH: READ ONE RECORD AT TIME while ((status = network.readByte()) > 0) { final ORecordSchemaAware<?> record = (ORecordSchemaAware<?>) readIdentifiable(network); if (record == null) break; switch (status) { case 1: // PUT AS PART OF THE RESULT SET. INVOKE THE LISTENER try { if (!aquery.getResultListener().result(record)) { // EMPTY THE INPUT CHANNEL while (network.in.available() > 0) network.in.read(); break; } } catch (Throwable t) { // ABSORBE ALL THE USER EXCEPTIONS t.printStackTrace(); } database.getLevel1Cache().updateRecord(record); break; case 2: // PUT IN THE CLIENT LOCAL CACHE database.getLevel1Cache().updateRecord(record); } } } else { final byte type = network.readByte(); switch (type) { case 'n': result = null; break; case 'r': result = readIdentifiable(network); if (result instanceof ORecord<?>) database.getLevel1Cache().updateRecord((ORecordInternal<?>) result); break; case 'l': final int tot = network.readInt(); final Collection<OIdentifiable> list = new ArrayList<OIdentifiable>(); for (int i = 0; i < tot; ++i) { final OIdentifiable resultItem = readIdentifiable(network); if (resultItem instanceof ORecord<?>) database.getLevel1Cache().updateRecord((ORecordInternal<?>) resultItem); list.add(resultItem); } result = list; break; case 'a': final String value = new String(network.readBytes()); result = ORecordSerializerStringAbstract.fieldTypeFromStream( null, ORecordSerializerStringAbstract.getType(value), value); break; } } break; } finally { endResponse(network); } } catch (OException e) { // PASS THROUGH throw e; } catch (Exception e) { handleException("Error on executing command: " + iCommand, e); } finally { OStorageRemoteThreadLocal.INSTANCE.get().commandExecuting = false; } } while (true); return result; }
@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 temp = parseOptionalWord(true); while (temp != null) { if (temp.equals("CLUSTER")) { clusterName = parserRequiredWord(false); } else if (temp.equals(KEYWORD_FROM)) { from = parserRequiredWord(false, "Syntax error", " =><,\r\n"); } else if (temp.equals("TO")) { to = parserRequiredWord(false, "Syntax error", " =><,\r\n"); } else if (temp.equals(KEYWORD_SET)) { fields = new LinkedHashMap<String, Object>(); parseSetFields(clazz, fields); } else if (temp.equals(KEYWORD_CONTENT)) { parseContent(); } else if (temp.equals(KEYWORD_RETRY)) { parseRetry(); } else if (className == null && temp.length() > 0) { className = temp; clazz = ((OMetadataInternal) database.getMetadata()) .getImmutableSchemaSnapshot() .getClass(className); } temp = parseOptionalWord(true); if (parserIsEnded()) break; } if (className == null) { // ASSIGN DEFAULT CLASS className = "E"; clazz = ((OMetadataInternal) database.getMetadata()) .getImmutableSchemaSnapshot() .getClass(className); } // GET/CHECK CLASS NAME if (clazz == null) throw new OCommandSQLParsingException("Class '" + className + "' was not found"); } finally { textRequest.setText(originalQuery); } return this; }