private void barrierTheHeads() { //these collections are only used for the current starts. this.heads.clear(); this.schemaTableParentIds.clear(); while (this.starts.hasNext()) { @SuppressWarnings("unchecked") Traverser.Admin<E> h = this.starts.next(); E value = h.get(); SchemaTable schemaTable = value.getSchemaTablePrefixed(); List<Traverser.Admin<E>> traverserList = this.heads.get(schemaTable); //noinspection Java8MapApi if (traverserList == null) { traverserList = new ArrayList<>(); this.heads.put(schemaTable, traverserList); } traverserList.add(h); List<Pair<RecordId.ID, Long>> parentIdList = this.schemaTableParentIds.get(schemaTable); //noinspection Java8MapApi if (parentIdList == null) { parentIdList = new ArrayList<>(); this.schemaTableParentIds.put(schemaTable, parentIdList); } parentIdList.add(Pair.of(((RecordId) value.id()).getID(), this.startIndex)); this.startIndexTraverserAdminMap.put(this.startIndex++, h); } }
private void barrierTheHeads() { //these collections are only used for the current starts. this.heads.clear(); this.schemaTableParentIds.clear(); while (this.starts.hasNext()) { @SuppressWarnings("unchecked") Traverser.Admin<E> h = this.starts.next(); E value = h.get(); SchemaTable schemaTable = value.getSchemaTablePrefixed(); List<Traverser.Admin<E>> traverserList = this.heads.get(schemaTable); //noinspection Java8MapApi if (traverserList == null) { traverserList = new ArrayList<>(); this.heads.put(schemaTable, traverserList); } traverserList.add(h); List<Pair<RecordId.ID, Long>> parentIdList = this.schemaTableParentIds.get(schemaTable); //noinspection Java8MapApi if (parentIdList == null) { parentIdList = new ArrayList<>(); this.schemaTableParentIds.put(schemaTable, parentIdList); } parentIdList.add(Pair.of(((RecordId) value.id()).getID(), this.startIndex)); this.startIndexTraverserAdminMap.put(this.startIndex++, h); } }
@Override public void flushRemovedEdges(SqlgGraph sqlgGraph, Map<SchemaTable, List<SqlgEdge>> removeEdgeCache) { if (!removeEdgeCache.isEmpty()) { //split the list of edges, postgres existVertexLabel a 2 byte limit in the in clause for (Map.Entry<SchemaTable, List<SqlgEdge>> schemaEdges : removeEdgeCache.entrySet()) { SchemaTable schemaTable = schemaEdges.getKey(); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(schemaTable.getSchema(), schemaTable.getTable()) .orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", schemaTable.getSchema(), schemaTable.getTable()))); //TODO refacor to remove looping. List<RecordId.ID> ids = new ArrayList<>(); for (SqlgEdge edge : schemaEdges.getValue()) { ids.add(((RecordId) edge.id()).getID()); } String sql = drop(edgeLabel, ids); if (logger.isDebugEnabled()) { logger.debug(sql); } Connection conn = sqlgGraph.tx().getConnection(); try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { preparedStatement.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } } } }
@Override public void flushRemovedEdges(SqlgGraph sqlgGraph, Map<SchemaTable, List<SqlgEdge>> removeEdgeCache) { if (!removeEdgeCache.isEmpty()) { //split the list of edges, postgres existVertexLabel a 2 byte limit in the in clause for (Map.Entry<SchemaTable, List<SqlgEdge>> schemaEdges : removeEdgeCache.entrySet()) { SchemaTable schemaTable = schemaEdges.getKey(); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(schemaTable.getSchema(), schemaTable.getTable()) .orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", schemaTable.getSchema(), schemaTable.getTable()))); //TODO refacor to remove looping. List<RecordId.ID> ids = new ArrayList<>(); for (SqlgEdge edge : schemaEdges.getValue()) { ids.add(((RecordId) edge.id()).getID()); } String sql = drop(edgeLabel, ids); if (logger.isDebugEnabled()) { logger.debug(sql); } Connection conn = sqlgGraph.tx().getConnection(); try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { preparedStatement.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } } } }
@Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof RecordId)) { return false; } RecordId otherRecordId = (RecordId) other; return this.schemaTable.equals(otherRecordId.getSchemaTable()) && this.id.equals(otherRecordId.getID()); }
@Override public boolean equals(Object other) { if (other == null) { return false; } if (other == this) { return true; } if (!(other instanceof RecordId)) { return false; } RecordId otherRecordId = (RecordId) other; return this.schemaTable.equals(otherRecordId.getSchemaTable()) && this.id.equals(otherRecordId.getID()); }
ids.add(((RecordId) vertex.id()).getID());
ids.add(((RecordId) vertex.id()).getID());
loadResultSet(resultSet); } else { throw new IllegalStateException(String.format("Vertex with label %s and id %s does not exist.", this.schema + "." + this.table, this.recordId.getID().toString()));
loadResultSet(resultSet); } else { throw new IllegalStateException(String.format("Vertex with label %s and id %s does not exist.", this.schema + "." + this.table, this.recordId.getID().toString()));
RecordId recordId = (RecordId) sqlgElement.id(); SchemaTable schemaTable = recordId.getSchemaTable(); RecordId.ID id = recordId.getID(); if (sqlgElement instanceof SqlgVertex) { Optional<VertexLabel> vertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId)edge.id()).getID()); if (added) { final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge)); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId)edge.id()).getID()); if (added) { final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
RecordId recordId = (RecordId) sqlgElement.id(); SchemaTable schemaTable = recordId.getSchemaTable(); RecordId.ID id = recordId.getID(); if (sqlgElement instanceof SqlgVertex) { Optional<VertexLabel> vertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable()); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId)edge.id()).getID()); if (added) { final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge)); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId)edge.id()).getID()); if (added) { final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
@Override public void write(Kryo kryo, Output output) { output.writeString(this.getSchemaTable().getSchema()); output.writeString(this.getSchemaTable().getTable()); if (hasSequenceId()) { output.writeString("s"); output.writeLong(this.getID().sequenceId); } else { output.writeString("i"); output.writeInt(getIdentifiers().size()); for (Comparable identifier : getIdentifiers()) { output.writeString((CharSequence) identifier); } } }
@Override public void write(Kryo kryo, Output output) { output.writeString(this.getSchemaTable().getSchema()); output.writeString(this.getSchemaTable().getTable()); if (hasSequenceId()) { output.writeString("s"); output.writeLong(this.getID().sequenceId); } else { output.writeString("i"); output.writeInt(getIdentifiers().size()); for (Comparable identifier : getIdentifiers()) { output.writeString((CharSequence) identifier); } } }