Search in sources :

Example 16 with Attribute

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

the class SdbComponentSpringTest method deleteAttributes.

@Test
public void deleteAttributes() {
    final List<Attribute> attributes = Arrays.asList(new Attribute[] { new Attribute("NAME1", "VALUE1") });
    final UpdateCondition condition = new UpdateCondition("Key1", "Value1", true);
    template.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.DeleteAttributes);
            exchange.getIn().setHeader(SdbConstants.ATTRIBUTES, attributes);
            exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1");
            exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, condition);
        }
    });
    assertEquals("TestDomain", amazonSDBClient.deleteAttributesRequest.getDomainName());
    assertEquals("ITEM1", amazonSDBClient.deleteAttributesRequest.getItemName());
    assertEquals(condition, amazonSDBClient.deleteAttributesRequest.getExpected());
    assertEquals(attributes, amazonSDBClient.deleteAttributesRequest.getAttributes());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) UpdateCondition(com.amazonaws.services.simpledb.model.UpdateCondition) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 17 with Attribute

use of com.amazonaws.services.simpledb.model.Attribute in project wildfly-camel by wildfly-extras.

the class SDBIntegrationTest method putAndGetAttributes.

@Test
@SuppressWarnings("unchecked")
public void putAndGetAttributes() throws Exception {
    AmazonSimpleDBClient sdbClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sdbClient);
    assertNoStaleDomain(sdbClient, "before");
    try {
        try {
            SDBUtils.createDomain(sdbClient, domainName);
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("sdbClient", sdbClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sdb://" + domainName + "?amazonSDBClient=#sdbClient");
                }
            });
            camelctx.start();
            try {
                ReplaceableAttribute attr = new ReplaceableAttribute("SomeName", "SomeValue", true);
                ProducerTemplate producer = camelctx.createProducerTemplate();
                Exchange exchange = producer.send("direct:start", new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
                        exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, Collections.singletonList(attr));
                    }
                });
                Assert.assertNull(exchange.getException());
                int retries = 10;
                List<Attribute> result = Collections.emptyList();
                while (result.isEmpty() && 0 < retries--) {
                    exchange = producer.send("direct:start", new Processor() {

                        public void process(Exchange exchange) throws Exception {
                            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.GetAttributes);
                            exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        }
                    });
                    Assert.assertNull(exchange.getException());
                    result = exchange.getIn().getHeader(SdbConstants.ATTRIBUTES, List.class);
                    System.out.println(retries + ": " + result);
                    Thread.sleep(500);
                }
                Assert.assertEquals(1, result.size());
                Assert.assertEquals(attr.getName(), result.get(0).getName());
                Assert.assertEquals(attr.getValue(), result.get(0).getValue());
            } finally {
                camelctx.stop();
            }
        } finally {
            sdbClient.deleteDomain(new DeleteDomainRequest(domainName));
        }
    } finally {
        assertNoStaleDomain(sdbClient, "after");
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Exchange(org.apache.camel.Exchange) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) List(java.util.List) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 18 with Attribute

use of com.amazonaws.services.simpledb.model.Attribute in project teiid by teiid.

the class TestSimpleDBExecution method mockResult.

private List<Item> mockResult() {
    List<Attribute> attributes = new ArrayList<Attribute>();
    attributes.add(new Attribute("a1", "a1"));
    attributes.add(new Attribute("a2", "a2"));
    attributes.add(new Attribute("a2", "a22"));
    List<Item> items = new ArrayList<Item>();
    items.add(new Item("one", attributes));
    return items;
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) Attribute(com.amazonaws.services.simpledb.model.Attribute) ArrayList(java.util.ArrayList)

Example 19 with Attribute

use of com.amazonaws.services.simpledb.model.Attribute in project teiid by teiid.

the class SimpleDbAPIClassTest method getAttributeNamesTest.

@Test
public void getAttributeNamesTest() throws Exception {
    DomainMetadataResult metadataResult = mock(DomainMetadataResult.class);
    SelectResult result = mock(SelectResult.class);
    ArrayList<Item> items = new ArrayList<Item>();
    items.add(new Item("1", Arrays.asList(new Attribute("c", "d"), new Attribute("a", "b"))));
    stub(result.getItems()).toReturn(items);
    when(metadataResult.getAttributeNameCount()).thenReturn(2);
    when(client.select(any(SelectRequest.class))).thenReturn(result);
    when(client.domainMetadata(any(DomainMetadataRequest.class))).thenReturn(metadataResult);
    assertEquals("c", simpleDbApi.getAttributeNames("x").iterator().next().getName());
}
Also used : DomainMetadataRequest(com.amazonaws.services.simpledb.model.DomainMetadataRequest) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Item(com.amazonaws.services.simpledb.model.Item) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) DomainMetadataResult(com.amazonaws.services.simpledb.model.DomainMetadataResult) ArrayList(java.util.ArrayList) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest) Test(org.junit.Test)

Example 20 with Attribute

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

the class SdbMappingUtils method fillModel.

public static void fillModel(String itemName, List<Attribute> attrs, Class<?> clazz, Object obj) {
    fillModelKeysOnly(itemName, clazz, obj);
    Attribute theAttr;
    for (Field field : ClassInfo.getClassInfo(clazz).updateFields) {
        if (!ClassInfo.isEmbeddedNative(field)) {
            theAttr = null;
            String attrName = getAttributeName(field);
            // searches attribute and if found, removes it from the list to reduce number of attributes
            for (Attribute attr : attrs) {
                if (attrName.equals(attr.getName())) {
                    theAttr = attr;
                    attrs.remove(attr);
                    break;
                }
            }
            if (theAttr != null) {
                setFromString(obj, field, theAttr.getValue());
            }
        } else {
            Object value = SdbNativeSerializer.unembed(field.getType(), ClassInfo.getSingleColumnName(field), attrs);
            Util.setField(obj, field, value);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Aggregations

Attribute (com.amazonaws.services.simpledb.model.Attribute)27 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)18 Test (org.junit.Test)12 Item (com.amazonaws.services.simpledb.model.Item)8 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)8 ArrayList (java.util.ArrayList)8 Exchange (org.apache.camel.Exchange)8 Processor (org.apache.camel.Processor)8 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)5 LinkedList (java.util.LinkedList)3 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)2 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)2 SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)2 Field (java.lang.reflect.Field)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)1