public static SchemaTable from(SqlgGraph sqlgGraph, final String label) { return from(sqlgGraph, label, false); }
public static SchemaTable from(SqlgGraph sqlgGraph, final String label) { return from(sqlgGraph, label, false); }
void addToAllTables(String tableName, Map<String, PropertyType> propertyTypeMap) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); this.allTableCache.put(tableName, propertyTypeMap); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, tableName); if (schemaTable.getTable().startsWith(VERTEX_PREFIX) && !this.schemaTableForeignKeyCache.containsKey(schemaTable)) { //This happens for VertexLabel that have no edges, //else the addOutForeignKeysToVertexLabel or addInForeignKeysToVertexLabel would have already added it to the cache. this.schemaTableForeignKeyCache.put(schemaTable, Pair.of(new HashSet<>(), new HashSet<>())); } }
void addToAllTables(String tableName, Map<String, PropertyType> propertyTypeMap) { Preconditions.checkState(isSqlWriteLockHeldByCurrentThread() || isTopologyMapWriteLockHeldByCurrentThread()); this.allTableCache.put(tableName, propertyTypeMap); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, tableName); if (schemaTable.getTable().startsWith(VERTEX_PREFIX) && !this.schemaTableForeignKeyCache.containsKey(schemaTable)) { //This happens for VertexLabel that have no edges, //else the addOutForeignKeysToVertexLabel or addInForeignKeysToVertexLabel would have already added it to the cache. this.schemaTableForeignKeyCache.put(schemaTable, Pair.of(new HashSet<>(), new HashSet<>())); } }
Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> getUncommittedSchemaTableForeignKeys() { Preconditions.checkState(getTopology().isSqlWriteLockHeldByCurrentThread(), "Schema.getUncommittedSchemaTableForeignKeys must be called with the lock held"); Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> result = new HashMap<>(); for (Map.Entry<String, VertexLabel> vertexLabelEntry : this.vertexLabels.entrySet()) { String vertexQualifiedName = this.name + "." + VERTEX_PREFIX + vertexLabelEntry.getValue().getLabel(); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, vertexQualifiedName); Pair<Set<SchemaTable>, Set<SchemaTable>> uncommittedSchemaTableForeignKeys = vertexLabelEntry.getValue().getUncommittedSchemaTableForeignKeys(); if (!uncommittedSchemaTableForeignKeys.getLeft().isEmpty() || !uncommittedSchemaTableForeignKeys.getRight().isEmpty()) { result.put(schemaTable, uncommittedSchemaTableForeignKeys); } } for (Map.Entry<String, VertexLabel> uncommittedVertexLabelEntry : this.uncommittedVertexLabels.entrySet()) { String vertexQualifiedName = this.name + "." + VERTEX_PREFIX + uncommittedVertexLabelEntry.getValue().getLabel(); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, vertexQualifiedName); Pair<Set<SchemaTable>, Set<SchemaTable>> uncommittedSchemaTableForeignKeys = uncommittedVertexLabelEntry.getValue().getUncommittedSchemaTableForeignKeys(); result.put(schemaTable, uncommittedSchemaTableForeignKeys); } return result; }
Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> getUncommittedSchemaTableForeignKeys() { Preconditions.checkState(getTopology().isSqlWriteLockHeldByCurrentThread(), "Schema.getUncommittedSchemaTableForeignKeys must be called with the lock held"); Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> result = new HashMap<>(); for (Map.Entry<String, VertexLabel> vertexLabelEntry : this.vertexLabels.entrySet()) { String vertexQualifiedName = this.name + "." + VERTEX_PREFIX + vertexLabelEntry.getValue().getLabel(); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, vertexQualifiedName); Pair<Set<SchemaTable>, Set<SchemaTable>> uncommittedSchemaTableForeignKeys = vertexLabelEntry.getValue().getUncommittedSchemaTableForeignKeys(); if (!uncommittedSchemaTableForeignKeys.getLeft().isEmpty() || !uncommittedSchemaTableForeignKeys.getRight().isEmpty()) { result.put(schemaTable, uncommittedSchemaTableForeignKeys); } } for (Map.Entry<String, VertexLabel> uncommittedVertexLabelEntry : this.uncommittedVertexLabels.entrySet()) { String vertexQualifiedName = this.name + "." + VERTEX_PREFIX + uncommittedVertexLabelEntry.getValue().getLabel(); SchemaTable schemaTable = SchemaTable.from(this.sqlgGraph, vertexQualifiedName); Pair<Set<SchemaTable>, Set<SchemaTable>> uncommittedSchemaTableForeignKeys = uncommittedVertexLabelEntry.getValue().getUncommittedSchemaTableForeignKeys(); result.put(schemaTable, uncommittedSchemaTableForeignKeys); } return result; }
private Set<SchemaTableTree> calculatePathFromVertexToEdge(SchemaTableTree schemaTableTree, SchemaTable schemaTableTo, Direction direction, Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupedIds) { Set<SchemaTableTree> result = new HashSet<>(); //add the child for schemaTableTo to the tree SchemaTableTree schemaTableTree1 = schemaTableTree.addChild( schemaTableTo, direction, Vertex.class, this, this.labels ); SchemaTable schemaTable = SchemaTable.from(this.topology.getSqlgGraph(), schemaTableTo.toString()); List<Multimap<BiPredicate, RecordId>> biPredicateRecordIs = groupedIds.get(schemaTable.withOutPrefix()); addIdHasContainers(schemaTableTree1, biPredicateRecordIs); result.add(schemaTableTree1); return result; }
private Set<SchemaTableTree> calculatePathFromVertexToEdge(SchemaTableTree schemaTableTree, SchemaTable schemaTableTo, Direction direction, Map<SchemaTable, List<Multimap<BiPredicate, RecordId>>> groupedIds) { Set<SchemaTableTree> result = new HashSet<>(); //add the child for schemaTableTo to the tree SchemaTableTree schemaTableTree1 = schemaTableTree.addChild( schemaTableTo, direction, Vertex.class, this, this.labels ); SchemaTable schemaTable = SchemaTable.from(this.topology.getSqlgGraph(), schemaTableTo.toString()); List<Multimap<BiPredicate, RecordId>> biPredicateRecordIs = groupedIds.get(schemaTable.withOutPrefix()); addIdHasContainers(schemaTableTree1, biPredicateRecordIs); result.add(schemaTableTree1); return result; }
public <L, R> void bulkAddEdges(String outVertexLabel, String inVertexLabel, String edgeLabel, Pair<String, String> idFields, Collection<Pair<L, R>> uids, Object... keyValues) { if (!(this.sqlDialect instanceof SqlBulkDialect)) { throw new UnsupportedOperationException(String.format("Bulk mode is not supported for %s", this.sqlDialect.dialectName())); } SqlBulkDialect sqlBulkDialect = (SqlBulkDialect) this.sqlDialect; if (!this.tx().isInStreamingBatchMode() && !this.tx().isInStreamingWithLockBatchMode()) { throw SqlgExceptions.invalidMode(TRANSACTION_MUST_BE_IN + BatchManager.BatchModeType.STREAMING + " or " + BatchManager.BatchModeType.STREAMING_WITH_LOCK + " mode for bulkAddEdges"); } if (!uids.isEmpty()) { SchemaTable outSchemaTable = SchemaTable.from(this, outVertexLabel); SchemaTable inSchemaTable = SchemaTable.from(this, inVertexLabel); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); sqlBulkDialect.bulkAddEdges(this, outSchemaTable, inSchemaTable, edgeLabel, idFields, uids, keyValueMapTriple.getLeft(), keyValueMapTriple.getRight()); } }
/** * @deprecated Please use {@link Topology#ensureVertexLabelExist(String, Map)} and {@link VertexLabel#ensureIndexExists(IndexType, List)}. */ @Deprecated public void createVertexLabeledIndex(String label, Object... dummykeyValues) { Map<String, PropertyType> columns = SqlgUtil.transformToColumnDefinitionMap(dummykeyValues); SchemaTable schemaTablePair = SchemaTable.from(this, label); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); List<PropertyColumn> properties = new ArrayList<>(); List<String> keys = SqlgUtil.transformToKeyList(dummykeyValues); for (String key : keys) { properties.add(vertexLabel.getProperty(key).get()); } vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, properties); }
public <L, R> void bulkAddEdges(String outVertexLabel, String inVertexLabel, String edgeLabel, Pair<String, String> idFields, Collection<Pair<L, R>> uids, Object... keyValues) { if (!(this.sqlDialect instanceof SqlBulkDialect)) { throw new UnsupportedOperationException(String.format("Bulk mode is not supported for %s", this.sqlDialect.dialectName())); } SqlBulkDialect sqlBulkDialect = (SqlBulkDialect) this.sqlDialect; if (!this.tx().isInStreamingBatchMode() && !this.tx().isInStreamingWithLockBatchMode()) { throw SqlgExceptions.invalidMode(TRANSACTION_MUST_BE_IN + BatchManager.BatchModeType.STREAMING + " or " + BatchManager.BatchModeType.STREAMING_WITH_LOCK + " mode for bulkAddEdges"); } if (!uids.isEmpty()) { SchemaTable outSchemaTable = SchemaTable.from(this, outVertexLabel); SchemaTable inSchemaTable = SchemaTable.from(this, inVertexLabel); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); sqlBulkDialect.bulkAddEdges(this, outSchemaTable, inSchemaTable, edgeLabel, idFields, uids, keyValueMapTriple.getLeft(), keyValueMapTriple.getRight()); } }
/** * @deprecated Please use {@link Topology#ensureVertexLabelExist(String, Map)} and {@link VertexLabel#ensureIndexExists(IndexType, List)}. */ @Deprecated public void createVertexLabeledIndex(String label, Object... dummykeyValues) { Map<String, PropertyType> columns = SqlgUtil.transformToColumnDefinitionMap(dummykeyValues); SchemaTable schemaTablePair = SchemaTable.from(this, label); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); List<PropertyColumn> properties = new ArrayList<>(); List<String> keys = SqlgUtil.transformToKeyList(dummykeyValues); for (String key : keys) { properties.add(vertexLabel.getProperty(key).get()); } vertexLabel.ensureIndexExists(IndexType.NON_UNIQUE, properties); }
public void addTemporaryVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label, true); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); new SqlgVertex(this, true, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
public void addTemporaryVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label, true); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); new SqlgVertex(this, true, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
private SqlgVertex internalStreamVertex(Object... keyValues) { Preconditions.checkState(this.sqlDialect.supportsStreamingBatchMode(), "Streaming batch mode is not supported."); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); SchemaTable streamingBatchModeVertexSchemaTable = this.tx().getBatchManager().getStreamingBatchModeVertexSchemaTable(); if (streamingBatchModeVertexSchemaTable != null && !streamingBatchModeVertexSchemaTable.toString().equals(schemaTablePair.toString())) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeVertexSchemaTable + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } List<String> keys = this.tx().getBatchManager().getStreamingBatchModeVertexKeys(); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues, keys); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.tx().readWrite(); this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); return new SqlgVertex(this, false, true, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
private SqlgVertex internalStreamVertex(Object... keyValues) { Preconditions.checkState(this.sqlDialect.supportsStreamingBatchMode(), "Streaming batch mode is not supported."); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); SchemaTable streamingBatchModeVertexSchemaTable = this.tx().getBatchManager().getStreamingBatchModeVertexSchemaTable(); if (streamingBatchModeVertexSchemaTable != null && !streamingBatchModeVertexSchemaTable.toString().equals(schemaTablePair.toString())) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeVertexSchemaTable + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } List<String> keys = this.tx().getBatchManager().getStreamingBatchModeVertexKeys(); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues, keys); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); this.tx().readWrite(); this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); return new SqlgVertex(this, false, true, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); }
private void internalStreamTemporaryVertex(Object... keyValues) { Preconditions.checkState(this.sqlDialect.supportsBatchMode()); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); SchemaTable streamingBatchModeVertexSchemaTable = this.tx().getBatchManager().getStreamingBatchModeVertexSchemaTable(); if (streamingBatchModeVertexSchemaTable != null && !streamingBatchModeVertexSchemaTable.toString().equals(schemaTablePair.toString())) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeVertexSchemaTable + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } List<String> keys = this.tx().getBatchManager().getStreamingBatchModeVertexKeys(); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValuesTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues, keys); final Map<String, Object> allKeyValueMap = keyValuesTriple.getMiddle(); final Map<String, PropertyType> columns = keyValuesTriple.getLeft(); this.tx().readWrite(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); new SqlgVertex(this, schemaTablePair.getTable(), allKeyValueMap); }
private void internalStreamTemporaryVertex(Object... keyValues) { Preconditions.checkState(this.sqlDialect.supportsBatchMode()); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); SchemaTable streamingBatchModeVertexSchemaTable = this.tx().getBatchManager().getStreamingBatchModeVertexSchemaTable(); if (streamingBatchModeVertexSchemaTable != null && !streamingBatchModeVertexSchemaTable.toString().equals(schemaTablePair.toString())) { throw new IllegalStateException("Streaming batch mode must occur for one label at a time. Expected \"" + streamingBatchModeVertexSchemaTable + "\" found \"" + label + "\". First commit the transaction or call SqlgGraph.flush() before streaming a different label"); } List<String> keys = this.tx().getBatchManager().getStreamingBatchModeVertexKeys(); Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValuesTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues, keys); final Map<String, Object> allKeyValueMap = keyValuesTriple.getMiddle(); final Map<String, PropertyType> columns = keyValuesTriple.getLeft(); this.tx().readWrite(); this.getTopology().ensureTemporaryVertexTableExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); new SqlgVertex(this, schemaTablePair.getTable(), allKeyValueMap); }
@Override public Vertex addVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } if (this.tx().isInStreamingWithLockBatchMode()) { return internalStreamVertex(keyValues); } else { Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); this.tx().readWrite(); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); if (!vertexLabel.hasIDPrimaryKey()) { Preconditions.checkArgument(columns.keySet().containsAll(vertexLabel.getIdentifiers()), "identifiers must be present %s", vertexLabel.getIdentifiers()); } return new SqlgVertex(this, false, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); } }
@Override public Vertex addVertex(Object... keyValues) { if (this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(String.format("Transaction is in %s, use streamVertex(Object ... keyValues)", this.tx().getBatchModeType().toString())); } if (this.tx().isInStreamingWithLockBatchMode()) { return internalStreamVertex(keyValues); } else { Triple<Map<String, PropertyType>, Map<String, Object>, Map<String, Object>> keyValueMapTriple = SqlgUtil.validateVertexKeysValues(this.sqlDialect, keyValues); final Pair<Map<String, Object>, Map<String, Object>> keyValueMapPair = Pair.of(keyValueMapTriple.getMiddle(), keyValueMapTriple.getRight()); final Map<String, PropertyType> columns = keyValueMapTriple.getLeft(); final String label = ElementHelper.getLabelValue(keyValues).orElse(Vertex.DEFAULT_LABEL); SchemaTable schemaTablePair = SchemaTable.from(this, label); this.tx().readWrite(); VertexLabel vertexLabel = this.getTopology().ensureVertexLabelExist(schemaTablePair.getSchema(), schemaTablePair.getTable(), columns); if (!vertexLabel.hasIDPrimaryKey()) { Preconditions.checkArgument(columns.keySet().containsAll(vertexLabel.getIdentifiers()), "identifiers must be present %s", vertexLabel.getIdentifiers()); } return new SqlgVertex(this, false, false, schemaTablePair.getSchema(), schemaTablePair.getTable(), keyValueMapPair); } }