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;
}
}
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;
}
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();
}
}
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;
}
Aggregations