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);
}
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);
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations