Search in sources :

Example 1 with TableOperation

use of com.microsoft.azure.storage.table.TableOperation in project YCSB by brianfrankcooper.

the class AzureClient method delete.

@Override
public Status delete(String table, String key) {
    try {
        // firstly, retrieve the entity to be deleted
        TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, TableServiceEntity.class);
        TableServiceEntity entity = cloudTable.execute(retrieveOp).getResultAsType();
        // secondly, delete the entity
        TableOperation deleteOp = TableOperation.delete(entity);
        cloudTable.execute(deleteOp);
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : TableOperation(com.microsoft.azure.storage.table.TableOperation) TableServiceEntity(com.microsoft.azure.storage.table.TableServiceEntity) DBException(com.yahoo.ycsb.DBException)

Example 2 with TableOperation

use of com.microsoft.azure.storage.table.TableOperation in project YCSB by brianfrankcooper.

the class AzureClient method insertOrUpdate.

private Status insertOrUpdate(String key, HashMap<String, ByteIterator> values) {
    HashMap<String, EntityProperty> properties = new HashMap<String, EntityProperty>();
    for (Entry<String, ByteIterator> entry : values.entrySet()) {
        String fieldName = entry.getKey();
        byte[] fieldVal = entry.getValue().toArray();
        properties.put(fieldName, new EntityProperty(fieldVal));
    }
    DynamicTableEntity entity = new DynamicTableEntity(partitionKey, key, properties);
    TableOperation insertOrReplace = TableOperation.insertOrReplace(entity);
    try {
        cloudTable.execute(insertOrReplace);
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : EntityProperty(com.microsoft.azure.storage.table.EntityProperty) DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) HashMap(java.util.HashMap) TableOperation(com.microsoft.azure.storage.table.TableOperation) DBException(com.yahoo.ycsb.DBException)

Example 3 with TableOperation

use of com.microsoft.azure.storage.table.TableOperation in project YCSB by brianfrankcooper.

the class AzureClient method readEntity.

private Status readEntity(String key, HashMap<String, ByteIterator> result) {
    try {
        // firstly, retrieve the entity to be deleted
        TableOperation retrieveOp = TableOperation.retrieve(partitionKey, key, DynamicTableEntity.class);
        DynamicTableEntity entity = cloudTable.execute(retrieveOp).getResultAsType();
        HashMap<String, EntityProperty> properties = entity.getProperties();
        for (Entry<String, EntityProperty> entry : properties.entrySet()) {
            String fieldName = entry.getKey();
            ByteIterator fieldVal = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
            result.put(fieldName, fieldVal);
        }
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : DynamicTableEntity(com.microsoft.azure.storage.table.DynamicTableEntity) EntityProperty(com.microsoft.azure.storage.table.EntityProperty) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) TableOperation(com.microsoft.azure.storage.table.TableOperation) DBException(com.yahoo.ycsb.DBException)

Aggregations

TableOperation (com.microsoft.azure.storage.table.TableOperation)3 DBException (com.yahoo.ycsb.DBException)3 DynamicTableEntity (com.microsoft.azure.storage.table.DynamicTableEntity)2 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)2 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)2 ByteIterator (com.yahoo.ycsb.ByteIterator)2 TableServiceEntity (com.microsoft.azure.storage.table.TableServiceEntity)1 HashMap (java.util.HashMap)1