Search in sources :

Example 61 with SQLException

use of android.database.SQLException in project aware-client by denzilferreira.

the class Barometer_Provider method bulkInsert.

/**
 * Batch insert for high performance sensors (e.g., accelerometer, etc)
 *
 * @param uri
 * @param values
 * @return values.length
 */
@Override
public synchronized int bulkInsert(Uri uri, ContentValues[] values) {
    initialiseDatabase();
    database.beginTransaction();
    int count = 0;
    switch(sUriMatcher.match(uri)) {
        case SENSOR_DEV:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[0], Barometer_Sensor.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[0], Barometer_Sensor.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        case SENSOR_DATA:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[1], Barometer_Data.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[1], Barometer_Data.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        default:
            database.endTransaction();
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    database.setTransactionSuccessful();
    database.endTransaction();
    getContext().getContentResolver().notifyChange(uri, null, false);
    return count;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException)

Example 62 with SQLException

use of android.database.SQLException in project aware-client by denzilferreira.

the class ESM_Provider method insert.

/**
 * Insert entry to the database
 */
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
    initialiseDatabase();
    ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
    database.beginTransaction();
    switch(sUriMatcher.match(uri)) {
        case ESMS_QUEUE:
            long quest_id = database.insertWithOnConflict(DATABASE_TABLES[0], ESM_Data.DEVICE_ID, values, SQLiteDatabase.CONFLICT_IGNORE);
            database.setTransactionSuccessful();
            database.endTransaction();
            if (quest_id > 0) {
                Uri questUri = ContentUris.withAppendedId(ESM_Data.CONTENT_URI, quest_id);
                getContext().getContentResolver().notifyChange(questUri, null, false);
                return questUri;
            }
            database.endTransaction();
            throw new SQLException("Failed to insert row into " + uri);
        default:
            database.endTransaction();
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Example 63 with SQLException

use of android.database.SQLException in project aware-client by denzilferreira.

the class Gravity_Provider method bulkInsert.

/**
 * Batch insert for high performance sensors (e.g., accelerometer, etc)
 *
 * @param uri
 * @param values
 * @return values.length
 */
@Override
public synchronized int bulkInsert(Uri uri, ContentValues[] values) {
    initialiseDatabase();
    database.beginTransaction();
    int count = 0;
    switch(sUriMatcher.match(uri)) {
        case SENSOR_DEV:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[0], Gravity_Sensor.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[0], Gravity_Sensor.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        case SENSOR_DATA:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[1], Gravity_Data.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[1], Gravity_Data.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        default:
            database.endTransaction();
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    database.setTransactionSuccessful();
    database.endTransaction();
    getContext().getContentResolver().notifyChange(uri, null, false);
    return count;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException)

Example 64 with SQLException

use of android.database.SQLException in project aware-client by denzilferreira.

the class Gyroscope_Provider method bulkInsert.

/**
 * Batch insert for high performance sensors (e.g., accelerometer, etc)
 *
 * @param uri
 * @param values
 * @return values.length
 */
@Override
public synchronized int bulkInsert(Uri uri, ContentValues[] values) {
    initialiseDatabase();
    database.beginTransaction();
    int count = 0;
    switch(sUriMatcher.match(uri)) {
        case GYRO_DEV:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[0], Gyroscope_Sensor.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[0], Gyroscope_Sensor.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        case GYRO_DATA:
            for (ContentValues v : values) {
                long id;
                try {
                    id = database.insertOrThrow(DATABASE_TABLES[1], Gyroscope_Data.DEVICE_ID, v);
                } catch (SQLException e) {
                    id = database.replace(DATABASE_TABLES[1], Gyroscope_Data.DEVICE_ID, v);
                }
                if (id <= 0) {
                    Log.w(Barometer.TAG, "Failed to insert/replace row into " + uri);
                } else {
                    count++;
                }
            }
            break;
        default:
            database.endTransaction();
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
    database.setTransactionSuccessful();
    database.endTransaction();
    getContext().getContentResolver().notifyChange(uri, null, false);
    return count;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException)

Example 65 with SQLException

use of android.database.SQLException in project aware-client by denzilferreira.

the class Installations_Provider method insert.

/**
 * Insert entry to the database
 */
@Override
public synchronized Uri insert(Uri uri, ContentValues initialValues) {
    initialiseDatabase();
    ContentValues values = (initialValues != null) ? new ContentValues(initialValues) : new ContentValues();
    database.beginTransaction();
    switch(sUriMatcher.match(uri)) {
        case INSTALLATIONS:
            long installations_id = database.insertWithOnConflict(DATABASE_TABLES[0], Installations_Data.PACKAGE_NAME, values, SQLiteDatabase.CONFLICT_IGNORE);
            database.setTransactionSuccessful();
            database.endTransaction();
            if (installations_id > 0) {
                Uri installationsUri = ContentUris.withAppendedId(Installations_Data.CONTENT_URI, installations_id);
                getContext().getContentResolver().notifyChange(installationsUri, null, false);
                return installationsUri;
            }
            database.endTransaction();
            throw new SQLException("Failed to insert row into " + uri);
        default:
            database.endTransaction();
            throw new IllegalArgumentException("Unknown URI " + uri);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Uri(android.net.Uri)

Aggregations

SQLException (android.database.SQLException)224 ContentValues (android.content.ContentValues)114 Uri (android.net.Uri)60 Cursor (android.database.Cursor)57 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)39 SQLiteException (android.database.sqlite.SQLiteException)18 Intent (android.content.Intent)16 ArrayList (java.util.ArrayList)14 SQLiteStatement (android.database.sqlite.SQLiteStatement)13 HandlerThread (android.os.HandlerThread)10 DatabaseUtils (android.database.DatabaseUtils)8 Gson (com.google.gson.Gson)8 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)7 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)6 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 IOException (java.io.IOException)5 BAction (io.github.mthli.Bitocle.Database.Bookmark.BAction)4 Test (org.junit.Test)4 Activity (android.app.Activity)3