package org.springframework.data.simpledb.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.simpledb.repository.support.entityinformation.SimpleDbEntityInformation;

import java.io.Serializable;
import java.util.List;

/**
 *
 */

public class SimpleDbOperationsImpl<T, ID extends Serializable> implements SimpleDbOperations {


    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleDbOperationsImpl.class);
    private final String accessID;
    private final String secretKey;
    private final DDL ddl;

    public enum DDL{
        drop_create,
        update,
        nothing
    }

    public SimpleDbOperationsImpl(String accessID, String secretKey) {
        this(accessID, secretKey, DDL.nothing.name());
    }

    public SimpleDbOperationsImpl(String accessID, String secretKey, String ddl) {
        this.accessID = accessID;
        this.secretKey = secretKey;
        this.ddl = DDL.valueOf(ddl);
    }

    public String getAccessID() {
        return accessID;
    }

    public String getSecretKey() {
        return secretKey;
    }

    @Override
    public void delete(SimpleDbEntity sdbEntity) {
        logOperation("Delete", sdbEntity);
    }

    @Override
    public Object addItem(SimpleDbEntity entity) {
        logOperation("Add  ", entity);
        return entity.getItem();
    }

    @Override
    public Object updateItem(SimpleDbEntity entity) {
        logOperation("Update", entity);
        return entity.getItem();
    }

    @Override
    public Object findOne(SimpleDbEntityInformation entityInformation, Serializable id) {
        LOGGER.info("FindOne ItemName \"{}\"\"", id);
        return null;
    }

    @Override
    public boolean exists(SimpleDbEntityInformation entityInformation, Serializable id) {
        LOGGER.info("Exists ItemName \"{}\"\"", id);
        return false;
    }

    @Override
    public List findAll(SimpleDbEntityInformation entityInformation, Iterable ids) {
        LOGGER.info("Find All Domain \"{}\"\"", entityInformation.getDomain());
        return null;
    }

    private void logOperation(String operation, SimpleDbEntity<T, ID> entity) {
        LOGGER.info(operation + " \"{}\" ItemName \"{}\"\"", entity.getDomain(), entity.getItemName());
    }

}

@@ -42,16 +42,132 @@
 .core;%0A%0A
+import com.amazonaws.services.simpledb.AmazonSimpleDB;%0Aimport com.amazonaws.services.simpledb.AmazonSimpleDBClient;%0A
 import o
@@ -183,16 +183,16 @@
 Logger;%0A
-
 import o
@@ -372,16 +372,56 @@
 il.List;
+%0Aimport org.springframework.util.Assert;
 %0A%0A/**%0A *
@@ -717,16 +717,54 @@
 DDL ddl;
+%0A    private final AmazonSimpleDB sdb;
 %0A%0A    pu
@@ -1050,24 +1050,139 @@
 ring ddl) %7B%0A
+        Assert.notNull(accessID);%0A        Assert.notNull(secretKey);%0A        sdb = new AmazonSimpleDBClient(null);%0A
         this
@@ -1235,24 +1235,24 @@
  secretKey;%0A
-
         this
@@ -1272,24 +1272,25 @@
 lueOf(ddl);%0A
+%0A
     %7D%0A%0A    p

add amazon simpleDB client