Showing posts with label amazon. Show all posts
Showing posts with label amazon. Show all posts

Wednesday, April 17, 2013

Amazon SimpleDB deleteAttributes() example c c++ objc

deleteAttributes:

Deletes one or more attributes associated with an item. If all attributes of the item are deleted, the item is deleted.
NOTE: If DeleteAttributes is called without being passed any attributes or values specified, all the attributes for the item are deleted.
DeleteAttributes is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.
Because Amazon SimpleDB makes multiple copies of item data and uses an eventual consistency update model, performing a GetAttributes or Select operation (read) immediately after a DeleteAttributes or PutAttributes operation (write) might not return updated item data.
- (SimpleDBDeleteAttributesResponse *)deleteAttributes:(SimpleDBDeleteAttributesRequest *)deleteAttributesRequest

Parameters

deleteAttributesRequest
Container for the necessary parameters to execute the DeleteAttributes service method on AmazonSimpleDB.
Example
// Delete attributes of the specified item in the specified domain.
//  If the attributes are not specified, it will delete the item in the domain.
//
+ (void)deleteAttributesWithDomainName:(NSString *)domainName
                              itemName:(NSString *)itemName
                            attributes:(NSArray *)attributes
{
    // Start Network Activity Indicator.
    //
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

    // Construct request form.
    //
    SimpleDBDeleteAttributesRequest     *deleteRequest = [[[SimpleDBDeleteAttributesRequest alloc] initWithDomainName:domainName andItemName:itemName] autorelease];

    [deleteRequest setRequestEndpoint:AMAZON_SDB_US_EAST_1_ENDPOINT_SECURE];
    
    if( attributes )
    {
        for(NSString *attrName in attributes )
            [deleteRequest addAttribute:[[[SimpleDBAttribute alloc] initWithName:attrName andValue:nil] autorelease]];
    }
    
    // Do request delete.
    //
    SimpleDBDeleteAttributesResponse    *deleteResponse = [[AmazonClientManager sdb] deleteAttributes:deleteRequest];
    
    if( deleteResponse.error != nil )
    {
        NSLog(@"Error: %@", deleteResponse.error);
    }
    
    // Stop Network Activity Indicator.
    //
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    
    // Return.
    //
    return;
}



Amazon SimpleDB listDomains() example c c++ objc


listDomains:

The ListDomains operation lists all domains associated with the Access Key ID. It returns domain names up to the limit set by MaxNumberOfDomains. A NextToken is returned if there are more than MaxNumberOfDomains domains. Calling ListDomains successive times with the NextToken provided by the operation returns up to MaxNumberOfDomains more domain names with each successive operation call.
- (SimpleDBListDomainsResponse *)listDomains:(SimpleDBListDomainsRequest *)listDomainsRequest

Parameters

listDomainsRequest
Container for the necessary parameters to execute the ListDomains service method on AmazonSimpleDB.

Return Value

The response from the ListDomains service method, as returned by AmazonSimpleDB.
Example
{
   // Get domain lists.
    //
    int                                 setMaxNumberOfDomains = 10;
    NSMutableArray              *domains = nil;

    SimpleDBListDomainsRequest  *listDomainsRequest  = [[[SimpleDBListDomainsRequest alloc] init] autorelease];

    [listDomainsRequest setRequestEndpoint:AMAZON_SDB_US_EAST_1_ENDPOINT_SECURE];
    [listDomainsRequest setMaxNumberOfDomains:[NSNumber numberWithInt:maxNumberOfDomains]];
    
    // Call listDomains() on AWS SimpleDB
    //
    SimpleDBListDomainsResponse *listDomainsResponse = [[AmazonClientManager sdb] listDomains:listDomainsRequest];
    
    if(listDomainsResponse.error != nil)
    {
        NSLog(@"Error: %@", listDomainsResponse.error);
    }
    
    domains = [[[NSMutableArray alloc] initWithCapacity:[listDomainsResponse.domainNames count]] autorelease];
   
    for (NSString *name in listDomainsResponse.domainNames)
        [domains addObject:name];
    
    return domains;
}

Amazon SimpleDB select() example c c++ objc


select:

The Select operation returns a set of attributes for ItemNames that match the select expression. Select is similar to the standard SQL SELECT statement.
The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB automatically adjusts the number of items returned per page to enforce this limit. For example, if the client asks to retrieve 2500 items, but each individual item is 10 kB in size, the system returns 100 items and an appropriate NextToken so the client can access the next page of results.
For information on how to construct select expressions, see Using Select to Create Amazon SimpleDB Queries in the Developer Guide.
- (SimpleDBSelectResponse *)select:(SimpleDBSelectRequest *)selectRequest

Parameters

selectRequest
Container for the necessary parameters to execute the Select service method on AmazonSimpleDB.

