Search in sources :

Example 6 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 7 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 8 with AmazonSimpleDB

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

the class DomainHelperTests method selectItemsTests.

@Test
public void selectItemsTests() {
    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, String.format("select * from `%s` LIMIT 3", domainName), null);
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), result.getNextToken());
        Assert.assertEquals(3, result.getItems().size());
        Assert.assertNotNull(result.getNextToken());
        result = DomainHelper.selectItems(sdbClient, String.format("select * from `%s` LIMIT 3", domainName), 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)

Example 9 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)

Example 10 with AmazonSimpleDB

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

the class DomainHelperTests method listAllItemsTests.

@Test
public void listAllItemsTests() {
    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 < 3; i++) {
            sdbClient.putAttributes(new PutAttributesRequest().withItemName("thing" + i).withDomainName(domainName).withAttributes(new ReplaceableAttribute("name", "value", true)));
        }
        List<Item> items = DomainHelper.listAllItems(sdbClient, domainName);
        Assert.assertEquals(3, items.size());
    } finally {
        sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) 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