private boolean isBrowsingAscendingOrder() { return !(orderedFields.size() == 1 && orderedFields.get(0).getKey().equalsIgnoreCase("@rid") && orderedFields.get(0).getValue() .equalsIgnoreCase("DESC")); }
private boolean isRidOnlySort() { if (parsedTarget.getTargetClasses() != null && this.orderedFields.size() == 1 && this.orderedFields.get(0).getKey() .toLowerCase(Locale.ENGLISH).equals("@rid")) { if (this.target != null && target instanceof ORecordIteratorClass) { return true; } } return false; }
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; }
@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(); }
/** * Check whether or not this filter item is chain of fields (e.g. "field1.field2.field3"). Return true if filter item contains * only field projections operators, if field item contains any other projection operator the method returns false. When filter * item does not contains any chain operator, it is also field chain consist of one field. * * @return whether or not this filter item can be represented as chain of fields. */ public boolean isFieldChain() { if (operationsChain == null) { return true; } for (OPair<OSQLMethodRuntime, Object[]> pair : operationsChain) { if (!pair.getKey().getMethod().getName().equals(OSQLMethodField.NAME)) { return false; } } return true; }
@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(); }
@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; } });
public boolean filter(final OEdge iObject) { if (targetVertex != null && !targetVertex.equals(iObject.getVertex(connection.getKey().opposite()))) return false; return iObject.isLabeled(labels); }
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; }
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; }
private boolean handleRemoveEntries(ODocument record) { boolean updated = false; if (!removeEntries.isEmpty()) { // REMOVE FIELD IF ANY for (OPair<String, Object> entry : removeEntries) { Object value = extractValue(record, entry); if (value == EMPTY_VALUE) { record.removeField(entry.getKey()); updated = true; } else { final Object fieldValue = record.field(entry.getKey()); if (fieldValue instanceof Collection<?>) { updated = removeFromCollection(updated, value, (Collection<?>) fieldValue); } else if (fieldValue instanceof Map<?, ?>) { updated = removeFromMap(updated, value, (Map<?, ?>) fieldValue); } else if (fieldValue instanceof ORidBag) { updated = removeFromBag(record, updated, value, (ORidBag) fieldValue); } } } } return updated; }
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; }
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"); } }
public boolean filter(final OrientEdge iObject) { if (targetVertex != null && !targetVertex.equals(iObject.getVertex(connection.getKey().opposite()))) return false; return this.sourceVertex.settings.isUseVertexFieldsForEdgeLabels() || iObject.isLabeled(labels); }
@Override public OIdentifiable getGraphElementRecord(final Object iObject) { final ORecord rec = ((OIdentifiable) iObject).getRecord(); if (rec == null || !(rec instanceof ODocument)) return null; final ODocument value = (ODocument) rec; final OIdentifiable v; OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(value); if (immutableClass.isVertexType()) { // DIRECT VERTEX v = value; } else if (immutableClass.isEdgeType()) { // EDGE if (vertex.settings.isUseVertexFieldsForEdgeLabels() || OrientEdge.isLabeled(OrientEdge.getRecordLabel(value), iLabels)) v = OrientEdge.getConnection(value, connection.getKey().opposite()); else v = null; } else throw new IllegalStateException("Invalid content found between connections: " + value); return v; }
if (fieldRecord.getSchemaClass().isSubClassOf(CLASS_NAME)) { if (connection.getKey() == Direction.OUT) toAdd = new OrientEdge(graph, doc, fieldRecord, connection.getValue());
@Override public Vertex createWrapper(final Object iObject) { if (iObject instanceof OrientVertex) return (OrientVertex) iObject; final ODocument value = ((OIdentifiable) iObject).getRecord(); final OrientVertex v; if (value.getSchemaClass().isSubClassOf(OrientVertex.CLASS_NAME)) { // DIRECT VERTEX v = new OrientVertex(vertex.graph, value); } else if (value.getSchemaClass().isSubClassOf(OrientEdge.CLASS_NAME)) { // EDGE if (vertex.graph.isUseVertexFieldsForEdgeLabels() || OrientEdge.isLabeled(OrientEdge.getRecordLabel(value), iLabels)) v = new OrientVertex(vertex.graph, OrientEdge.getConnection(value, connection.getKey().opposite())); else v = null; } else throw new IllegalStateException("Invalid content found between connections:" + value); return v; }
OrientEdge.getRecordLabel(fieldRecord), iLabels)) { final OIdentifiable vertexDoc = OrientEdge.getConnection( fieldRecord, connection.getKey().opposite()); if (vertexDoc == null) { fieldRecord.reload(); "Cannot load edge " + fieldRecord + " to get the " + connection.getKey().opposite() + " vertex"); return;
@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; }