/** * Ensures that the schema, vertex table exist in the db. * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param schemaName The schema the vertex is in. * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. */ public VertexLabel ensureVertexLabelExist(final String schemaName, final String label) { return ensureVertexLabelExist(schemaName, label, Collections.emptyMap()); }
/** * Ensures that the schema, vertex table exist in the db. * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param schemaName The schema the vertex is in. * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. */ public VertexLabel ensureVertexLabelExist(final String schemaName, final String label) { return ensureVertexLabelExist(schemaName, label, Collections.emptyMap()); }
private static VertexLabel ensureVertexLabelExist(Topology topology, String label, Map<String, PropertyType> columns, List<String> nonUniqueIndexNames) { VertexLabel vertexLabel = topology.ensureVertexLabelExist(label, columns); nonUniqueIndexNames.stream() .flatMap(fromOptional(vertexLabel::getProperty)) .map(Collections::singletonList) .forEach(properties -> vertexLabel.ensureIndexExists(NON_UNIQUE, properties)); return vertexLabel; }
/** * Ensures that the vertex table exist in the db. The default schema is assumed. @See {@link SqlDialect#getPublicSchema()} * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. */ public VertexLabel ensureVertexLabelExist(final String label) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, Collections.emptyMap()); }
/** * Ensures that the vertex table exist in the db. The default schema is assumed. @See {@link SqlDialect#getPublicSchema()} * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. */ public VertexLabel ensureVertexLabelExist(final String label) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, Collections.emptyMap()); }
/** * Ensures that the vertex table and property columns exist in the db. The default schema is assumed. @See {@link SqlDialect#getPublicSchema()} * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. * @param columns The properties with their types. * @see PropertyType */ public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, columns); }
/** * Ensures that the vertex table and property columns exist in the db. The default schema is assumed. @See {@link SqlDialect#getPublicSchema()} * If any element does not exist the a lock is first obtained. After the lock is obtained the maps are rechecked to * see if the element has not been added in the mean time. * * @param label The vertex's label. Translates to a table prepended with 'V_' and the table's name being the label. * @param columns The properties with their types. * @see PropertyType */ public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, columns); }
public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns, ListOrderedSet<String> identifiers) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, columns, identifiers); }
public VertexLabel ensureVertexLabelExist(final String label, final Map<String, PropertyType> columns, ListOrderedSet<String> identifiers) { return ensureVertexLabelExist(this.sqlgGraph.getSqlDialect().getPublicSchema(), label, columns, identifiers); }
/** * @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); }
/** * @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); }
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); }
@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); } }
VertexLabel fileLabel = graph().getTopology().ensureVertexLabelExist(file.getSchema(), file.withOutPrefix().getTable()); graph().getTopology().ensureEdgeLabelExist(parent.withOutPrefix().getTable(), fileLabel, fileLabel, ImmutableMap.of());