public String getItemName(int fieldIndex) { if (fieldIndex == 0) { return name; } else { return operationsChain.get(fieldIndex - 1).getValue()[0].toString(); } }
public static <K extends Comparable<K>, V> Map<K, V> convertToMap(final List<OPair<K, V>> iValues) { final HashMap<K, V> result = new HashMap<K, V>(iValues.size()); for (OPair<K, V> p : iValues) result.put(p.getKey(), p.getValue()); return result; }
private boolean isBrowsingAscendingOrder() { return !(orderedFields.size() == 1 && orderedFields.get(0).getKey().equalsIgnoreCase("@rid") && orderedFields.get(0).getValue() .equalsIgnoreCase("DESC")); }
@Override public String toString() { return key + ":" + value.getKey() + "/" + value.getValue(); }
@Override public String dumpActiveAtomicOperations() { if (!trackAtomicOperations) { activeAtomicOperations.clear(); } @SuppressWarnings("resource") final StringWriter writer = new StringWriter(); writer.append("List of active atomic operations: \r\n"); writer.append("------------------------------------------------------------------------------------------------\r\n"); for (Map.Entry<OOperationUnitId, OPair<String, StackTraceElement[]>> entry : activeAtomicOperations.entrySet()) { writer.append("Operation unit id :").append(entry.getKey().toString()).append("\r\n"); writer.append("Started at thread : ").append(entry.getValue().getKey()).append("\r\n"); writer.append("Stack trace of method which started this operation : \r\n"); StackTraceElement[] stackTraceElements = entry.getValue().getValue(); for (int i = 1; i < stackTraceElements.length; i++) { writer.append("\tat ").append(stackTraceElements[i].toString()).append("\r\n"); } writer.append("\r\n\r\n"); } writer.append("-------------------------------------------------------------------------------------------------\r\n"); return writer.toString(); }
@Override public String toString() { final StringBuilder buffer = new StringBuilder(128); final String root = getRoot(); if (root != null) buffer.append(root); if (operationsChain != null) { for (OPair<OSQLMethodRuntime, Object[]> op : operationsChain) { buffer.append('.'); buffer.append(op.getKey()); if (op.getValue() != null) { final Object[] values = op.getValue(); buffer.append('('); int i = 0; for (Object v : values) { if (i++ > 0) buffer.append(','); buffer.append(v); } buffer.append(')'); } } } return buffer.toString(); }
boolean canBeUsedByOrderBy(OIndex<?> index, List<OPair<String, String>> orderedFields) { if (orderedFields.isEmpty()) return false; if (!index.supportsOrderedIterations()) return false; final OIndexDefinition definition = index.getDefinition(); final List<String> fields = definition.getFields(); final int endIndex = Math.min(fields.size(), orderedFields.size()); final String firstOrder = orderedFields.get(0).getValue(); for (int i = 0; i < endIndex; i++) { final OPair<String, String> pair = orderedFields.get(i); if (!firstOrder.equals(pair.getValue())) return false; final String orderFieldName = orderedFields.get(i).getKey(); final String indexFieldName = fields.get(i); if (!orderFieldName.equals(indexFieldName)) return false; } return true; }
remainingStarts.add(item.getValue());
private boolean handleIncrementEntries(final ODocument record) { boolean updated = false; // BIND VALUES TO INCREMENT if (!incrementEntries.isEmpty()) { for (OPair<String, Object> entry : incrementEntries) { final Number prevValue = record.field(entry.getKey()); Number current; if (entry.getValue() instanceof OSQLFilterItem) current = (Number) ((OSQLFilterItem) entry.getValue()).getValue(record, null, context); else if (entry.getValue() instanceof Number) current = (Number) entry.getValue(); else throw new OCommandExecutionException("Increment value is not a number (" + entry.getValue() + ")"); if (prevValue == null) // NO PREVIOUS VALUE: CONSIDER AS 0 record.field(entry.getKey(), current); else // COMPUTING INCREMENT record.field(entry.getKey(), OType.increment(prevValue, current)); } updated = true; } return updated; }
public Object transformValue(final OIdentifiable iRecord, final OCommandContext iContext, Object ioResult) { if (ioResult != null && operationsChain != null) { // APPLY OPERATIONS FOLLOWING THE STACK ORDER OSQLMethodRuntime method = null; for (OPair<OSQLMethodRuntime, Object[]> op : operationsChain) { method = op.getKey(); // DON'T PASS THE CURRENT RECORD TO FORCE EVALUATING TEMPORARY RESULT method.setParameters(op.getValue(), true); ioResult = method.execute(ioResult, iRecord, ioResult, iContext); } } return ioResult; }
@Override public int compare(final Object o1, final Object o2) { final ODocument doc1 = ((OIdentifiable) o1).getRecord(); final ODocument doc2 = ((OIdentifiable) o2).getRecord(); final Object value1 = doc1.field(columnSorting.getKey()); final Object value2 = doc2.field(columnSorting.getKey()); final boolean ascending = columnSorting.getValue(); final int result; if (value2 == null) result = 1; else if (value1 == null) result = 0; else if (value1 instanceof Comparable) result = ((Comparable) value1).compareTo(value2); else result = value1.toString().compareTo(value2.toString()); return ascending ? result : result * -1; } });
private Object extractValue(ODocument record, OPair<String, Object> entry) { Object value = entry.getValue(); if (value instanceof OSQLFilterItem) value = ((OSQLFilterItem) value).getValue(record, null, context); else if (value instanceof OCommandRequest) value = ((OCommandRequest) value).execute(record, null, context); if (value instanceof OIdentifiable && ((OIdentifiable) value).getIdentity().isPersistent()) // USE ONLY THE RID TO AVOID CONCURRENCY PROBLEM WITH OLD VERSIONS value = ((OIdentifiable) value).getIdentity(); return value; }
protected int handleStatus(final byte iResult, final int iClientTxId) throws IOException { if (iResult == OChannelBinaryProtocol.RESPONSE_STATUS_OK || iResult == OChannelBinaryProtocol.PUSH_DATA) { return iClientTxId; } else if (iResult == OChannelBinaryProtocol.RESPONSE_STATUS_ERROR) { final List<OPair<String, String>> exceptions = new ArrayList<OPair<String, String>>(); // EXCEPTION while (readByte() == 1) { final String excClassName = readString(); final String excMessage = readString(); exceptions.add(new OPair<String, String>(excClassName, excMessage)); } byte[] serializedException = null; if (srvProtocolVersion >= 19) serializedException = readBytes(); Exception previous = null; if (serializedException != null && serializedException.length > 0) throwSerializedException(serializedException); for (int i = exceptions.size() - 1; i > -1; --i) { previous = createException(exceptions.get(i).getKey(), exceptions.get(i).getValue(), previous); } if (previous != null) { throw new RuntimeException(previous); } else throw new ONetworkProtocolException("Network response error"); } else { // PROTOCOL ERROR // close(); throw new ONetworkProtocolException("Error on reading response from the server"); } }
final String ordering = field.getValue();
/** * Execute the command and return the ODocument object created. */ public Object execute(final Map<Object, Object> iArgs) { if (clazz == null) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); // CREATE VERTEX DOES NOT HAVE TO BE IN TX final OVertex vertex = getDatabase().newVertex(clazz); if (fields != null) // EVALUATE FIELDS for (final OPair<String, Object> f : fields) { if (f.getValue() instanceof OSQLFunctionRuntime) f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context)); } OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context); if (content != null) ((ODocument)vertex.getRecord()).merge(content, true, false); if (clusterName != null) vertex.save(clusterName); else vertex.save(); return vertex.getRecord(); }
@Override public OrientEdge createWrapper(final Object iObject) { if (iObject instanceof OrientEdge) return (OrientEdge) iObject; final OIdentifiable rec = (OIdentifiable) iObject; final ODocument value = rec.getRecord(); if (value == null || value.getSchemaClass() == null) return null; final OrientEdge edge; if (value.getSchemaClass().isSubClassOf(OrientVertex.CLASS_NAME)) { // DIRECT VERTEX, CREATE DUMMY EDGE if (connection.getKey() == Direction.OUT) edge = new OrientEdge(this.vertex.graph, this.vertex.getIdentity(), rec.getIdentity(), connection.getValue()); else edge = new OrientEdge(this.vertex.graph, rec.getIdentity(), this.vertex.getIdentity(), connection.getValue()); } else if (value.getSchemaClass().isSubClassOf(OrientEdge.CLASS_NAME)) { // EDGE edge = new OrientEdge(this.vertex.graph, rec.getIdentity()); } else throw new IllegalStateException("Invalid content found between connections:" + value); if (this.vertex.graph.isUseVertexFieldsForEdgeLabels() || edge.isLabeled(labels)) return edge; return null; }