use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.
the class CognitoSyncStorage method getDatasets.
/*
* (non-Javadoc)
* @see com.amazonaws.cognitov2.RemoteStorage#listDatasets()
*/
@Override
public List<DatasetMetadata> getDatasets() {
List<DatasetMetadata> datasets = new ArrayList<DatasetMetadata>();
String nextToken = null;
do {
ListDatasetsRequest request = new ListDatasetsRequest();
appendUserAgent(request, userAgent);
request.setIdentityPoolId(identityPoolId);
// a large enough number to reduce # of requests
request.setMaxResults("64");
request.setNextToken(nextToken);
ListDatasetsResult result = null;
try {
request.setIdentityId(getIdentityId());
result = client.listDatasets(request);
} catch (AmazonClientException ace) {
throw handleException(ace, "Failed to list dataset metadata");
}
for (com.amazonaws.services.cognitosync.model.Dataset dataset : result.getDatasets()) {
datasets.add(modelToDatasetMetadata(dataset));
}
nextToken = result.getNextToken();
} while (nextToken != null);
return datasets;
}
use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.
the class SQLiteLocalStorage method getDatasetMetadata.
@Override
public DatasetMetadata getDatasetMetadata(String identityId, String datasetName) throws DataStorageException {
DatasetMetadata dataset = null;
SQLiteDatabase db = helper.getWritableDatabase();
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()) {
dataset = cursorToDatasetMetadata(c);
}
c.close();
return dataset;
}
use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.
the class SQLiteLocalStorage method getCommonDatasetNames.
/**
* Checks the metadata of all datasets for one identity id and another to
* see if any have the same name.
*
* @param oldIdentityId the old identity id, which the user is changing from
* @param newIdentityId the new identity id, which the user is changing to
* @return a set of all of the non unique names
*/
Set<String> getCommonDatasetNames(String oldIdentityId, String newIdentityId) {
Set<String> newNameSet = new HashSet<String>();
Set<String> oldNameSet = new HashSet<String>();
if (oldIdentityId != null && newIdentityId != null) {
List<DatasetMetadata> newDatasets = getDatasets(newIdentityId);
List<DatasetMetadata> oldDatasets = getDatasets(oldIdentityId);
for (DatasetMetadata oldMetaData : oldDatasets) {
oldNameSet.add(oldMetaData.getDatasetName());
}
for (DatasetMetadata newMetaData : newDatasets) {
newNameSet.add(newMetaData.getDatasetName());
}
oldNameSet.retainAll(newNameSet);
}
return oldNameSet;
}
use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.
the class SQLiteLocalStorage method createDataset.
/**
* Creates a new {@link Dataset}. Stores its information in datasets table.
* Nothing will happen if a dataset with the same name exists. This should
* be called before any operation related to this dataset name is performed.
* Otherwise this dataset won't be visible in listDatasets and will result
* in dangled records.
*
* @param identityId identity id
* @param datasetName dataset name
*/
public void createDataset(String identityId, String datasetName) {
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
// check if the dataset exists or not
DatasetMetadata metadata = getMetadataInternal(db, identityId, datasetName);
if (metadata == null) {
// add a new entry if it doesn't exist
ContentValues values = new ContentValues();
values.put(DatasetColumns.IDENTITY_ID, identityId);
values.put(DatasetColumns.DATASET_NAME, datasetName);
values.put(DatasetColumns.CREATION_TIMESTAMP, String.valueOf(new Date().getTime()));
values.put(DatasetColumns.LAST_MODIFIED_TIMESTAMP, String.valueOf(new Date().getTime()));
// use default values for other fields
long row = db.insert(TABLE_DATASETS, null, values);
if (row == -1) {
Log.e(TAG, String.format("couldn't create dataset %s", datasetName));
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
use of com.amazonaws.mobileconnectors.cognito.DatasetMetadata in project amazon-cognito-android by aws.
the class CognitoSyncStorage method getDatasetMetadata.
@Override
public DatasetMetadata getDatasetMetadata(String datasetName) throws DataStorageException {
DescribeDatasetRequest request = new DescribeDatasetRequest();
appendUserAgent(request, userAgent);
request.setIdentityPoolId(identityPoolId);
DatasetMetadata dataset = null;
try {
request.setIdentityId(getIdentityId());
request.setDatasetName(datasetName);
DescribeDatasetResult result = client.describeDataset(request);
dataset = modelToDatasetMetadata(result.getDataset());
} catch (AmazonClientException ace) {
throw handleException(ace, "Failed to get metadata of dataset: " + datasetName);
}
return dataset;
}
Aggregations