@Provides
 public ODatabaseDocument getDatabaseRecord() {
   ODatabaseDocument db =
       DefaultODatabaseThreadLocalFactory.castToODatabaseDocument(
           ODatabaseRecordThreadLocal.INSTANCE.get().getDatabaseOwner());
   if (db.isClosed()) {
     ODatabaseRecordThreadLocal.INSTANCE.remove();
     db =
         DefaultODatabaseThreadLocalFactory.castToODatabaseDocument(
             ODatabaseRecordThreadLocal.INSTANCE.get().getDatabaseOwner());
   }
   return db;
 }
Beispiel #2
0
  public static ODatabaseDocument getDb() {
    ODatabaseDocument db = DatabaseObjects.INSTANCE.get();
    boolean useServer = Application.getConfig().getBooleanProperty("db.server", false);

    if (db == null) {
      db = new ODatabaseDocumentTx(useServer ? "remote:localhost/main" : "local:data");

      if (!useServer && !db.exists()) db.create();

      if (db.isClosed()) db.open("admin", "admin");
    }

    ODatabaseRecordThreadLocal.INSTANCE.get().setDatabaseOwner(db);
    DatabaseObjects.INSTANCE.set(db);

    return db;
  }