use of org.neo4j.kernel.EmbeddedGraphDatabase in project neo4j-mobile-android by neo4j-contrib.
the class Neo4jServiceImpl method doOpenOrCreateDatabase.
private IGraphDatabase doOpenOrCreateDatabase(String name) {
mDatabaseLock.lock();
try {
// TODO: [eRiC] what happens if another application tries to
// open the same database?
WeakReference<EmbeddedGraphDatabase> dbRef = mDatabases.get(name);
// check if the DB is already loaded, or if has been
// previously loaded but unloaded by the GC
EmbeddedGraphDatabase db = null;
if (dbRef != null) {
db = dbRef.get();
if (db == null) {
Log.d(TAG, "database '" + name + "' was previously loaded, and garbage collected.");
// delete the mapping, we will reload and remap it
// later
mDatabases.remove(name);
}
}
// been unloaded by the GC
if (db == null) {
File dbDir = new File(getApplicationContext().getFilesDir(), name);
db = new EmbeddedGraphDatabase(getApplicationContext(), dbDir.getAbsolutePath());
mDatabases.put(name, new WeakReference<EmbeddedGraphDatabase>(db));
Log.d(TAG, "database '" + name + "' loaded.");
}
DbWrapper dbWrapper = new DbWrapper(db, mTrxManager, getApplicationContext());
Log.i(TAG, "Returning database '" + name + "' (binder hashcode '" + dbWrapper.asBinder().hashCode() + "'): " + db);
return dbWrapper;
} finally {
mDatabaseLock.unlock();
}
}
use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.
the class UdcExtensionImplTest method shouldLoadWhenNormalGraphdbIsCreated.
/**
* Expect the counts to be initialized.
*/
@Test
public void shouldLoadWhenNormalGraphdbIsCreated() throws Exception {
EmbeddedGraphDatabase graphdb = createTempDatabase(null);
// when the UDC extension successfully loads, it initializes the attempts count to 0
assertGotSuccessWithRetry(IS_ZERO);
destroy(graphdb);
}
use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.
the class UdcExtensionImplTest method shouldLoadForEachCreatedGraphdb.
/**
* Expect separate counts for each graphdb.
*/
@Test
public void shouldLoadForEachCreatedGraphdb() throws IOException {
EmbeddedGraphDatabase graphdb1 = createTempDatabase(null);
EmbeddedGraphDatabase graphdb2 = createTempDatabase(null);
Set<String> successCountValues = UdcTimerTask.successCounts.keySet();
assertThat(successCountValues.size(), equalTo(2));
assertThat("this", is(not("that")));
destroy(graphdb1);
destroy(graphdb2);
}
use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.
the class UdcExtensionImplTest method shouldBeAbleToSpecifySourceWithConfig.
@Test
public void shouldBeAbleToSpecifySourceWithConfig() throws Exception {
// first, set up the test server
LocalTestServer server = new LocalTestServer(null, null);
PingerHandler handler = new PingerHandler();
server.register("/*", handler);
server.start();
final String hostname = server.getServiceHostName();
final String serverAddress = hostname + ":" + server.getServicePort();
Map<String, String> config = new HashMap<String, String>();
config.put(UdcExtensionImpl.FIRST_DELAY_CONFIG_KEY, "100");
config.put(UdcExtensionImpl.UDC_HOST_ADDRESS_KEY, serverAddress);
config.put(UdcExtensionImpl.UDC_SOURCE_KEY, "test");
EmbeddedGraphDatabase graphdb = createTempDatabase(config);
assertGotSuccessWithRetry(IS_GREATER_THAN_ZERO);
assertEquals("test", handler.getQueryMap().get("source"));
destroy(graphdb);
}
use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.
the class UdcExtensionImplTest method createTempDatabase.
private EmbeddedGraphDatabase createTempDatabase(Map<String, String> config) throws IOException {
EmbeddedGraphDatabase tempdb = null;
String randomDbName = "tmpdb-" + rnd.nextInt();
File possibleDirectory = new File("target" + File.separator + randomDbName);
if (possibleDirectory.exists()) {
FileUtils.deleteDirectory(possibleDirectory);
}
if (config == null) {
tempdb = new EmbeddedGraphDatabase(randomDbName);
} else {
tempdb = new EmbeddedGraphDatabase(randomDbName, config);
}
return tempdb;
}
Aggregations