Home | History | Annotate | Download | only in SQLite
      1 package SQLite;
      2 
      3 /**
      4  * Class wrapping an SQLite backup object.
      5  */
      6 
      7 public class Backup {
      8 
      9     /**
     10      * Internal handle for the native SQLite API.
     11      */
     12 
     13     protected long handle = 0;
     14 
     15     /**
     16      * Finish a backup.
     17      */
     18 
     19     protected void finish() throws SQLite.Exception {
     20 	synchronized(this) {
     21 	    _finalize();
     22 	}
     23     }
     24 
     25     /**
     26      * Destructor for object.
     27      */
     28 
     29     protected void finalize() {
     30 	synchronized(this) {
     31 	    try {
     32 		_finalize();
     33 	    } catch (SQLite.Exception e) {
     34 	    }
     35 	}
     36     }
     37 
     38     protected native void _finalize() throws SQLite.Exception;
     39 
     40     /**
     41      * Perform a backup step.
     42      *
     43      * @param n number of pages to backup
     44      * @return true when backup completed
     45      */
     46 
     47     public boolean step(int n) throws SQLite.Exception {
     48 	synchronized(this) {
     49 	    return _step(n);
     50 	}
     51     }
     52 
     53     private native boolean _step(int n) throws SQLite.Exception;
     54 
     55     /**
     56      * Perform the backup in one step.
     57      */
     58 
     59     public void backup() throws SQLite.Exception {
     60 	synchronized(this) {
     61 	    _step(-1);
     62 	}
     63     }
     64 
     65     /**
     66      * Return number of remaining pages to be backed up.
     67      */
     68 
     69     public int remaining() throws SQLite.Exception {
     70 	synchronized(this) {
     71 	    return _remaining();
     72 	}
     73     }
     74 
     75     private native int _remaining() throws SQLite.Exception;
     76 
     77     /**
     78      * Return the total number of pages in the backup source database.
     79      */
     80 
     81     public int pagecount() throws SQLite.Exception {
     82 	synchronized(this) {
     83 	    return _pagecount();
     84 	}
     85     }
     86 
     87     private native int _pagecount() throws SQLite.Exception;
     88 
     89     /**
     90      * Internal native initializer.
     91      */
     92 
     93     private static native void internal_init();
     94 
     95     static {
     96 	internal_init();
     97     }
     98 }
     99 
    100