private static BatchManager.BatchModeType flushAndSetTxToNone(SqlgGraph sqlgGraph) { //topology elements can not be added in batch mode because on flushing the topology //needs to be queries and yet the elements are still in the cache. BatchManager.BatchModeType batchModeType = sqlgGraph.tx().getBatchModeType(); if (sqlgGraph.tx().isInBatchMode()) { batchModeType = sqlgGraph.tx().getBatchModeType(); sqlgGraph.tx().flush(); sqlgGraph.tx().batchMode(BatchManager.BatchModeType.NONE); } return batchModeType; }
private boolean existSqlgSchema() { Connection conn = this.sqlgGraph.tx().getConnection(); try { DatabaseMetaData metadata = conn.getMetaData(); return this.sqlDialect.schemaExists(metadata, SQLG_SCHEMA); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public Set<String> keys() { this.sqlgGraph.tx().readWrite(); return this.internalGetProperties().keySet(); }
private void createDefaultSchema() { Connection conn = this.sqlgGraph.tx().getConnection(); try (Statement statement = conn.createStatement()) { statement.execute(this.sqlDialect.createSchemaStatement(this.sqlDialect.getPublicSchema())); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public Iterator<Vertex> vertices(Direction direction) { SqlgEdge.this.sqlgGraph.tx().readWrite(); return internalGetVertices(direction); }
private boolean existDefaultSchema() { Connection conn = this.sqlgGraph.tx().getConnection(); try { DatabaseMetaData metadata = conn.getMetaData(); return this.sqlDialect.schemaExists(metadata, this.sqlDialect.getPublicSchema()); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public void remove() { this.sqlgGraph.tx().readWrite(); if (this.removed) throw new IllegalStateException(String.format("Edge with id %s was removed.", id().toString())); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode()) { this.sqlgGraph.tx().getBatchManager().removeEdge(this.schema, this.table, this); } else { super.remove(); } }
@SuppressWarnings("unchecked") @Override public <V> VertexProperty<V> property(final String key, final V value) { if (this.removed) { throw new IllegalStateException(String.format("Vertex with id %s was removed.", id().toString())); } ElementHelper.validateProperty(key, value); this.sqlgGraph.tx().readWrite(); return (VertexProperty<V>) super.property(key, value); }
@SuppressWarnings("unchecked") @Override public <V> VertexProperty<V> property(final String key, final V value) { if (this.removed) { throw new IllegalStateException(String.format("Vertex with id %s was removed.", id().toString())); } ElementHelper.validateProperty(key, value); this.sqlgGraph.tx().readWrite(); return (VertexProperty<V>) super.property(key, value); }
@Override public Iterator<Vertex> vertices(Object... vertexIds) { this.tx().readWrite(); if (this.sqlDialect.supportsBatchMode() && this.tx().getBatchManager().isStreaming()) { throw new IllegalStateException("streaming is in progress, first flush or commit before querying."); } return createElementIterator(Vertex.class, vertexIds); }
private Iterator<List<Emit<E>>> elements() { this.sqlgGraph.tx().readWrite(); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().getBatchManager().isStreaming()) { throw new IllegalStateException("streaming is in progress, first flush or commit before querying."); } Preconditions.checkState(this.replacedSteps.size() > 0, "There must be at least one replacedStep"); Preconditions.checkState(this.replacedSteps.get(0).isGraphStep(), "The first step must a SqlgGraphStep"); Set<SchemaTableTree> rootSchemaTableTrees = doLast(); return new SqlgCompiledResultIterator<>(this.sqlgGraph, rootSchemaTableTrees); }
public static void addSchema(SqlgGraph sqlgGraph, String schema) { BatchManager.BatchModeType batchModeType = flushAndSetTxToNone(sqlgGraph); try { sqlgGraph.addVertex( T.label, SQLG_SCHEMA + "." + SQLG_SCHEMA_SCHEMA, "name", schema, CREATED_ON, LocalDateTime.now() ); } finally { sqlgGraph.tx().batchMode(batchModeType); } }
private Iterator<List<Emit<E>>> elements() { this.sqlgGraph.tx().readWrite(); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().getBatchManager().isStreaming()) { throw new IllegalStateException("streaming is in progress, first flush or commit before querying."); } Preconditions.checkState(this.replacedSteps.size() > 0, "There must be at least one replacedStep"); Preconditions.checkState(this.replacedSteps.get(0).isGraphStep(), "The first step must a SqlgGraphStep"); Set<SchemaTableTree> rootSchemaTableTrees = doLast(); return new SqlgCompiledResultIterator<>(this.sqlgGraph, rootSchemaTableTrees); }
@Override public Iterator<Edge> edges(Direction direction, String... edgeLabels) { SqlgVertex.this.sqlgGraph.tx().readWrite(); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().getBatchManager().isStreaming()) { throw new IllegalStateException("streaming is in progress, first flush or commit before querying."); } return internalEdges(direction, edgeLabels); }
@Override public int hashCode() { if (this.id() != null) { return id().hashCode(); } if (this.sqlgGraph.features().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode()) { return super.hashCode(); } else { return id().hashCode(); } }
public void rollback() { try { this.sqlG.tx().rollback(); } finally { TransactionThreadEntityVar.remove(); TransactionThreadMetaNodeVar.remove(); TransactionThreadNotificationVar.remove(); } }
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); }