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();
}
use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.
the class UtilTests method renameSubclass.
@Ignore("Rename Subclass feature is currently broken")
@Test
public void renameSubclass() throws IOException, ExecutionException, InterruptedException, AmazonClientException {
EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
AmazonSimpleDB db = em.getSimpleDb();
String domainName = em.getFactory().getDomainName(MyInheritanceObject1.class);
em.getFactory().createIfNotExistDomain(domainName);
String id = "abc123";
List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
atts.add(new ReplaceableAttribute("id", id, true));
atts.add(new ReplaceableAttribute(EntityManagerFactoryImpl.DTYPE, "MyInheritanceObjectOld", true));
atts.add(new ReplaceableAttribute("fieldInSubClass2", "Bullwinkle", true));
db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(id).withAttributes(atts));
MyInheritanceObject1 object;
/*object = em.find(MyInheritanceObject2.class, id);
Assert.assertNull(object);
object = em.find(MyInheritanceObject1.class, id);
Assert.assertNotNull(object);
Assert.assertEquals(id, object.getId());*/
em.renameSubclass("MyInheritanceObjectOld", MyInheritanceObject2.class);
em.close();
// now find it again and the name should be good
em = (EntityManagerSimpleJPA) factory.createEntityManager();
MyInheritanceObject2 object2 = em.find(MyInheritanceObject2.class, id);
Assert.assertNotNull(object2);
Assert.assertEquals("Bullwinkle", object2.getFieldInSubClass2());
Assert.assertEquals(id, object2.getId());
// now delete object
em.remove(object2);
// and make sure it's gone
object = em.find(MyInheritanceObject1.class, object2.getId());
Assert.assertNull(object);
em.close();
}
use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.
the class DomainHelperTests method findByIdTest.
@Test
public void findByIdTest() {
EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
AmazonSimpleDB sdbClient = em.getSimpleDb();
String domainName = "simplejpa-domainhelper-tests";
sdbClient.createDomain(new CreateDomainRequest().withDomainName(domainName));
try {
Assert.assertNull(DomainHelper.findItemById(sdbClient, domainName, "noexist"));
sdbClient.putAttributes(new PutAttributesRequest().withItemName("exist").withDomainName(domainName).withAttributes(new ReplaceableAttribute("name", "value", true)));
Assert.assertNotNull(DomainHelper.findItemById(sdbClient, domainName, "exist"));
} finally {
sdbClient.deleteDomain(new DeleteDomainRequest().withDomainName(domainName));
}
}
use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.
the class EntityManagerSimpleJPA method putAndDelete.
private void putAndDelete(String domainName, String oldAttributeName, String newAttributeName, List<Item> items) throws AmazonClientException {
AmazonSimpleDB db = factory.getSimpleDb();
for (Item item : items) {
GetAttributesResult getOldResults = db.getAttributes(new GetAttributesRequest().withDomainName(domainName).withConsistentRead(true).withItemName(item.getName()).withAttributeNames(oldAttributeName));
List<Attribute> oldAtts = getOldResults.getAttributes();
if (oldAtts.size() > 0) {
Attribute oldAtt = oldAtts.get(0);
List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
atts.add(new ReplaceableAttribute(newAttributeName, oldAtt.getValue(), true));
db.putAttributes(new PutAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(atts));
db.deleteAttributes(new DeleteAttributesRequest().withDomainName(domainName).withItemName(item.getName()).withAttributes(oldAtts));
}
}
}
use of com.amazonaws.services.simpledb.AmazonSimpleDB in project simplejpa by appoxy.
the class EntityManagerSimpleJPA method putNewValue.
private void putNewValue(String domainName, List<Item> items, String dtype, String newClassName) throws AmazonClientException {
AmazonSimpleDB db = factory.getSimpleDb();
for (Item item : items) {
List<ReplaceableAttribute> atts = new ArrayList<ReplaceableAttribute>();
atts.add(new ReplaceableAttribute(dtype, newClassName, true));
db.putAttributes(new PutAttributesRequest(domainName, item.getName(), atts));
}
}
Aggregations