Search in sources :

Example 1 with CreateDomainRequest

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

the class SdbEndpoint method doStart.

@Override
public void doStart() throws Exception {
    super.doStart();
    sdbClient = configuration.getAmazonSDBClient() != null ? configuration.getAmazonSDBClient() : createSdbClient();
    if (ObjectHelper.isNotEmpty(configuration.getAmazonSdbEndpoint())) {
        sdbClient.setEndpoint(configuration.getAmazonSdbEndpoint());
    }
    String domainName = getConfiguration().getDomainName();
    LOG.trace("Querying whether domain [{}] already exists...", domainName);
    try {
        sdbClient.domainMetadata(new DomainMetadataRequest(domainName));
        LOG.trace("Domain [{}] already exists", domainName);
        return;
    } catch (NoSuchDomainException ase) {
        LOG.trace("Domain [{}] doesn't exist yet", domainName);
        LOG.trace("Creating domain [{}]...", domainName);
        sdbClient.createDomain(new CreateDomainRequest(domainName));
        LOG.trace("Domain [{}] created", domainName);
    }
}
Also used : DomainMetadataRequest(com.amazonaws.services.simpledb.model.DomainMetadataRequest) CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException)

Example 2 with CreateDomainRequest

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

the class SdbPersistenceManager method checkDomain.

public void checkDomain(String domainName) {
    if (domains == null) {
        domains = sdb.listDomains().getDomainNames();
    }
    if (!domains.contains(domainName)) {
        sdb.createDomain(new CreateDomainRequest(domainName));
        domains.add(domainName);
    }
}
Also used : CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest)

Example 3 with CreateDomainRequest

use of com.amazonaws.services.simpledb.model.CreateDomainRequest 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 4 with CreateDomainRequest

use of com.amazonaws.services.simpledb.model.CreateDomainRequest 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 5 with CreateDomainRequest

use of com.amazonaws.services.simpledb.model.CreateDomainRequest 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

CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)8 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)5 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)4 PutAttributesRequest (com.amazonaws.services.simpledb.model.PutAttributesRequest)4 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)4 Test (org.junit.Test)4 AmazonClientException (com.amazonaws.AmazonClientException)2 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)2 DomainMetadataRequest (com.amazonaws.services.simpledb.model.DomainMetadataRequest)1 Item (com.amazonaws.services.simpledb.model.Item)1 ListDomainsResult (com.amazonaws.services.simpledb.model.ListDomainsResult)1 NoSuchDomainException (com.amazonaws.services.simpledb.model.NoSuchDomainException)1 PersistenceException (javax.persistence.PersistenceException)1