Search in sources :

Example 6 with SqlDialect

use of org.umlg.sqlg.sql.dialect.SqlDialect in project sqlg by pietermartin.

the class SqlgAbstractGraphProvider method clear.

@Override
public void clear(final Graph g, final Configuration configuration) throws Exception {
    logger.debug("clearing datasource " + configuration.getString("jdbc.url"));
    SqlgDataSource sqlgDataSource = null;
    if (null != g) {
        if (g.features().graph().supportsTransactions() && g.tx().isOpen()) {
            g.tx().rollback();
        }
        g.close();
    }
    SqlgPlugin plugin = getSqlgPlugin();
    SqlDialect sqlDialect = plugin.instantiateDialect();
    try {
        sqlgDataSource = SqlgGraph.createDataSourceFactory(configuration).setup(plugin.getDriverFor(configuration.getString("jdbc.url")), configuration);
        try (Connection conn = sqlgDataSource.getDatasource().getConnection()) {
            SqlgUtil.dropDb(sqlDialect, conn);
        }
    } catch (PropertyVetoException e) {
        throw new RuntimeException(e);
    } finally {
        if (sqlgDataSource != null) {
            sqlgDataSource.close();
        }
    }
}
Also used : SqlgDataSource(org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource) PropertyVetoException(java.beans.PropertyVetoException) Connection(java.sql.Connection) SqlDialect(org.umlg.sqlg.sql.dialect.SqlDialect) SqlgPlugin(org.umlg.sqlg.SqlgPlugin)

Example 7 with SqlDialect

use of org.umlg.sqlg.sql.dialect.SqlDialect in project sqlg by pietermartin.

the class EdgeLabel method delete.

/**
 * delete the table
 */
void delete() {
    String schema = getSchema().getName();
    String tableName = EDGE_PREFIX + getLabel();
    SqlDialect sqlDialect = this.sqlgGraph.getSqlDialect();
    sqlDialect.assertTableName(tableName);
    StringBuilder sql = new StringBuilder("DROP TABLE IF EXISTS ");
    sql.append(sqlDialect.maybeWrapInQoutes(schema));
    sql.append(".");
    sql.append(sqlDialect.maybeWrapInQoutes(tableName));
    if (sqlDialect.supportsCascade()) {
        sql.append(" CASCADE");
    }
    if (logger.isDebugEnabled()) {
        logger.debug(sql.toString());
    }
    if (sqlDialect.needsSemicolon()) {
        sql.append(";");
    }
    Connection conn = sqlgGraph.tx().getConnection();
    try (Statement stmt = conn.createStatement()) {
        stmt.execute(sql.toString());
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SqlDialect(org.umlg.sqlg.sql.dialect.SqlDialect)

Aggregations

SqlDialect (org.umlg.sqlg.sql.dialect.SqlDialect)7 PropertyVetoException (java.beans.PropertyVetoException)1 Connection (java.sql.Connection)1 SqlgPlugin (org.umlg.sqlg.SqlgPlugin)1 SqlgDataSource (org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource)1