Return Value

The response from the Select service method, as returned by AmazonSimpleDB.

Example


{
    NSString      *expression = @"select * from `domainName` limit 100";
    // Construct request.
    //
    SimpleDBSelectRequest   *selectRequest = [[[SimpleDBSelectRequest alloc] initWithSelectExpression:expression] autorelease];

    [selectRequest setRequestEndpoint:AMAZON_SDB_US_EAST_1_ENDPOINT_SECURE];
    
    // Perform select operation.
    //
    SimpleDBSelectResponse  *selectResponse = [[AmazonClientManager sdb] select:selectRequest];
    if( selectResponse.error != nil )
    {
        NSLog(@"Error: %@", selectResponse.error);
    }
   
    return selectResponse.items;
}

Amazon SimpleDB putAttributes example c c++ objc

putAttributes:
The PutAttributes operation creates or replaces attributes in an item. The client may specify new attributes using a combination of the Attribute.X.Name and Attribute.X.Value parameters. The client specifies the first attribute by the parameters Attribute.0.Name and Attribute.0.Value , the second attribute by the parameters Attribute.1.Name and Attribute.1.Value , and so on. [putAttributes]
Attributes are uniquely identified in an item by their name/value combination. For example, a single item can have the attributes { "first_name", "first_value" } and { "first_name", second_value" } . However, it cannot have two attribute instances where both the Attribute.X.Name and Attribute.X.Value are the same.[putAttributes]
Optionally, the requestor can supply the Replace parameter for each individual attribute. Setting this value to true causes the new attribute value to replace the existing attribute value(s). For example, if an item has the attributes { ‘a’, ‘1’ } ,
- (SimpleDBPutAttributesResponse *)putAttributes:(SimpleDBPutAttributesRequest *)putAttributesRequest

Parameters

putAttributesRequest
Container for the necessary parameters to execute the PutAttributes service method on AmazonSimpleDB.
Example
{
   // Construct attribute (name, value) pairs to put.
   //
    NSMutableArray  *attrList = [[[NSMutableArray alloc] initWithCapacity:attrs.size()] autorelease];
    
    for( int i=0; i<10; i++)
    {
        SimpleDBReplaceableAttribute    *attr = [[[SimpleDBReplaceableAttribute alloc] initWithName: [NSString stringWithFormat:@"attr%d", i] andValue:[NSString stringWithFormat:"@value%d", i] andReplace:YES] autorelease];

        [attrList addObject:attr];
    }

    // Do Put Attributes request to AWS.
    //
    SimpleDBPutAttributesRequest    *putRequest = [[SimpleDBPutAttributesRequest alloc] initWithDomainName:domainName andItemName:itemName andAttributes:attrList];

    [putRequest setRequestEndpoint:AMAZON_SDB_US_EAST_1_ENDPOINT_SECURE];

    SimpleDBPutAttributesResponse   *putResponse = [[AmazonClientManager sdb] putAttributes:putRequest];

    if(putResponse.error != nil)
    {
        NSLog(@"Error: %@", putResponse.error);
    }
}



Amazon SimpleDB getAttributes example c c++ objc

getAttributes:
Returns all of the attributes associated with the specified item. Optionally, the attributes returned can be limited to one or more attributes by specifying an attribute name parameter.
If the item does not exist on the replica that was accessed for this operation, an empty set is returned. The system does not return an error as it cannot guarantee the item does not exist on other replicas.
NOTE: If GetAttributes is called without being passed any attribute names, all the attributes for the item are returned.
- (SimpleDBGetAttributesResponse *)getAttributes:(SimpleDBGetAttributesRequest *)getAttributesRequest

Parameters

getAttributesRequest
Container for the necessary parameters to execute the GetAttributes service method on AmazonSimpleDB.

Return Value

The response from the GetAttributes service method, as returned by AmazonSimpleDB.
Example
{
     NSString        *domainName = @"domainName";
     NSString        *itemName = @"itemName";
     NSMutableArray  attributes = [NSMutableArray arrayWithObjects:@"attr1", @"attr2", nil];    

    // Construct getAttributes request.
    //
    SimpleDBGetAttributesRequest *gar = [[[SimpleDBGetAttributesRequest alloc] initWithDomainName:domainName   andItemName:itemName] autorelease];

    if( attributes )
    {
        for( NSString *attr in attributes )
            [gar addAttributeName:attr];
    }
    
    // Perform getAttributes() on the AWS SimpleDB
    //
    SimpleDBGetAttributesResponse *response = [[AmazonClientManager sdb] getAttributes:gar];
    if(response.error != nil)
    {
        NSLog(@"Error: %@", response.error);
    }

   for (SimpleDBAttribute *attr in response.attributes )
        NSLog(@"%@ -> %@", attr.name, attr.value);

}