public static void addEdgeColumn(SqlgGraph sqlgGraph, String schema, String prefixedTable, Map<String, PropertyType> column, ListOrderedSet<String> primaryKeys) { for (Map.Entry<String, PropertyType> stringPropertyTypeEntry : column.entrySet()) { addEdgeColumn(sqlgGraph, schema, prefixedTable, stringPropertyTypeEntry, primaryKeys); } }
TopologyManager.updateVertexLabelPartitionTypeAndExpression( sqlgGraph, this.schema, this.getPartitionExpression()); } else { TopologyManager.updateEdgeLabelPartitionTypeAndExpression( sqlgGraph, this.schema, Preconditions.checkState(child.fromExpression() != null); Preconditions.checkState(child.toExpression() != null); TopologyManager.addVertexLabelPartition( sqlgGraph, this.schema, } else { Preconditions.checkState(child.inExpression() != null); TopologyManager.addVertexLabelPartition( sqlgGraph, this.schema, Preconditions.checkState(child.fromExpression() != null); Preconditions.checkState(child.toExpression() != null); TopologyManager.addEdgeLabelPartition( sqlgGraph, this.schema, } else {
@SuppressWarnings("OptionalGetWithoutIsPresent") static GlobalUniqueIndex createGlobalUniqueIndex(SqlgGraph sqlgGraph, Topology topology, String globalUniqueIndexName, Set<PropertyColumn> properties) { //all PropertyColumns must be for the same PropertyType PropertyType propertyType = properties.iterator().next().getPropertyType(); Map<String, PropertyType> valueColumn = new HashMap<>(); valueColumn.put(GLOBAL_UNIQUE_INDEX_RECORD_ID, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME, PropertyType.STRING); valueColumn.put(GLOBAL_UNIQUE_INDEX_VALUE, propertyType); VertexLabel vertexLabel = topology.getGlobalUniqueIndexSchema().ensureVertexLabelExist(globalUniqueIndexName, valueColumn); PropertyColumn valuePropertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_VALUE).get(); PropertyColumn recordIdColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_RECORD_ID).get(); PropertyColumn propertyColumn = vertexLabel.getProperty(GLOBAL_UNIQUE_INDEX_PROPERTY_NAME).get(); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Collections.singletonList(valuePropertyColumn)); vertexLabel.ensureIndexExists(IndexType.UNIQUE, Arrays.asList(recordIdColumn, propertyColumn)); GlobalUniqueIndex globalUniqueIndex = new GlobalUniqueIndex(topology, globalUniqueIndexName, properties); topology.getGlobalUniqueIndexSchema().globalUniqueIndexes.put(globalUniqueIndex.getName(),globalUniqueIndex); TopologyManager.addGlobalUniqueIndex(sqlgGraph, globalUniqueIndexName, properties); globalUniqueIndex.committed = false; return globalUniqueIndex; }
String sql = this.sqlDialect.sqlgCreateTopologyGraph(); statement.execute(sql); TopologyManager.addGraph(this.sqlgGraph, version); oldVersion = version; List<Vertex> graphVertices = traversalSource.V().hasLabel(SQLG_SCHEMA + "." + Topology.SQLG_SCHEMA_GRAPH).toList(); if (graphVertices.isEmpty()) { TopologyManager.addGraph(this.sqlgGraph, version); oldVersion = version; } else { oldVersion = TopologyManager.updateGraph(this.sqlgGraph, version);
TopologyManager.addSchema(this.sqlgGraph, schemaName); List<String> primaryKeys = this.sqlDialect.getPrimaryKeys(metadata, tblCat, schema, table); if (primaryKeys.size() == 1 && primaryKeys.get(0).equals(Topology.ID)) { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, new ListOrderedSet<>()); } else { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, identifiers); } else { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, ListOrderedSet.listOrderedSet(primaryKeys)); if (idxs != null) { for (IndexRef ir : idxs) { TopologyManager.addIndex(sqlgGraph, schema, label, true, ir.getIndexName(), ir.getIndexType(), ir.getColumns()); Vertex edgeVertex; if (hasIDPrimaryKey(primaryKeys)) { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), new ListOrderedSet<>(), PartitionType.NONE, null); } else { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), identifiers, PartitionType.NONE, null); } else { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), ListOrderedSet.listOrderedSet(primaryKeys), PartitionType.NONE, null); TopologyManager.addLabelToEdge(this.sqlgGraph, edgeVertex, schema, table, true, foreignKey); } else if (column.endsWith(Topology.OUT_VERTEX_COLUMN_END)) { TopologyManager.addLabelToEdge(this.sqlgGraph, edgeVertex, schema, table, false, foreignKey); TopologyManager.addEdgeColumn(this.sqlgGraph, schema, table, columns, ListOrderedSet.listOrderedSet(primaryKeys));
/** * Create a list partition on an {@link AbstractLabel} * * @param sqlgGraph * @param abstractLabel * @param name * @param in * @return */ static Partition createListPartition(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String name, String in) { Preconditions.checkArgument(!abstractLabel.getSchema().isSqlgSchema(), "createListPartition may not be called for \"%s\"", Topology.SQLG_SCHEMA); Partition partition = new Partition(sqlgGraph, abstractLabel, name, in, PartitionType.NONE, null); partition.createListPartitionOnDb(); if (abstractLabel instanceof VertexLabel) { TopologyManager.addVertexLabelPartition( sqlgGraph, abstractLabel.getSchema().getName(), abstractLabel.getName(), name, in, PartitionType.NONE, null); } else { TopologyManager.addEdgeLabelPartition(sqlgGraph, abstractLabel, name, in, PartitionType.NONE, null); } partition.committed = false; return partition; }
String partitionExpression) { BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); addEdgeLabelPartition( sqlgGraph, abstractLabel.getSchema().getName(), BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); addEdgeLabel(sqlgGraph, schema, prefixedTable, foreignKeyOut, foreignKeyIn, columns, identifiers, PartitionType.NONE, null); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology();
private static Partition createListSubPartitionWithPartition( SqlgGraph sqlgGraph, Partition parentPartition, String name, String in, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(!parentPartition.getAbstractLabel().getSchema().isSqlgSchema(), "createRangeSubPartitionWithPartition may not be called for \"%s\"", Topology.SQLG_SCHEMA); Partition partition = new Partition(sqlgGraph, parentPartition, name, in, partitionType, partitionExpression); partition.createListPartitionOnDb(); TopologyManager.addSubPartition(sqlgGraph, partition); partition.committed = false; return partition; }
String partitionExpression) { Vertex edgeVertex = addEdgeLabel(sqlgGraph, prefixedTable, columns, identifiers, partitionType, partitionExpression); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology();
if (!this.sqlDialect.isSystemIndex(lastIndexName)) { if (!Schema.GLOBAL_UNIQUE_INDEX_SCHEMA.equals(schema)) { TopologyManager.addIndex(sqlgGraph, schema, label, isVertex, lastIndexName, lastIndexType, lastColumns); TopologyManager.addIndex(sqlgGraph, schema, label, isVertex, lastIndexName, lastIndexType, lastColumns);
@SuppressWarnings("OptionalGetWithoutIsPresent") private EdgeLabel createEdgeLabel( final String edgeLabelName, final VertexLabel outVertexLabel, final VertexLabel inVertexLabel, final Map<String, PropertyType> columns, final ListOrderedSet<String> identifiers) { Preconditions.checkArgument(this.topology.isSqlWriteLockHeldByCurrentThread(), "Lock must be held by the thread to call createEdgeLabel"); Preconditions.checkArgument(!edgeLabelName.startsWith(EDGE_PREFIX), "edgeLabelName may not start with " + EDGE_PREFIX); Preconditions.checkState(!this.isSqlgSchema(), "createEdgeLabel may not be called for \"%s\"", SQLG_SCHEMA); Schema inVertexSchema = inVertexLabel.getSchema(); //Edge may not already exist. Preconditions.checkState(!getEdgeLabel(edgeLabelName).isPresent(), "BUG: Edge \"%s\" already exists!", edgeLabelName); SchemaTable foreignKeyOut = SchemaTable.of(this.name, outVertexLabel.getLabel()); SchemaTable foreignKeyIn = SchemaTable.of(inVertexSchema.name, inVertexLabel.getLabel()); TopologyManager.addEdgeLabel(this.sqlgGraph, this.getName(), EDGE_PREFIX + edgeLabelName, foreignKeyOut, foreignKeyIn, columns, identifiers); if (this.sqlgGraph.getSqlDialect().needsSchemaCreationPrecommit()) { try { this.sqlgGraph.tx().getConnection().commit(); } catch (SQLException e) { throw new RuntimeException(e); } } return outVertexLabel.addEdgeLabel(edgeLabelName, inVertexLabel, columns, identifiers); }
static Schema createSchema(SqlgGraph sqlgGraph, Topology topology, String name) { Schema schema = new Schema(topology, name); Preconditions.checkArgument(!name.equals(SQLG_SCHEMA) && !sqlgGraph.getSqlDialect().getPublicSchema().equals(name), "createSchema may not be called for 'sqlg_schema' or 'public'"); schema.createSchemaOnDb(); TopologyManager.addSchema(sqlgGraph, name); schema.committed = false; return schema; }
public void ensurePropertiesExist(Map<String, PropertyType> columns) { for (Map.Entry<String, PropertyType> column : columns.entrySet()) { if (!this.properties.containsKey(column.getKey())) { Preconditions.checkState(!this.schema.isSqlgSchema(), "schema may not be %s", SQLG_SCHEMA); if (!this.uncommittedProperties.containsKey(column.getKey())) { this.schema.getTopology().lock(); if (!getProperty(column.getKey()).isPresent()) { TopologyManager.addVertexColumn(this.sqlgGraph, this.schema.getName(), VERTEX_PREFIX + getLabel(), column); addColumn(this.schema.getName(), VERTEX_PREFIX + getLabel(), ImmutablePair.of(column.getKey(), column.getValue())); PropertyColumn propertyColumn = new PropertyColumn(this, column.getKey(), column.getValue()); propertyColumn.setCommitted(false); this.uncommittedProperties.put(column.getKey(), propertyColumn); this.getSchema().getTopology().fire(propertyColumn, "", TopologyChangeAction.CREATE); } } } } }
public static void addEdgeLabelPartition( SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String name, String in, PartitionType partitionType, String partitionExpression) { addEdgeLabelPartition( sqlgGraph, abstractLabel.getSchema().getName(), abstractLabel.getName(), name, in, partitionType, partitionExpression ); }
public void ensureEdgeVertexLabelExist(Direction direction, VertexLabel vertexLabel) { //if the direction is OUT then the vertexLabel must be in the same schema as the edgeLabel (this) if (direction == Direction.OUT) { Preconditions.checkState(vertexLabel.getSchema().equals(getSchema()), "For Direction.OUT the VertexLabel must be in the same schema as the edge. Found %s and %s", vertexLabel.getSchema().getName(), getSchema().getName()); } SchemaTable foreignKey = SchemaTable.of(vertexLabel.getSchema().getName(), vertexLabel.getLabel() + (direction == Direction.IN ? Topology.IN_VERTEX_COLUMN_END : Topology.OUT_VERTEX_COLUMN_END)); if (!foreignKeysContains(direction, vertexLabel)) { //Make sure the current thread/transaction owns the lock Schema schema = this.getSchema(); schema.getTopology().lock(); if (!foreignKeysContains(direction, vertexLabel)) { TopologyManager.addLabelToEdge(this.sqlgGraph, this.getSchema().getName(), EDGE_PREFIX + getLabel(), direction == Direction.IN, foreignKey); if (direction == Direction.IN) { this.uncommittedInVertexLabels.add(vertexLabel); vertexLabel.addToUncommittedInEdgeLabels(schema, this); } else { this.uncommittedOutVertexLabels.add(vertexLabel); vertexLabel.addToUncommittedOutEdgeLabels(schema, this); } SchemaTable vertexSchemaTable = SchemaTable.of(vertexLabel.getSchema().getName(), vertexLabel.getLabel()); addEdgeForeignKey(schema.getName(), EDGE_PREFIX + getLabel(), foreignKey, vertexSchemaTable); this.getSchema().getTopology().fire(this, vertexSchemaTable.toString(), TopologyChangeAction.ADD_IN_VERTEX_LABELTO_EDGE); } } }
loadSqlgSchemaFromInformationSchema(); String version = getBuildVersion(); TopologyManager.addGraph(this.sqlgGraph, version); stopWatch2.stop(); logger.debug("Time to upgrade sqlg from pre sqlg_schema: " + stopWatch2.toString());
TopologyManager.addSchema(this.sqlgGraph, schemaName); List<String> primaryKeys = this.sqlDialect.getPrimaryKeys(metadata, tblCat, schema, table); if (primaryKeys.size() == 1 && primaryKeys.get(0).equals(Topology.ID)) { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, new ListOrderedSet<>()); } else { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, identifiers); } else { TopologyManager.addVertexLabel(this.sqlgGraph, schema, label, columns, ListOrderedSet.listOrderedSet(primaryKeys)); if (idxs != null) { for (IndexRef ir : idxs) { TopologyManager.addIndex(sqlgGraph, schema, label, true, ir.getIndexName(), ir.getIndexType(), ir.getColumns()); Vertex edgeVertex; if (hasIDPrimaryKey(primaryKeys)) { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), new ListOrderedSet<>(), PartitionType.NONE, null); } else { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), identifiers, PartitionType.NONE, null); } else { edgeVertex = TopologyManager.addEdgeLabel(this.sqlgGraph, table, Collections.emptyMap(), ListOrderedSet.listOrderedSet(primaryKeys), PartitionType.NONE, null); TopologyManager.addLabelToEdge(this.sqlgGraph, edgeVertex, schema, table, true, foreignKey); } else if (column.endsWith(Topology.OUT_VERTEX_COLUMN_END)) { TopologyManager.addLabelToEdge(this.sqlgGraph, edgeVertex, schema, table, false, foreignKey); TopologyManager.addEdgeColumn(this.sqlgGraph, schema, table, columns, ListOrderedSet.listOrderedSet(primaryKeys));
/** * Create a list partition on an {@link AbstractLabel} * * @param sqlgGraph * @param abstractLabel * @param name * @param in * @return */ static Partition createListPartition(SqlgGraph sqlgGraph, AbstractLabel abstractLabel, String name, String in) { Preconditions.checkArgument(!abstractLabel.getSchema().isSqlgSchema(), "createListPartition may not be called for \"%s\"", Topology.SQLG_SCHEMA); Partition partition = new Partition(sqlgGraph, abstractLabel, name, in, PartitionType.NONE, null); partition.createListPartitionOnDb(); if (abstractLabel instanceof VertexLabel) { TopologyManager.addVertexLabelPartition( sqlgGraph, abstractLabel.getSchema().getName(), abstractLabel.getName(), name, in, PartitionType.NONE, null); } else { TopologyManager.addEdgeLabelPartition(sqlgGraph, abstractLabel, name, in, PartitionType.NONE, null); } partition.committed = false; return partition; }
String partitionExpression) { BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); addEdgeLabelPartition( sqlgGraph, abstractLabel.getSchema().getName(), BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology(); addEdgeLabel(sqlgGraph, schema, prefixedTable, foreignKeyOut, foreignKeyIn, columns, identifiers, PartitionType.NONE, null); BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { GraphTraversalSource traversalSource = sqlgGraph.topology();
private static Partition createListSubPartitionWithPartition( SqlgGraph sqlgGraph, Partition parentPartition, String name, String in, PartitionType partitionType, String partitionExpression) { Preconditions.checkArgument(!parentPartition.getAbstractLabel().getSchema().isSqlgSchema(), "createRangeSubPartitionWithPartition may not be called for \"%s\"", Topology.SQLG_SCHEMA); Partition partition = new Partition(sqlgGraph, parentPartition, name, in, partitionType, partitionExpression); partition.createListPartitionOnDb(); TopologyManager.addSubPartition(sqlgGraph, partition); partition.committed = false; return partition; }