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();
}
}
}
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);
}
}
Aggregations