Search in sources :

Example 16 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project siena by mandubian.

the class SdbPersistenceManager method rawGetByKeys.

protected <T> List<T> rawGetByKeys(Class<T> clazz, Iterable<?> keys) {
    try {
        StringBuffer domainBuf = new StringBuffer();
        SelectRequest req = SdbMappingUtils.buildBatchGetQueryByKeys(clazz, keys, prefix, domainBuf);
        checkDomain(domainBuf.toString());
        req.setConsistentRead(isReadConsistent());
        SelectResult res = sdb.select(req);
        List<T> models = new ArrayList<T>();
        SdbMappingUtils.mapSelectResultToListOrderedFromKeys(res, models, clazz, keys);
        // join management
        if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
            mapJoins(models);
        }
        return models;
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) SienaException(siena.SienaException) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 17 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project camel by apache.

the class AmazonSDBClientMock method select.

@Override
public SelectResult select(SelectRequest selectRequest) throws AmazonServiceException, AmazonClientException {
    this.selectRequest = selectRequest;
    SelectResult result = new SelectResult();
    result.setNextToken("TOKEN2");
    result.getItems().add(new Item("ITEM1", null));
    result.getItems().add(new Item("ITEM2", null));
    return result;
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Item(com.amazonaws.services.simpledb.model.Item)

Example 18 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project SimianArmy by Netflix.

the class SimpleDBConformityClusterTracker method querySimpleDBItems.

private List<Item> querySimpleDBItems(String query) {
    Validate.notNull(query);
    String nextToken = null;
    List<Item> items = new ArrayList<Item>();
    do {
        SelectRequest request = new SelectRequest(query);
        request.setNextToken(nextToken);
        request.setConsistentRead(Boolean.TRUE);
        SelectResult result = this.simpleDBClient.select(request);
        items.addAll(result.getItems());
        nextToken = result.getNextToken();
    } while (nextToken != null);
    return items;
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) ArrayList(java.util.ArrayList) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 19 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project SimianArmy by Netflix.

the class TestSimpleDBRecorder method mkSelectResult.

private SelectResult mkSelectResult(String id) {
    Item item = new Item();
    List<Attribute> attrs = new LinkedList<Attribute>();
    attrs.add(new Attribute("id", id));
    attrs.add(new Attribute("eventTime", "1330538400000"));
    attrs.add(new Attribute("region", "region"));
    attrs.add(new Attribute("recordType", "MonkeyEvent"));
    attrs.add(new Attribute("monkeyType", "MONKEY|com.netflix.simianarmy.aws.TestSimpleDBRecorder$Type"));
    attrs.add(new Attribute("eventType", "EVENT|com.netflix.simianarmy.aws.TestSimpleDBRecorder$EventTypes"));
    attrs.add(new Attribute("field1", "value1"));
    attrs.add(new Attribute("field2", "value2"));
    item.setAttributes(attrs);
    item.setName("MONKEY-" + id + "-region");
    SelectResult result = new SelectResult();
    result.setItems(Arrays.asList(item));
    return result;
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) LinkedList(java.util.LinkedList)

Example 20 with SelectResult

use of com.amazonaws.services.simpledb.model.SelectResult in project SimianArmy by Netflix.

the class TestSimpleDBRecorder method testFindEvent.

@Test
public void testFindEvent() {
    SelectResult result1 = mkSelectResult("testId1");
    result1.setNextToken("nextToken");
    SelectResult result2 = mkSelectResult("testId2");
    ArgumentCaptor<SelectRequest> arg = ArgumentCaptor.forClass(SelectRequest.class);
    when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
    Map<String, String> query = new LinkedHashMap<String, String>();
    query.put("instanceId", "testId1");
    verifyEvents(findEvents(query, new Date(0)));
    verify(sdbMock, times(2)).select(arg.capture());
    SelectRequest req = arg.getValue();
    StringBuilder sb = new StringBuilder();
    sb.append("select * from `DOMAIN` where region = 'region'");
    sb.append(" and instanceId = 'testId1'");
    Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
    // reset for next test
    when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
    verifyEvents(findEvents(Type.MONKEY, query, new Date(0)));
    verify(sdbMock, times(4)).select(arg.capture());
    req = arg.getValue();
    sb.append(" and monkeyType = 'MONKEY|com.netflix.simianarmy.aws.TestSimpleDBRecorder$Type'");
    Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
    // reset for next test
    when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
    verifyEvents(findEvents(Type.MONKEY, EventTypes.EVENT, query, new Date(0)));
    verify(sdbMock, times(6)).select(arg.capture());
    req = arg.getValue();
    sb.append(" and eventType = 'EVENT|com.netflix.simianarmy.aws.TestSimpleDBRecorder$EventTypes'");
    Assert.assertEquals(req.getSelectExpression(), sb.toString() + " and eventTime > '0' order by eventTime desc");
    // reset for next test
    when(sdbMock.select(any(SelectRequest.class))).thenReturn(result1).thenReturn(result2);
    verifyEvents(findEvents(Type.MONKEY, EventTypes.EVENT, query, new Date(1330538400000L)));
    verify(sdbMock, times(8)).select(arg.capture());
    req = arg.getValue();
    sb.append(" and eventTime > '1330538400000' order by eventTime desc");
    Assert.assertEquals(req.getSelectExpression(), sb.toString());
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Aggregations

SelectResult (com.amazonaws.services.simpledb.model.SelectResult)22 SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)12 Item (com.amazonaws.services.simpledb.model.Item)11 AmazonClientException (com.amazonaws.AmazonClientException)7 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)5 ArrayList (java.util.ArrayList)5 Attribute (com.amazonaws.services.simpledb.model.Attribute)4 SienaException (siena.SienaException)4 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)3 LinkedList (java.util.LinkedList)3 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)2 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)2 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 NoSuchDomainException (com.amazonaws.services.simpledb.model.NoSuchDomainException)1 EventType (com.netflix.simianarmy.EventType)1 MonkeyType (com.netflix.simianarmy.MonkeyType)1