private static boolean existPublicSchema(SqlgGraph sqlgGraph) { Connection conn = sqlgGraph.tx().getConnection(); try { DatabaseMetaData metadata = conn.getMetaData(); return sqlgGraph.getSqlDialect().schemaExists(metadata, sqlgGraph.getSqlDialect().getPublicSchema()); } catch (SQLException e) { throw new RuntimeException(e); } }
private void cacheTopology() { this.sqlgGraph.getTopology().cacheTopology(); }
/** * Executes the supplied task with a new Sqlg graph. */ public void execute(SqlgTask task) throws Exception { SqlgGraph sqlgGraph = SqlgGraph.open(sqlgConfiguration(configuration), sqlgDataSourceFactory(configuration)); sqlgGraph.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK); try { task.run(sqlgGraph); } finally { sqlgGraph.close(); } }
public static <G extends Graph> G open(final Configuration configuration) { SqlgDataSource dataSource = createDataSource(configuration); try { return open(configuration, dataSource); } catch (Exception ex) { dataSource.close(); throw ex; } }
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<Edge> internalEdges(Direction direction, String... labels) { this.sqlgGraph.tx().readWrite(); if (this.sqlgGraph.getSqlDialect().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode() && this.sqlgGraph.tx().getBatchManager().vertexIsCached(this)) { this.sqlgGraph.tx().flush(); } // need topology when we're a topology vertex GraphTraversalSource gts = Topology.SQLG_SCHEMA.equals(schema) ? this.sqlgGraph.topology() : this.sqlgGraph.traversal(); switch (direction) { case OUT: return gts.V(this).outE(labels); case IN: return gts.V(this).inE(labels); case BOTH: return gts.V(this).bothE(labels); } return Collections.emptyIterator(); }
this.distributed = sqlgGraph.configuration().getBoolean(SqlgGraph.DISTRIBUTED, false); this.topologySqlWriteLock = new ReentrantLock(true); this.topologyMapLock = new ReentrantReadWriteLock(true); this.schemas.put(sqlgGraph.getSqlDialect().getPublicSchema(), Schema.createPublicSchema(sqlgGraph, this, sqlgGraph.getSqlDialect().getPublicSchema())); ((SqlSchemaChangeDialect) this.sqlgGraph.getSqlDialect()).registerListener(sqlgGraph); this.sqlgGraph.tx().beforeCommit(this::beforeCommit); this.sqlgGraph.tx().afterCommit(this::afterCommit); this.sqlgGraph.tx().afterRollback(() -> { if (this.sqlgGraph.getSqlDialect().supportsTransactionalSchema()) { afterRollback(); } else { if (this.sqlgGraph.getSqlDialect().isPostgresql()) { registerListener((topologyInf, string, topologyChangeAction) -> deallocateAll());
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); }
this.sqlgGraph.tx().commit(); stopWatch.stop(); logger.debug("Time to createVertexLabel sqlg topology: " + stopWatch.toString()); if (!existSqlgSchema) { addPublicSchema(); this.sqlgGraph.tx().commit(); if (this.sqlgGraph.configuration().getBoolean("validate.topology", false)) { validateTopology(); this.sqlgGraph.tx().commit(); } catch (Exception e) { this.sqlgGraph.tx().rollback(); throw e;
@Override public GraphTraversalSource traversal() { return this.sqlG.traversal(); }
SqlgGraph sqlgGraph = SqlgGraph.open(configuration); this.umlgGraph = new UmlgSqlgGraph(sqlgGraph); if (!sqlgGraph.getTopology().getVertexLabel(sqlgGraph.getSqlDialect().getPublicSchema(), UmlgGraph.ROOT_VERTEX).isPresent()) { try {
/** * 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); }
SqlgGraph sqlgGraph = (SqlgGraph)this.umlgGraph.getUnderlyingGraph(); SqlDialect sqlDialect = sqlgGraph.getSqlDialect(); try (Connection conn = sqlgGraph.getSqlgDataSource().getDatasource().getConnection()) { DatabaseMetaData metadata = conn.getMetaData(); String catalog = null; sqlgGraph.getSqlgDataSource().close(); } catch (SQLException e) { throw new RuntimeException(e); sqlgGraph.close(); UMLG.remove(); } catch (Exception e) {
public void streamVertex(Object... keyValues) { if (!this.tx().isInStreamingBatchMode()) { throw SqlgExceptions.invalidMode(TRANSACTION_MUST_BE_IN + this.tx().getBatchModeType().toString() + MODE_FOR_STREAM_VERTEX); } internalStreamVertex(keyValues); }
@Override public Configuration configuration() { return this.sqlG.configuration(); }
@Override public Vertex addVertex(Object... keyvalues) { return this.sqlG.addVertex(keyvalues); }
public UmlgSqlgGraph(Configuration config) { this.sqlG = SqlgGraph.open(config); this.transactionEventHandler = new UmlgTransactionEventHandlerImpl(); }