Search in sources :

Example 1 with TableServiceEntity

use of com.microsoft.azure.storage.table.TableServiceEntity 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 TableServiceEntity

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

the class AzureClient method readSubset.

/*
   * Read subset of properties instead of full fields with projection.
   */
public Status readSubset(String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    String whereStr = String.format("RowKey eq '%s'", key);
    TableQuery<TableServiceEntity> projectionQuery = TableQuery.from(TableServiceEntity.class).where(whereStr).select(fields.toArray(new String[0]));
    EntityResolver<HashMap<String, ByteIterator>> resolver = new EntityResolver<HashMap<String, ByteIterator>>() {

        public HashMap<String, ByteIterator> resolve(String partitionkey, String rowKey, Date timeStamp, HashMap<String, EntityProperty> properties, String etag) {
            HashMap<String, ByteIterator> tmp = new HashMap<String, ByteIterator>();
            for (Entry<String, EntityProperty> entry : properties.entrySet()) {
                String key = entry.getKey();
                ByteIterator val = new ByteArrayByteIterator(entry.getValue().getValueAsByteArray());
                tmp.put(key, val);
            }
            return tmp;
        }
    };
    try {
        for (HashMap<String, ByteIterator> tmp : cloudTable.execute(projectionQuery, resolver)) {
            for (Entry<String, ByteIterator> entry : tmp.entrySet()) {
                String fieldName = entry.getKey();
                ByteIterator fieldVal = entry.getValue();
                result.put(fieldName, fieldVal);
            }
        }
        return Status.OK;
    } catch (Exception e) {
        return Status.ERROR;
    }
}
Also used : HashMap(java.util.HashMap) EntityResolver(com.microsoft.azure.storage.table.EntityResolver) TableServiceEntity(com.microsoft.azure.storage.table.TableServiceEntity) Date(java.util.Date) DBException(com.yahoo.ycsb.DBException) EntityProperty(com.microsoft.azure.storage.table.EntityProperty) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator)

Aggregations

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