public Optional<PropertyColumn> getProperty(String key) { PropertyColumn propertyColumn = getProperties().get(key); if (propertyColumn != null) { return Optional.of(propertyColumn); } else { return Optional.empty(); } }
/** * Only called from {@link Topology#fromNotifyJson(int, LocalDateTime)} * * @param globalUniqueIndex The {@link GlobalUniqueIndex} to add. */ void addToGlobalUniqueIndexes(GlobalUniqueIndex globalUniqueIndex) { this.globalUniqueIndices.add(globalUniqueIndex); this.abstractLabel.addGlobalUniqueIndexToProperties(this); }
void addGlobalUniqueIndex(GlobalUniqueIndex globalUniqueIndex) { this.uncommittedGlobalUniqueIndices.add(globalUniqueIndex); this.abstractLabel.addGlobalUniqueIndexToUncommittedProperties(this); }
/** * Ensures that a LIST partition exists. * * @param name The partition's name. * @param in The LIST partition's 'in' clause. * @return The {@link Partition} */ public Partition ensureListPartitionExists(String name, String in) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "LIST Partition's \"name\" must not be null"); Objects.requireNonNull(in, "LIST Partition's \"in\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.LIST, "ensureRangePartitionExists(String name, String ... in) can only be called for a LIST partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createListPartition(name, in)); } else { return partitionOptional.get(); } }
public Index ensureIndexExists(final IndexType indexType, final List<PropertyColumn> properties) { String prefix = this instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; SchemaTable schemaTable = SchemaTable.of(this.getSchema().getName(), this.getLabel()); for (Index idx : this.getIndexes().values()) { if (idx.getProperties().equals(properties)) { return idx; this.getSchema().getTopology().lock(); for (Index idx : this.getIndexes().values()) { if (idx.getProperties().equals(properties)) { return idx; return this.createIndex(indexName, indexType, properties); Optional<Index> indexOptional = this.getIndex(indexName); if (!indexOptional.isPresent()) { this.getSchema().getTopology().lock(); indexOptional = this.getIndex(indexName); if (!indexOptional.isPresent()) { return this.createIndex(indexName, indexType, properties); } else { return indexOptional.get();
.getSchema(this.schema).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", this.schema))) .getVertexLabel(this.table).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel %s not found", this.table))); properties = abstractLabel.getProperties(); } else { abstractLabel = this.sqlgGraph.getTopology() .getSchema(this.schema).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", this.schema))) .getEdgeLabel(this.table).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel %s not found", this.table))); properties = abstractLabel.getProperties(); if (abstractLabel.hasIDPrimaryKey()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); sql.append(" = ?"); } else { int count = 1; for (String identifier : abstractLabel.getIdentifiers()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(identifier)); sql.append(" = ?"); if (count++ < abstractLabel.getIdentifiers().size()) { sql.append(" AND "); if (abstractLabel.hasIDPrimaryKey()) { preparedStatement.setLong(idx, ((RecordId) this.id()).sequenceId()); } else { for (String identifier : abstractLabel.getIdentifiers()) { keyValue = new HashMap<>(abstractLabel.getIdentifiers().size()); keyValue.put(identifier, value(identifier)); idx = setKeyValuesAsParameter(this.sqlgGraph, idx, preparedStatement, keyValue);
/** * Ensures that a RANGE partition exists. * * @param name The partition's name * @param from The RANGE partition's start clause. * @param to THe RANGE partition's end clause. * @return The {@link Partition} */ public Partition ensureRangePartitionExists(String name, String from, String to) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "RANGE Partition's \"name\" must not be null"); Objects.requireNonNull(from, "RANGE Partition's \"from\" must not be null"); Objects.requireNonNull(to, "RANGE Partition's \"to\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.RANGE, "ensureRangePartitionExists(String name, String from, String to) can only be called for a RANGE partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createRangePartition(name, from, to)); } else { return partitionOptional.get(); } }
/** * Ensures that a LIST partition exists. * * @param name The partition's name. * @param in The LIST partition's 'in' clause. * @param partitionType The partition's {@link PartitionType} if is is going to be sub-partitioned. * @param partitionExpression The partition's partitionExpression if is is going to be sub-partitioned. * @return The {@link Partition} */ public Partition ensureListPartitionWithSubPartitionExists(String name, String in, PartitionType partitionType, String partitionExpression) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "LIST Partition's \"name\" must not be null"); Objects.requireNonNull(in, "LIST Partition's \"in\" must not be null"); Objects.requireNonNull(partitionType, "Sub-partition's \"partitionType\" must not be null"); Objects.requireNonNull(partitionExpression, "Sub-partition's \"partitionExpression\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.LIST, "ensureRangePartitionExists(String name, String ... in) can only be called for a LIST partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createListPartitionWithSubPartition(name, in, partitionType, partitionExpression)); } else { return partitionOptional.get(); } }
void afterRollbackForInEdges() { Preconditions.checkState(this.schema.getTopology().isSqlWriteLockHeldByCurrentThread(), "VertexLabel.afterRollback must hold the write lock"); super.afterRollback(); for (Iterator<EdgeLabel> it = this.uncommittedInEdgeLabels.values().iterator(); it.hasNext(); ) { EdgeLabel edgeLabel = it.next(); edgeLabel.afterRollbackInEdges(this); it.remove(); } for (EdgeLabel edgeLabel : this.inEdgeLabels.values()) { edgeLabel.afterRollbackInEdges(this); } }
void afterCommit() { Preconditions.checkState(this.getSchema().getTopology().isSqlWriteLockHeldByCurrentThread(), "EdgeLabel.afterCommit must hold the write lock"); super.afterCommit(); for (Iterator<VertexLabel> it = this.uncommittedInVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.inVertexLabels.add(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedRemovedInVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.inVertexLabels.remove(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedOutVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.outVertexLabels.add(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedRemovedOutVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.outVertexLabels.remove(vertexLabel); it.remove(); } }
sql.append(", "); AbstractLabel.buildColumns(this.sqlgGraph, new ListOrderedSet<>(), columns, sql); sql.append(") "); sql.append(this.sqlgGraph.getSqlDialect().afterCreateTemporaryTableStatement());
public Index ensureIndexExists(final IndexType indexType, final List<PropertyColumn> properties) { String prefix = this instanceof VertexLabel ? VERTEX_PREFIX : EDGE_PREFIX; SchemaTable schemaTable = SchemaTable.of(this.getSchema().getName(), this.getLabel()); for (Index idx : this.getIndexes().values()) { if (idx.getProperties().equals(properties)) { return idx; this.getSchema().getTopology().lock(); for (Index idx : this.getIndexes().values()) { if (idx.getProperties().equals(properties)) { return idx; return this.createIndex(indexName, indexType, properties); Optional<Index> indexOptional = this.getIndex(indexName); if (!indexOptional.isPresent()) { this.getSchema().getTopology().lock(); indexOptional = this.getIndex(indexName); if (!indexOptional.isPresent()) { return this.createIndex(indexName, indexType, properties); } else { return indexOptional.get();
.getSchema(this.schema).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", this.schema))) .getVertexLabel(this.table).orElseThrow(() -> new IllegalStateException(String.format("VertexLabel %s not found", this.table))); properties = abstractLabel.getProperties(); } else { abstractLabel = this.sqlgGraph.getTopology() .getSchema(this.schema).orElseThrow(() -> new IllegalStateException(String.format("Schema %s not found", this.schema))) .getEdgeLabel(this.table).orElseThrow(() -> new IllegalStateException(String.format("EdgeLabel %s not found", this.table))); properties = abstractLabel.getProperties(); if (abstractLabel.hasIDPrimaryKey()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes("ID")); sql.append(" = ?"); } else { int count = 1; for (String identifier : abstractLabel.getIdentifiers()) { sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(identifier)); sql.append(" = ?"); if (count++ < abstractLabel.getIdentifiers().size()) { sql.append(" AND "); if (abstractLabel.hasIDPrimaryKey()) { preparedStatement.setLong(idx, ((RecordId) this.id()).sequenceId()); } else { for (String identifier : abstractLabel.getIdentifiers()) { keyValue = new HashMap<>(abstractLabel.getIdentifiers().size()); keyValue.put(identifier, value(identifier)); idx = setKeyValuesAsParameter(this.sqlgGraph, idx, preparedStatement, keyValue);
/** * Ensures that a LIST partition exists. * * @param name The partition's name. * @param in The LIST partition's 'in' clause. * @return The {@link Partition} */ public Partition ensureListPartitionExists(String name, String in) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "LIST Partition's \"name\" must not be null"); Objects.requireNonNull(in, "LIST Partition's \"in\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.LIST, "ensureRangePartitionExists(String name, String ... in) can only be called for a LIST partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createListPartition(name, in)); } else { return partitionOptional.get(); } }
/** * Ensures that a RANGE partition exists. * * @param name The partition's name * @param from The RANGE partition's start clause. * @param to THe RANGE partition's end clause. * @return The {@link Partition} */ public Partition ensureRangePartitionExists(String name, String from, String to) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "RANGE Partition's \"name\" must not be null"); Objects.requireNonNull(from, "RANGE Partition's \"from\" must not be null"); Objects.requireNonNull(to, "RANGE Partition's \"to\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.RANGE, "ensureRangePartitionExists(String name, String from, String to) can only be called for a RANGE partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createRangePartition(name, from, to)); } else { return partitionOptional.get(); } }
/** * Ensures that a LIST partition exists. * * @param name The partition's name. * @param in The LIST partition's 'in' clause. * @param partitionType The partition's {@link PartitionType} if is is going to be sub-partitioned. * @param partitionExpression The partition's partitionExpression if is is going to be sub-partitioned. * @return The {@link Partition} */ public Partition ensureListPartitionWithSubPartitionExists(String name, String in, PartitionType partitionType, String partitionExpression) { Preconditions.checkState(this.sqlgGraph.getSqlDialect().supportsPartitioning()); Objects.requireNonNull(name, "LIST Partition's \"name\" must not be null"); Objects.requireNonNull(in, "LIST Partition's \"in\" must not be null"); Objects.requireNonNull(partitionType, "Sub-partition's \"partitionType\" must not be null"); Objects.requireNonNull(partitionExpression, "Sub-partition's \"partitionExpression\" must not be null"); Preconditions.checkState(this.partitionType == PartitionType.LIST, "ensureRangePartitionExists(String name, String ... in) can only be called for a LIST partitioned VertexLabel. Found %s", this.partitionType.name()); Optional<Partition> partitionOptional = this.getPartition(name); if (!partitionOptional.isPresent()) { getSchema().getTopology().lock(); partitionOptional = this.getPartition(name); return partitionOptional.orElseGet(() -> this.createListPartitionWithSubPartition(name, in, partitionType, partitionExpression)); } else { return partitionOptional.get(); } }
void afterRollbackForInEdges() { Preconditions.checkState(this.schema.getTopology().isSqlWriteLockHeldByCurrentThread(), "VertexLabel.afterRollback must hold the write lock"); super.afterRollback(); for (Iterator<EdgeLabel> it = this.uncommittedInEdgeLabels.values().iterator(); it.hasNext(); ) { EdgeLabel edgeLabel = it.next(); edgeLabel.afterRollbackInEdges(this); it.remove(); } for (EdgeLabel edgeLabel : this.inEdgeLabels.values()) { edgeLabel.afterRollbackInEdges(this); } }
void afterCommit() { Preconditions.checkState(this.getSchema().getTopology().isSqlWriteLockHeldByCurrentThread(), "EdgeLabel.afterCommit must hold the write lock"); super.afterCommit(); for (Iterator<VertexLabel> it = this.uncommittedInVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.inVertexLabels.add(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedRemovedInVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.inVertexLabels.remove(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedOutVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.outVertexLabels.add(vertexLabel); it.remove(); } for (Iterator<VertexLabel> it = this.uncommittedRemovedOutVertexLabels.iterator(); it.hasNext(); ) { VertexLabel vertexLabel = it.next(); this.outVertexLabels.remove(vertexLabel); it.remove(); } }
sql.append(", "); AbstractLabel.buildColumns(this.sqlgGraph, new ListOrderedSet<>(), columns, sql); sql.append(") "); sql.append(this.sqlgGraph.getSqlDialect().afterCreateTemporaryTableStatement());
public Optional<PropertyColumn> getProperty(String key) { PropertyColumn propertyColumn = getProperties().get(key); if (propertyColumn != null) { return Optional.of(propertyColumn); } else { return Optional.empty(); } }