gnunet-android

GNUnet for Android
Log | Files | Refs | README

SQLiteDirectCursorDriver.java (2573B)


      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 /*
     17 ** Modified to support SQLite extensions by the SQLite developers: 
     18 ** sqlite-dev@sqlite.org.
     19 */
     20 
     21 package org.sqlite.database.sqlite;
     22 
     23 import android.database.Cursor;
     24 import org.sqlite.database.sqlite.SQLiteDatabase.CursorFactory;
     25 import android.os.CancellationSignal;
     26 
     27 /**
     28  * A cursor driver that uses the given query directly.
     29  * 
     30  * @hide
     31  */
     32 public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
     33     private final SQLiteDatabase mDatabase;
     34     private final String mEditTable; 
     35     private final String mSql;
     36     private final CancellationSignal mCancellationSignal;
     37     private SQLiteQuery mQuery;
     38 
     39     public SQLiteDirectCursorDriver(SQLiteDatabase db, String sql, String editTable,
     40             CancellationSignal cancellationSignal) {
     41         mDatabase = db;
     42         mEditTable = editTable;
     43         mSql = sql;
     44         mCancellationSignal = cancellationSignal;
     45     }
     46 
     47     public Cursor query(CursorFactory factory, String[] selectionArgs) {
     48         final SQLiteQuery query = new SQLiteQuery(mDatabase, mSql, mCancellationSignal);
     49         final Cursor cursor;
     50         try {
     51             query.bindAllArgsAsStrings(selectionArgs);
     52 
     53             if (factory == null) {
     54                 cursor = new SQLiteCursor(this, mEditTable, query);
     55             } else {
     56                 cursor = factory.newCursor(mDatabase, this, mEditTable, query);
     57             }
     58         } catch (RuntimeException ex) {
     59             query.close();
     60             throw ex;
     61         }
     62 
     63         mQuery = query;
     64         return cursor;
     65     }
     66 
     67     public void cursorClosed() {
     68         // Do nothing
     69     }
     70 
     71     public void setBindArguments(String[] bindArgs) {
     72         mQuery.bindAllArgsAsStrings(bindArgs);
     73     }
     74 
     75     public void cursorDeactivated() {
     76         // Do nothing
     77     }
     78 
     79     public void cursorRequeried(Cursor cursor) {
     80         // Do nothing
     81     }
     82 
     83     @Override
     84     public String toString() {
     85         return "SQLiteDirectCursorDriver: " + mSql;
     86     }
     87 }