Note that there are some explanatory texts on larger screens.

plurals
  1. POdb4o on Android 3.0+ Issue
    primarykey
    data
    text
    <p>I'm having an issue with db4o on Android 3.0+ because it turns out that on the creation of the db4o database, it uses some of the network apis by default. (I stumbled upon this post: <a href="http://mavistechchannel.wordpress.com/2011/11/18/db4o-at-honeycomb-and-ice-cream-sandwich/" rel="nofollow">http://mavistechchannel.wordpress.com/2011/11/18/db4o-at-honeycomb-and-ice-cream-sandwich/</a> about it)</p> <p>However, I've attempted to make the db creation requests async, but I think I'm running into an issue of calling the db before it's fully created as it locks the DB. (And I now get a locking error) Is there any way I can do this synchronous? or, at a minimum wait until it's been finished? Here's my db4o helper:</p> <pre><code>public class Db4oHelperAsync implements Constants{ private static final String USE_INTERNAL_MEMORY_FOR_DATABASE = "USE_INTERNAL_MEMORY_FOR_DATABASE"; private static ObjectContainer oc = null; private Context context; /** * @param ctx */ public Db4oHelperAsync(Context ctx) { context = ctx; } /** * Create, open and close the database */ public ObjectContainer db() { if (oc == null || oc.ext().isClosed()) { if (Utilities.getPreferences(context).getBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true)) { new GetDbFromInternalMemory().execute(); } else { new GetDbFromSDCard().execute(); } return oc; } else { return oc; } } /** * Configure the behavior of the database */ private EmbeddedConfiguration dbConfig() throws IOException { EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration(); configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).objectField("name").indexed(true); configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnUpdate(true); configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnActivate(true); configuration.common().objectClass(PersistentObjectWithCascadeOnDelete.class).cascadeOnDelete(true); configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).objectField("name").indexed(true); configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnUpdate(true); configuration.common().objectClass(PersistentObjectWithoutCascadeOnDelete.class).cascadeOnActivate(true); return configuration; } /** * Returns the path for the database location */ private String db4oDBFullPathInternal(Context ctx) { return ctx.getDir("data", 0) + "/" + "testapp.db4o"; } private String db4oDBFullPathSdCard(Context ctx) { File path = new File(Environment.getExternalStorageDirectory(), ".testapp"); if (!path.exists()) { path.mkdir(); } return path + "/" + "testapp.db4o"; } /** * Closes the database */ public void close() { if (oc != null) oc.close(); } private class GetDbFromInternalMemory extends AsyncTask&lt;Void, Void, ObjectContainer&gt;{ @Override protected ObjectContainer doInBackground(Void... params) { try { ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathInternal(context)); CLog.v("USING INTERNAL MEMORY FOR DATABASE"); return obj; } catch (Exception ie) { ie.printStackTrace(); CLog.e(Db4oHelper.class.getName(), ie.toString()); return null; } } @Override protected void onPostExecute(ObjectContainer result) { oc = result; } } private class GetDbFromSDCard extends AsyncTask&lt;Void, Void, ObjectContainer&gt;{ @Override protected ObjectContainer doInBackground(Void... params) { try { ObjectContainer obj = Db4oEmbedded.openFile(dbConfig(), db4oDBFullPathSdCard(context)); CLog.v("USING SDCARD FOR DATABASE"); SharedPreferences.Editor edit = Utilities.getPreferencesEditor(context); edit.putBoolean(USE_INTERNAL_MEMORY_FOR_DATABASE, true); edit.commit(); return obj; } catch (Exception ie) { ie.printStackTrace(); CLog.e(Db4oHelper.class.getName(), ie.toString()); return null; } } @Override protected void onPostExecute(ObjectContainer result) { oc = result; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload