Search in sources :

Example 16 with ReplaceableAttribute

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

the class SdbMappingUtils method createItem.

public static ReplaceableItem createItem(Object obj) {
    Class<?> clazz = obj.getClass();
    ReplaceableItem item = new ReplaceableItem(getItemName(clazz, obj));
    for (Field field : ClassInfo.getClassInfo(clazz).updateFields) {
        try {
            String value = objectFieldToString(obj, field);
            if (value != null) {
                ReplaceableAttribute attr = new ReplaceableAttribute(getAttributeName(field), value, true);
                item.withAttributes(attr);
            } else {
                if (ClassInfo.isEmbeddedNative(field)) {
                    SdbNativeSerializer.embed(item, ClassInfo.getSingleColumnName(field), value);
                }
            }
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
    return item;
}
Also used : Field(java.lang.reflect.Field) SienaException(siena.SienaException) ReplaceableItem(com.amazonaws.services.simpledb.model.ReplaceableItem) SienaException(siena.SienaException) SienaRestrictedApiException(siena.SienaRestrictedApiException) IOException(java.io.IOException) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 17 with ReplaceableAttribute

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

the class SdbMappingUtils method createPutRequest.

public static PutAttributesRequest createPutRequest(String domain, Class<?> clazz, ClassInfo info, Object obj) {
    PutAttributesRequest req = new PutAttributesRequest().withDomainName(domain);
    req.withItemName(getItemName(clazz, obj));
    for (Field field : ClassInfo.getClassInfo(clazz).updateFields) {
        try {
            String value = objectFieldToString(obj, field);
            if (value != null) {
                ReplaceableAttribute attr = new ReplaceableAttribute(getAttributeName(field), value, true);
                req.withAttributes(attr);
            } else {
                if (ClassInfo.isEmbeddedNative(field)) {
                    SdbNativeSerializer.embed(req, ClassInfo.getSingleColumnName(field), value);
                }
            }
        } catch (Exception e) {
            throw new SienaException(e);
        }
    }
    return req;
}
Also used : Field(java.lang.reflect.Field) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) SienaException(siena.SienaException) SienaException(siena.SienaException) SienaRestrictedApiException(siena.SienaRestrictedApiException) IOException(java.io.IOException) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 18 with ReplaceableAttribute

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

the class PutAttributesCommandTest method executeWithoutItemName.

@Test(expected = IllegalArgumentException.class)
public void executeWithoutItemName() {
    List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
    replaceableAttributes.add(new ReplaceableAttribute("NAME1", "VALUE1", true));
    exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes);
    UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
    exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition);
    command.execute();
}
Also used : UpdateCondition(com.amazonaws.services.simpledb.model.UpdateCondition) ArrayList(java.util.ArrayList) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 19 with ReplaceableAttribute

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

the class PutAttributesCommandTest method execute.

@Test
public void execute() {
    List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
    replaceableAttributes.add(new ReplaceableAttribute("NAME1", "VALUE1", true));
    exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes);
    exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1");
    UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true);
    exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition);
    command.execute();
    assertEquals("DOMAIN1", sdbClient.putAttributesRequest.getDomainName());
    assertEquals("ITEM1", sdbClient.putAttributesRequest.getItemName());
    assertEquals(updateCondition, sdbClient.putAttributesRequest.getExpected());
    assertEquals(replaceableAttributes, sdbClient.putAttributesRequest.getAttributes());
}
Also used : UpdateCondition(com.amazonaws.services.simpledb.model.UpdateCondition) ArrayList(java.util.ArrayList) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Example 20 with ReplaceableAttribute

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

the class PutAttributesCommandTest method determineReplaceableAttributes.

@Test
public void determineReplaceableAttributes() {
    assertNull(this.command.determineReplaceableAttributes());
    List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();
    replaceableAttributes.add(new ReplaceableAttribute("NAME1", "VALUE1", true));
    exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes);
    assertEquals(replaceableAttributes, this.command.determineReplaceableAttributes());
}
Also used : ArrayList(java.util.ArrayList) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Aggregations

ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)25 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)14 Test (org.junit.Test)12 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)8 UpdateCondition (com.amazonaws.services.simpledb.model.UpdateCondition)8 ArrayList (java.util.ArrayList)7 Exchange (org.apache.camel.Exchange)5 Processor (org.apache.camel.Processor)5 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)4 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 SienaException (siena.SienaException)4 Item (com.amazonaws.services.simpledb.model.Item)3 Collection (java.util.Collection)3 Attribute (com.amazonaws.services.simpledb.model.Attribute)2 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)2 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2