Search in sources :

Example 6 with DatasetMetadata

use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.

the class SQLiteLocalStorage method updateDatasetMetadataInternal.

/**
 * Internal helper function to update one dataset metadata.
 *
 * @param db SQLiteDatabase handler
 * @param identityId identity id of the datasets
 * @param metadata dataset metadata to update
 * @return true if update successfully, false otherwise
 */
boolean updateDatasetMetadataInternal(SQLiteDatabase db, String identityId, DatasetMetadata metadata) {
    DatasetMetadata local = getMetadataInternal(db, identityId, metadata.getDatasetName());
    ContentValues values = new ContentValues();
    values.put(DatasetColumns.IDENTITY_ID, identityId);
    values.put(DatasetColumns.DATASET_NAME, metadata.getDatasetName());
    values.put(DatasetColumns.CREATION_TIMESTAMP, metadata.getCreationDate().getTime());
    values.put(DatasetColumns.LAST_MODIFIED_TIMESTAMP, metadata.getLastModifiedDate().getTime());
    values.put(DatasetColumns.LAST_MODIFIED_BY, metadata.getLastModifiedBy());
    values.put(DatasetColumns.RECORD_COUNT, metadata.getRecordCount());
    values.put(DatasetColumns.STORAGE_SIZE_BYTES, metadata.getStorageSizeBytes());
    if (local == null) {
        return db.insert(TABLE_DATASETS, null, values) != -1;
    } else {
        return db.update(TABLE_DATASETS, values, DatasetColumns.IDENTITY_ID + " = ? AND " + DatasetColumns.DATASET_NAME + " = ?", new String[] { identityId, metadata.getDatasetName() }) == 1;
    }
}
Also used : ContentValues(android.content.ContentValues) DatasetMetadata(com.amazonaws.mobileconnectors.cognito.DatasetMetadata)

Example 7 with DatasetMetadata

use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.

the class SQLiteLocalStorage method getDatasets.

@Override
public List<DatasetMetadata> getDatasets(String identityId) {
    List<DatasetMetadata> datasets = new ArrayList<DatasetMetadata>();
    SQLiteDatabase db = helper.getWritableDatabase();
    Cursor c = db.query(TABLE_DATASETS, DatasetColumns.ALL, DatasetColumns.IDENTITY_ID + " = ?", new String[] { identityId }, null, null, null);
    while (c.moveToNext()) {
        datasets.add(cursorToDatasetMetadata(c));
    }
    c.close();
    return datasets;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DatasetMetadata(com.amazonaws.mobileconnectors.cognito.DatasetMetadata) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 8 with DatasetMetadata

use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.

the class SQLiteLocalStorage method updateDatasetMetadata.

@Override
public void updateDatasetMetadata(String identityId, List<DatasetMetadata> datasetMetadata) {
    SQLiteDatabase db = helper.getWritableDatabase();
    db.beginTransaction();
    try {
        for (DatasetMetadata metadata : datasetMetadata) {
            if (!updateDatasetMetadataInternal(db, identityId, metadata)) {
                Log.w(TAG, String.format("couldn't update dataset metadata %s", metadata.getDatasetName()));
            }
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DatasetMetadata(com.amazonaws.mobileconnectors.cognito.DatasetMetadata)

Example 9 with DatasetMetadata

use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.

the class SQLiteLocalStorage method getMetadataInternal.

/**
 * Internal helper function to get dataset metadata
 *
 * @param db SQLiteDatabase handler
 * @param identityId identity id of the datasets
 * @param datasetName dataset name
 * @return DatasetMetadata if found, or null if not found
 */
DatasetMetadata getMetadataInternal(SQLiteDatabase db, String identityId, String datasetName) {
    DatasetMetadata metadata = null;
    Cursor c = db.query(TABLE_DATASETS, DatasetColumns.ALL, DatasetColumns.IDENTITY_ID + " = ? AND " + DatasetColumns.DATASET_NAME + " = ?", new String[] { identityId, datasetName }, null, null, null);
    if (c.moveToFirst()) {
        metadata = cursorToDatasetMetadata(c);
    }
    c.close();
    return metadata;
}
Also used : DatasetMetadata(com.amazonaws.mobileconnectors.cognito.DatasetMetadata) Cursor(android.database.Cursor)

Aggregations

DatasetMetadata (com.amazonaws.mobileconnectors.cognito.DatasetMetadata)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 Cursor (android.database.Cursor)3 ContentValues (android.content.ContentValues)2 AmazonClientException (com.amazonaws.AmazonClientException)2 ArrayList (java.util.ArrayList)2 DescribeDatasetRequest (com.amazonaws.services.cognitosync.model.DescribeDatasetRequest)1 DescribeDatasetResult (com.amazonaws.services.cognitosync.model.DescribeDatasetResult)1 ListDatasetsRequest (com.amazonaws.services.cognitosync.model.ListDatasetsRequest)1 ListDatasetsResult (com.amazonaws.services.cognitosync.model.ListDatasetsResult)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1