use of org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource in project sqlg by pietermartin.
the class JNDIDataSource method create.
public static SqlgDataSource create(Configuration configuration) throws NamingException {
String url = configuration.getString(SqlgGraph.JDBC_URL);
if (!isJNDIUrl(url)) {
throw new IllegalArgumentException("Creating JNDI ds from invalid url: " + url);
}
String jndiName = url.substring(JNDI_PREFIX.length());
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
return new JNDIDataSource(url, ds);
}
use of org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource 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();
}
}
}
Aggregations