Search in sources :

Example 61 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class Mapper method clearMapping.

void clearMapping() {
    final SQLiteDatabase database = mDatabase.getSQLiteDatabase();
    database.beginTransaction();
    try {
        mInMappingIds.clear();
        // Disconnect all device rows.
        try {
            startAddingDocuments(null);
            stopAddingDocuments(null);
        } catch (FileNotFoundException exception) {
            Log.e(MtpDocumentsProvider.TAG, "Unexpected FileNotFoundException.", exception);
            throw new RuntimeException(exception);
        }
        database.setTransactionSuccessful();
    } finally {
        database.endTransaction();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) FileNotFoundException(java.io.FileNotFoundException)

Example 62 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class Mapper method startAddingDocuments.

/**
     * Starts adding new documents.
     * It changes the direct child documents of the given document from VALID to INVALIDATED.
     * Note that it keeps DISCONNECTED documents as they are.
     *
     * @param parentDocumentId Parent document ID or NULL for root documents.
     * @throws FileNotFoundException
     */
void startAddingDocuments(@Nullable String parentDocumentId) throws FileNotFoundException {
    final String selection;
    final String[] args;
    if (parentDocumentId != null) {
        selection = COLUMN_PARENT_DOCUMENT_ID + " = ?";
        args = strings(parentDocumentId);
    } else {
        selection = COLUMN_PARENT_DOCUMENT_ID + " IS NULL";
        args = EMPTY_ARGS;
    }
    final SQLiteDatabase database = mDatabase.getSQLiteDatabase();
    database.beginTransaction();
    try {
        getParentOrHaltMapping(parentDocumentId);
        Preconditions.checkState(!mInMappingIds.contains(parentDocumentId));
        // Set all valid documents as invalidated.
        final ContentValues values = new ContentValues();
        values.put(COLUMN_ROW_STATE, ROW_STATE_INVALIDATED);
        database.update(TABLE_DOCUMENTS, values, selection + " AND " + COLUMN_ROW_STATE + " = ?", DatabaseUtils.appendSelectionArgs(args, strings(ROW_STATE_VALID)));
        database.setTransactionSuccessful();
        mInMappingIds.add(parentDocumentId);
    } finally {
        database.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 63 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method readPreviousNameInternal.

private String readPreviousNameInternal(UserAccounts accounts, Account account) {
    if (account == null) {
        return null;
    }
    synchronized (accounts.cacheLock) {
        AtomicReference<String> previousNameRef = accounts.previousNameCache.get(account);
        if (previousNameRef == null) {
            final SQLiteDatabase db = accounts.openHelper.getReadableDatabase();
            Cursor cursor = db.query(TABLE_ACCOUNTS, new String[] { ACCOUNTS_PREVIOUS_NAME }, ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE + "=?", new String[] { account.name, account.type }, null, null, null);
            try {
                if (cursor.moveToNext()) {
                    String previousName = cursor.getString(0);
                    previousNameRef = new AtomicReference<>(previousName);
                    accounts.previousNameCache.put(account, previousNameRef);
                    return previousName;
                } else {
                    return null;
                }
            } finally {
                cursor.close();
            }
        } else {
            return previousNameRef.get();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 64 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method logRecord.

private void logRecord(UserAccounts accounts, String action, String tableName) {
    SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
    logRecord(db, action, tableName, -1, accounts);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 65 with SQLiteDatabase

use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.

the class AccountManagerService method logRecordWithUid.

private void logRecordWithUid(UserAccounts accounts, String action, String tableName, int uid) {
    SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
    logRecord(db, action, tableName, -1, accounts, uid);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21