public Edge addEdgeWithMap(String label, Vertex inVertex, Map<String, Object> keyValues) { Object[] parameters = SqlgUtil.mapToStringKeyValues(keyValues); return addEdge(label, inVertex, parameters); }
@Override public Object[] getRowData() { List<Object> values = new ArrayList<>(); Object value = this.currentRow.get(this.propertyColumn.getName()); if (value == null) { value = "dummy_" + UUID.randomUUID().toString(); } values.add(value); values.add(this.currentVertex.id().toString()); values.add(this.propertyColumn.getName()); return values.toArray(); }
SqlgVertex putVertexIfAbsent(SqlgGraph sqlgGraph, String schema, String table, ListOrderedSet<Comparable> identifiers) { RecordId recordId = RecordId.from(SchemaTable.of(schema, table), identifiers); SqlgVertex sqlgVertex; if (this.cacheVertices) { sqlgVertex = this.vertexCache.get(recordId); if (sqlgVertex == null) { sqlgVertex = new SqlgVertex(sqlgGraph, identifiers, schema, table); this.vertexCache.put(recordId, sqlgVertex); return sqlgVertex; } } else { sqlgVertex = new SqlgVertex(sqlgGraph, identifiers, schema, table); } return sqlgVertex; }
@Override public void remove() { this.sqlgGraph.tx().readWrite(); if (this.removed) throw new IllegalStateException(String.format("Vertex with id %s was removed.", id().toString())); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode()) { this.sqlgGraph.tx().getBatchManager().removeVertex(this.schema, this.table, this); } else { //Remove all internalEdges Pair<Set<SchemaTable>, Set<SchemaTable>> foreignKeys = this.sqlgGraph.getTopology().getTableLabels(this.getSchemaTablePrefixed()); //in edges for (SchemaTable schemaTable : foreignKeys.getLeft()) { deleteEdgesWithInKey(schemaTable); } //out edges for (SchemaTable schemaTable : foreignKeys.getRight()) { deleteEdgesWithOutKey(schemaTable); } super.remove(); } }
void addVertex(boolean temporary, boolean streaming, SqlgVertex sqlgVertex, Map<String, Object> keyValueMap) { SchemaTable schemaTable = SchemaTable.of(sqlgVertex.getSchema(), sqlgVertex.getTable(), temporary); if (!streaming) { Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> pairs = this.vertexCache.get(schemaTable); this.streamingBatchModeVertexSchemaTable = sqlgVertex.getSchemaTable(); sqlgVertex.setInternalPrimaryKey(RecordId.from(schemaTable, ++this.batchIndex));
if (value == null) { if (sqlgVertex.property(column).isPresent()) { value = sqlgVertex.value(column); } else { value = null; RecordId recordId = ((RecordId) sqlgVertex.id()); if (recordId.hasSequenceId()) { preparedStatement.setLong(i, ((RecordId) sqlgVertex.id()).sequenceId()); } else { for (Comparable identifierValue : recordId.getIdentifiers()) {
preparedStatement.setLong(i++, ((RecordId) parameterValueMap.getLeft().id()).sequenceId()); } else { for (String identifier : outVertexLabel.getIdentifiers()) { ImmutablePair.of(outVertexLabel.getProperty(identifier).orElseThrow( () -> new IllegalStateException(String.format("Property for identifier %s not found", identifier)) ).getPropertyType(), parameterValueMap.getLeft().value(identifier))); preparedStatement.setLong(i, ((RecordId) parameterValueMap.getMiddle().id()).sequenceId()); } else { for (String identifier : inVertexLabel.getIdentifiers()) { ImmutablePair.of(inVertexLabel.getProperty(identifier).orElseThrow( () -> new IllegalStateException(String.format("Property for identifier %s not found", identifier)) ).getPropertyType(), parameterValueMap.getMiddle().value(identifier)));
identifiers.add((Comparable) parameterValueMap.get(identifier)); sqlgVertex.setInternalPrimaryKey(RecordId.from(SchemaTable.of(schemaTable.getSchema(), schemaTable.getTable()), identifiers)); int i = 0; while (generatedKeys.next()) { sqlgVertices.get(i++).setInternalPrimaryKey(RecordId.from(schemaTable, generatedKeys.getLong(1)));
StringBuilder sql = new StringBuilder("SELECT\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); appendProperties(vertexLabel, sql); sql.append("\nFROM\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema)); 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()));
@Override public Edge addEdge(String label, Vertex inVertex, Object... keyValues) { this.sqlgGraph.tx().readWrite(); boolean streaming = this.sqlgGraph.getSqlDialect().supportsBatchMode() && (this.sqlgGraph.tx().isInStreamingBatchMode() || this.sqlgGraph.tx().isInStreamingWithLockBatchMode()); if (streaming) { SchemaTable streamingBatchModeEdgeLabel = this.sqlgGraph.tx().getBatchManager().getStreamingBatchModeEdgeSchemaTable(); if (streamingBatchModeEdgeLabel != null && !streamingBatchModeEdgeLabel.getTable().substring(EDGE_PREFIX.length()).equals(label)) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeEdgeLabel + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } } return addEdgeInternal(streaming, label, inVertex, keyValues); }
private void deleteEdgesWithInKey(SchemaTable edgeSchemaTable) { deleteEdges(Direction.IN, edgeSchemaTable); }
@Override public void remove() { this.sqlgGraph.tx().readWrite(); if (this.removed) throw new IllegalStateException(String.format("Vertex with id %s was removed.", id().toString())); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode()) { this.sqlgGraph.tx().getBatchManager().removeVertex(this.schema, this.table, this); } else { //Remove all internalEdges Pair<Set<SchemaTable>, Set<SchemaTable>> foreignKeys = this.sqlgGraph.getTopology().getTableLabels(this.getSchemaTablePrefixed()); //in edges for (SchemaTable schemaTable : foreignKeys.getLeft()) { deleteEdgesWithInKey(schemaTable); } //out edges for (SchemaTable schemaTable : foreignKeys.getRight()) { deleteEdgesWithOutKey(schemaTable); } super.remove(); } }
void addVertex(boolean temporary, boolean streaming, SqlgVertex sqlgVertex, Map<String, Object> keyValueMap) { SchemaTable schemaTable = SchemaTable.of(sqlgVertex.getSchema(), sqlgVertex.getTable(), temporary); if (!streaming) { Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> pairs = this.vertexCache.get(schemaTable); this.streamingBatchModeVertexSchemaTable = sqlgVertex.getSchemaTable(); sqlgVertex.setInternalPrimaryKey(RecordId.from(schemaTable, ++this.batchIndex));
if (value == null) { if (sqlgVertex.property(column).isPresent()) { value = sqlgVertex.value(column); } else { value = null; RecordId recordId = ((RecordId) sqlgVertex.id()); if (recordId.hasSequenceId()) { preparedStatement.setLong(i, ((RecordId) sqlgVertex.id()).sequenceId()); } else { for (Comparable identifierValue : recordId.getIdentifiers()) {
preparedStatement.setLong(i++, ((RecordId) parameterValueMap.getLeft().id()).sequenceId()); } else { for (String identifier : outVertexLabel.getIdentifiers()) { ImmutablePair.of(outVertexLabel.getProperty(identifier).orElseThrow( () -> new IllegalStateException(String.format("Property for identifier %s not found", identifier)) ).getPropertyType(), parameterValueMap.getLeft().value(identifier))); preparedStatement.setLong(i, ((RecordId) parameterValueMap.getMiddle().id()).sequenceId()); } else { for (String identifier : inVertexLabel.getIdentifiers()) { ImmutablePair.of(inVertexLabel.getProperty(identifier).orElseThrow( () -> new IllegalStateException(String.format("Property for identifier %s not found", identifier)) ).getPropertyType(), parameterValueMap.getMiddle().value(identifier)));
identifiers.add((Comparable) parameterValueMap.get(identifier)); sqlgVertex.setInternalPrimaryKey(RecordId.from(SchemaTable.of(schemaTable.getSchema(), schemaTable.getTable()), identifiers)); int i = 0; while (generatedKeys.next()) { sqlgVertices.get(i++).setInternalPrimaryKey(RecordId.from(schemaTable, generatedKeys.getLong(1)));
StringBuilder sql = new StringBuilder("SELECT\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); appendProperties(vertexLabel, sql); sql.append("\nFROM\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema)); 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()));
@Override public Edge addEdge(String label, Vertex inVertex, Object... keyValues) { this.sqlgGraph.tx().readWrite(); boolean streaming = this.sqlgGraph.getSqlDialect().supportsBatchMode() && (this.sqlgGraph.tx().isInStreamingBatchMode() || this.sqlgGraph.tx().isInStreamingWithLockBatchMode()); if (streaming) { SchemaTable streamingBatchModeEdgeLabel = this.sqlgGraph.tx().getBatchManager().getStreamingBatchModeEdgeSchemaTable(); if (streamingBatchModeEdgeLabel != null && !streamingBatchModeEdgeLabel.getTable().substring(EDGE_PREFIX.length()).equals(label)) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeEdgeLabel + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } } return addEdgeInternal(streaming, label, inVertex, keyValues); }
private void deleteEdgesWithOutKey(SchemaTable edgeSchemaTable) { deleteEdges(Direction.OUT, edgeSchemaTable); }