Domanda

DB4O doesn't seem to provide a method to check if the database (ObjectContainer) is closed. So right now, this is the code I use to see if it's closed. I get the feeling there is a better way to do this.

    public ObjectContainer getDb() {

    if (db == null) {
        System.out.println("db was null in " + dbci
                + " connection. Had to create new DB object.");
        db = Db4oEmbedded.openFile(dbci.getConnectionName());
    }
    try{
        db.query();
    }
    catch(Exception e){
         db = Db4oEmbedded.openFile(dbci.getConnectionName());
    }
    return db;
}

Is there a way around a try/catch block like this?

È stato utile?

Soluzione

db4o does provide a method to check if the object container is closed or not.

Take a look in ExtObjectContainer#isClosed() method.

http://source.db4o.com/db4o/trunk/db4oj/core/src/com/db4o/ext/ExtObjectContainer.java

Hope this helps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top