use of org.umlg.sqlg.SqlgPlugin 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.SqlgPlugin in project sqlg by pietermartin.
the class TestJNDIInitialization method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
URL sqlProperties = Thread.currentThread().getContextClassLoader().getResource("sqlg.properties");
configuration = new PropertiesConfiguration(sqlProperties);
if (!configuration.containsKey("jdbc.url")) {
throw new IllegalArgumentException(String.format("SqlGraph configuration requires that the %s be set", "jdbc.url"));
}
String url = configuration.getString("jdbc.url");
// obtain the connection that we will later supply from JNDI
SqlgPlugin p = findSqlgPlugin(url);
Assert.assertNotNull(p);
ds = new C3p0DataSourceFactory().setup(p.getDriverFor(url), configuration).getDatasource();
// change the connection url to be a JNDI one
configuration.setProperty("jdbc.url", "jndi:testConnection");
// set up the initial context
NamingManager.setInitialContextFactoryBuilder(environment -> {
InitialContextFactory mockFactory = mock(InitialContextFactory.class);
Context mockContext = mock(Context.class);
when(mockFactory.getInitialContext(any())).thenReturn(mockContext);
when(mockContext.lookup("testConnection")).thenReturn(ds);
return mockFactory;
});
}
Aggregations