@Override public Object[] getRowData() { List<Object> values = new ArrayList<>(); Object value = this.currentRow.getRight().get(this.propertyColumn.getName()); if (value == null) { value = "dummy_" + UUID.randomUUID().toString(); } values.add(value); values.add(this.currentEdge.id().toString()); values.add(this.propertyColumn.getName()); return values.toArray(); }
public static SqlgEdge of(SqlgGraph sqlgGraph, Long id, String schema, String table) { return new SqlgEdge(sqlgGraph, id, schema, table); }
void removeEdge(String schema, String table, SqlgEdge edge) { SchemaTable schemaTable = SchemaTable.of(schema, table); //check it the edge is in the newly inserted cache MetaEdge metaEdge = MetaEdge.from(schemaTable, edge.getOutVertex(), edge.getInVertex()); Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>> sqlgEdgeTripleMap = this.edgeCache.get(metaEdge); if (sqlgEdgeTripleMap != null && sqlgEdgeTripleMap.getRight().containsKey(edge)) { sqlgEdgeTripleMap.getRight().remove(edge); } else { List<SqlgEdge> edges = this.removeEdgeCache.get(schemaTable); if (edges == null) { edges = new ArrayList<>(); this.removeEdgeCache.put(schemaTable, edges); } edges.add(edge); } }
void addEdge(boolean streaming, SqlgEdge sqlgEdge, SqlgVertex outVertex, SqlgVertex inVertex, Map<String, Object> keyValueMap) { SchemaTable outSchemaTable = SchemaTable.of(outVertex.getSchema(), sqlgEdge.getTable()); SchemaTable outVertexLabelSchemaTable = SchemaTable.of(outVertex.getSchema(), outVertex.getTable()); SchemaTable inSchemaTable = SchemaTable.of(inVertex.getSchema(), inVertex.getTable()); VertexLabel outVertexLabel = sqlgGraph.getTopology().getVertexLabel(outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()))); VertexLabel inVertexLabel = sqlgGraph.getTopology().getVertexLabel(inSchemaTable.getSchema(), inSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", inSchemaTable.getSchema(), inSchemaTable.getTable()))); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(outSchemaTable.getSchema(), sqlgEdge.getTable()).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", outSchemaTable.getSchema(), sqlgEdge.getTable()))); MetaEdge metaEdge = MetaEdge.from(outSchemaTable, outVertex, inVertex); if (!streaming) { this.streamingBatchModeEdgeSchemaTable = sqlgEdge.getSchemaTablePrefixed(); sqlgEdge.setInternalPrimaryKey(RecordId.from(outSchemaTable, ++this.batchIndex));
writeColumnNames(propertyTypeValueMap, sql); if (keyValueMap.size() > 0) { sql.append(", "); writeColumnParameters(propertyTypeValueMap, sql); if (keyValueMap.size() > 0) { sql.append(", "); buildQuestionMark(sql, inVertexLabel); sql.append(", "); buildQuestionMark(sql, outVertexLabel); sql.append(")"); if (this.sqlgGraph.getSqlDialect().needsSemicolon()) { insertGlobalUniqueIndex(keyValueMap, propertyColumns);
sqlgEdge.setInternalPrimaryKey(RecordId.from(schemaTable, id++)); identifiers.add((Comparable) values.get(identifier)); sqlgEdge.setInternalPrimaryKey(RecordId.from(schemaTable, identifiers));
StringBuilder sql = new StringBuilder("SELECT\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); appendProperties(edgeLabel, sql); for (VertexLabel vertexLabel : edgeLabel.getOutVertexLabels()) { sql.append(", "); loadResultSet(resultSet);
while (edges.hasNext()) { Edge edge = edges.next(); SchemaTable schemaTableEdge = ((SqlgEdge)edge).getSchemaTablePrefixed().withOutPrefix(); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); while (edges.hasNext()) { Edge edge = edges.next(); SchemaTable schemaTableEdge = ((SqlgEdge)edge).getSchemaTablePrefixed().withOutPrefix(); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent());
void addEdge(boolean streaming, SqlgEdge sqlgEdge, SqlgVertex outVertex, SqlgVertex inVertex, Map<String, Object> keyValueMap) { SchemaTable outSchemaTable = SchemaTable.of(outVertex.getSchema(), sqlgEdge.getTable()); SchemaTable outVertexLabelSchemaTable = SchemaTable.of(outVertex.getSchema(), outVertex.getTable()); SchemaTable inSchemaTable = SchemaTable.of(inVertex.getSchema(), inVertex.getTable()); VertexLabel outVertexLabel = sqlgGraph.getTopology().getVertexLabel(outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", outVertexLabelSchemaTable.getSchema(), outVertexLabelSchemaTable.getTable()))); VertexLabel inVertexLabel = sqlgGraph.getTopology().getVertexLabel(inSchemaTable.getSchema(), inSchemaTable.getTable()).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel not found for %s.%s", inSchemaTable.getSchema(), inSchemaTable.getTable()))); EdgeLabel edgeLabel = sqlgGraph.getTopology().getEdgeLabel(outSchemaTable.getSchema(), sqlgEdge.getTable()).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel not found for %s.%s", outSchemaTable.getSchema(), sqlgEdge.getTable()))); MetaEdge metaEdge = MetaEdge.from(outSchemaTable, outVertex, inVertex); if (!streaming) { this.streamingBatchModeEdgeSchemaTable = sqlgEdge.getSchemaTablePrefixed(); sqlgEdge.setInternalPrimaryKey(RecordId.from(outSchemaTable, ++this.batchIndex));
writeColumnNames(propertyTypeValueMap, sql); if (keyValueMap.size() > 0) { sql.append(", "); writeColumnParameters(propertyTypeValueMap, sql); if (keyValueMap.size() > 0) { sql.append(", "); buildQuestionMark(sql, inVertexLabel); sql.append(", "); buildQuestionMark(sql, outVertexLabel); sql.append(")"); if (this.sqlgGraph.getSqlDialect().needsSemicolon()) { insertGlobalUniqueIndex(keyValueMap, propertyColumns);
identifiers.add((Comparable) parameterValueMap.getRight().get(identifier)); sqlgEdge.setInternalPrimaryKey(RecordId.from(SchemaTable.of(metaEdge.getSchemaTable().getSchema(), metaEdge.getSchemaTable().getTable()), identifiers)); i = 0; while (generatedKeys.next()) { sqlgEdges.get(i++).setInternalPrimaryKey(RecordId.from(metaEdge.getSchemaTable(), generatedKeys.getLong(1)));
StringBuilder sql = new StringBuilder("SELECT\n\t"); sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); appendProperties(edgeLabel, sql); for (VertexLabel vertexLabel : edgeLabel.getOutVertexLabels()) { sql.append(", "); loadResultSet(resultSet);
while (edges.hasNext()) { Edge edge = edges.next(); SchemaTable schemaTableEdge = ((SqlgEdge)edge).getSchemaTablePrefixed().withOutPrefix(); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent()); while (edges.hasNext()) { Edge edge = edges.next(); SchemaTable schemaTableEdge = ((SqlgEdge)edge).getSchemaTablePrefixed().withOutPrefix(); Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable()); Preconditions.checkState(edgeLabelOptional.isPresent());
void removeEdge(String schema, String table, SqlgEdge edge) { SchemaTable schemaTable = SchemaTable.of(schema, table); //check it the edge is in the newly inserted cache MetaEdge metaEdge = MetaEdge.from(schemaTable, edge.getOutVertex(), edge.getInVertex()); Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>> sqlgEdgeTripleMap = this.edgeCache.get(metaEdge); if (sqlgEdgeTripleMap != null && sqlgEdgeTripleMap.getRight().containsKey(edge)) { sqlgEdgeTripleMap.getRight().remove(edge); } else { List<SqlgEdge> edges = this.removeEdgeCache.get(schemaTable); if (edges == null) { edges = new ArrayList<>(); this.removeEdgeCache.put(schemaTable, edges); } edges.add(edge); } }
@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); } } } }
identifiers.add((Comparable) parameterValueMap.getRight().get(identifier)); sqlgEdge.setInternalPrimaryKey(RecordId.from(SchemaTable.of(metaEdge.getSchemaTable().getSchema(), metaEdge.getSchemaTable().getTable()), identifiers)); i = 0; while (generatedKeys.next()) { sqlgEdges.get(i++).setInternalPrimaryKey(RecordId.from(metaEdge.getSchemaTable(), generatedKeys.getLong(1)));