@ InterfaceAudience . Public public boolean replaceDatabase ( String databaseName , String databaseDir ) { Database db = getDatabase ( databaseName , false ) ; if ( db == null ) return false ; File dir = new File ( databaseDir ) ; if ( ! dir . exists ( ) ) { Log . w ( Database . TAG , "Database file doesn't exist at path : %s" , databaseDir ) ; return false ; } if ( ! dir . isDirectory ( ) ) { Log . w ( Database . TAG , "Database file is not a directory. " + "Use -replaceDatabaseNamed:withDatabaseFilewithAttachments:error: instead." ) ; return false ; } File destDir = new File ( db . getPath ( ) ) ; File srcDir = new File ( databaseDir ) ; if ( destDir . exists ( ) ) { if ( ! FileDirUtils . deleteRecursive ( destDir ) ) { Log . w ( Database . TAG , "Failed to delete file/directly: " + destDir ) ; return false ; } } try { FileDirUtils . copyFolder ( srcDir , destDir ) ; } catch ( IOException e ) { Log . w ( Database . TAG , "Failed to copy directly from " + srcDir + " to " + destDir , e ) ; return false ; } try { db . open ( ) ; } catch ( CouchbaseLiteException e ) { Log . w ( Database . TAG , "Failed to open database" , e ) ; return false ; } /* TODO: Currently Java implementation is different from iOS, needs to catch up. if(!db.saveLocalUUIDInLocalCheckpointDocument()){ Log.w(Database.TAG, "Failed to replace UUIDs"); return false; } */ if ( ! db . replaceUUIDs ( ) ) { Log . w ( Database . TAG , "Failed to replace UUIDs" ) ; db . close ( ) ; return false ; } // close so app can (re)open db with its preferred options: db . close ( ) ; return true ; }
Replaces or installs a database from a file .