Search in sources :

Example 1 with AmazonSimpleDB

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

the class SdbEndpoint method createSdbClient.

AmazonSimpleDB createSdbClient() {
    AmazonSimpleDB client = null;
    ClientConfiguration clientConfiguration = null;
    boolean isClientConfigFound = false;
    if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
        clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost(configuration.getProxyHost());
        clientConfiguration.setProxyPort(configuration.getProxyPort());
        isClientConfigFound = true;
    }
    if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
        AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
        if (isClientConfigFound) {
            client = new AmazonSimpleDBClient(credentials, clientConfiguration);
        } else {
            client = new AmazonSimpleDBClient(credentials);
        }
    } else {
        if (isClientConfigFound) {
            client = new AmazonSimpleDBClient();
        } else {
            client = new AmazonSimpleDBClient(clientConfiguration);
        }
    }
    return client;
}
Also used : AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with AmazonSimpleDB

use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.

the class EntityManagerFactoryImpl method loadDomains.

private synchronized void loadDomains() {
    if (domainSet != null)
        return;
    try {
        domainSet = new HashSet<String>();
        logger.info("getting all domains");
        AmazonSimpleDB db = getSimpleDb();
        ListDomainsResult listDomainsResult = db.listDomains();
        domainSet.addAll(listDomainsResult.getDomainNames());
        while (listDomainsResult.getNextToken() != null) {
            ListDomainsRequest request = new ListDomainsRequest().withNextToken(listDomainsResult.getNextToken());
            listDomainsResult = db.listDomains(request);
            domainSet.addAll(listDomainsResult.getDomainNames());
        }
    } catch (AmazonClientException e) {
        throw new PersistenceException(e);
    }
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult) ListDomainsRequest(com.amazonaws.services.simpledb.model.ListDomainsRequest) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) AmazonClientException(com.amazonaws.AmazonClientException) PersistenceException(javax.persistence.PersistenceException)

Example 3 with AmazonSimpleDB

use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.

the class ConcurrentRetriever method test.

public static List<ItemAndAttributes> test(EntityManagerSimpleJPA em, String domainName) throws AmazonClientException, ExecutionException, InterruptedException {
    AmazonSimpleDB db = em.getSimpleDb();
    SelectResult result = DomainHelper.selectItems(db, "select * from `" + domainName + "`", null);
    List<SdbItem> list = new ArrayList<SdbItem>();
    for (Item item : result.getItems()) {
        list.add(new SdbItemImpl2(item));
    }
    return getAttributesFromSdb(list, em.getExecutor(), em);
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) SdbItem(com.spaceprogram.simplejpa.SdbItem) Item(com.amazonaws.services.simpledb.model.Item) SdbItem(com.spaceprogram.simplejpa.SdbItem) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) ArrayList(java.util.ArrayList) SdbItemImpl2(com.spaceprogram.simplejpa.SdbItemImpl2)

Example 4 with AmazonSimpleDB

use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.

the class BaseTestClass method deleteAll.

@After
public void deleteAll() throws AmazonClientException {
    printLog();
    // todo: should just delete all items in the domain, would probably be faster
    System.out.println("Deleting all objects created during test...");
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    AmazonSimpleDB db = em.getSimpleDb();
    deleteAll(em, db, MyTestObject.class);
    // db.deleteDomain(d);
    // d = db.getDomain(em.getDomainName(MyTestObject2.class));
    deleteAll(em, db, MyTestObject2.class);
    // db.deleteDomain(d);
    // d = db.getDomain(em.getDomainName(MyTestObject3.class));
    // db.deleteDomain(d);
    deleteAll(em, db, MyTestObject3.class);
    deleteAll(em, db, MyTestObject4.class);
    // d = db.getDomain(em.getDomainName(MyInheritanceObject1.class));
    // db.deleteDomain(d);
    deleteAll(em, db, MyInheritanceObject1.class);
    deleteAll(em, db, MyInheritanceObject2.class);
    deleteAll(em, db, MyInheritanceObject3.class);
    em.close();
}
Also used : AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) After(org.junit.After)

Example 5 with AmazonSimpleDB

use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.

the class DomainHelperTests method selectItemsWithWhereTests.

@Test
public void selectItemsWithWhereTests() {
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    AmazonSimpleDB sdbClient = em.getSimpleDb();
    String domainName = "simplejpa-domainhelper-tests";
    sdbClient.createDomain(new CreateDomainRequest().withDomainName(domainName));
    try {
        for (int i = 0; i < 10; i++) {
            sdbClient.putAttributes(new PutAttributesRequest().withItemName("thing" + i).withDomainName(domainName).withAttributes(new ReplaceableAttribute("name", "value", true)));
        }
        SelectResult result = DomainHelper.selectItems(sdbClient, domainName, "name = 'value' LIMIT 3", null);
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, domainName, "name = 'value' LIMIT 3", result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, domainName, "name = 'value' LIMIT 3", result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, domainName, "name = 'value' LIMIT 3", result.getNextToken());
        Assert.assertEquals(1, result.getItems().size());
        Assert.assertNull(result.getNextToken());
    } finally {
        sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
    }
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Test(org.junit.Test)

Aggregations

AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)17 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)8 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)8 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)5 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)5 Item (com.amazonaws.services.simpledb.model.Item)4 Test (org.junit.Test)4 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)3 ArrayList (java.util.ArrayList)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ClientConfiguration (com.amazonaws.ClientConfiguration)2 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 PersistenceException (javax.persistence.PersistenceException)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)1 GetAttributesRequest (com.amazonaws.services.simpledb.model.GetAttributesRequest)1 GetAttributesResult (com.amazonaws.services.simpledb.model.GetAttributesResult)1