/** * Clears the database and recreates an empty version of it. This method acquires the exclusive lock before closing * the db -- it will block if other threads are in transactions. This method will throw an exception if called from * within a transaction. * <p> * If called from within the {@link #onUpgrade(ISQLiteDatabase, int, int)} or * {@link #onDowngrade(ISQLiteDatabase, int, int)} hooks, this method will abort the remainder of the * migration and simply clear the database. This method is also safe to call from within * {@link #onMigrationFailed(MigrationFailedException)} * <p> * WARNING: Any open database resources (e.g. cursors) will be invalid after calling this method. Do not call this * method if any open cursors may be in use. The existing database file will be deleted and all data will be lost, * with a new empty database taking its place. * * @see #clear() */ public final void recreate() { if (isInMigration) { throw new RecreateDuringMigrationException(); } else if (isInMigrationFailedHook || databaseOpenFailedRetryCount > 0) { recreateLocked(); // Safe to call here, necessary locks are already held in this case } else { acquireExclusiveLock(); try { recreateLocked(); } finally { releaseExclusiveLock(); } } }
/** * Clears the database and recreates an empty version of it. This method acquires the exclusive lock before closing * the db -- it will block if other threads are in transactions. This method will throw an exception if called from * within a transaction. * <p> * If called from within the {@link #onUpgrade(ISQLiteDatabase, int, int)} or * {@link #onDowngrade(ISQLiteDatabase, int, int)} hooks, this method will abort the remainder of the * migration and simply clear the database. This method is also safe to call from within * {@link #onMigrationFailed(MigrationFailedException)} * <p> * WARNING: Any open database resources (e.g. cursors) will be invalid after calling this method. Do not call this * method if any open cursors may be in use. The existing database file will be deleted and all data will be lost, * with a new empty database taking its place. * * @see #clear() */ public final void recreate() { if (isInMigration) { throw new RecreateDuringMigrationException(); } else if (isInMigrationFailedHook || databaseOpenFailedRetryCount > 0) { recreateLocked(); // Safe to call here, necessary locks are already held in this case } else { acquireExclusiveLock(); try { recreateLocked(); } finally { releaseExclusiveLock(); } } }