Search in sources :

Example 1 with SqlgDataSource

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);
}
Also used : InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) SqlgDataSource(org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource)

Example 2 with SqlgDataSource

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

Aggregations

SqlgDataSource (org.umlg.sqlg.structure.SqlgDataSourceFactory.SqlgDataSource)2 PropertyVetoException (java.beans.PropertyVetoException)1 Connection (java.sql.Connection)1 InitialContext (javax.naming.InitialContext)1 DataSource (javax.sql.DataSource)1 SqlgPlugin (org.umlg.sqlg.SqlgPlugin)1 SqlDialect (org.umlg.sqlg.sql.dialect.SqlDialect)1