Search in sources :

Example 11 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 12 with AmazonSimpleDB

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();
}
Also used : AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) ArrayList(java.util.ArrayList) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 13 with AmazonSimpleDB

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));
    }
}
Also used : 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 14 with AmazonSimpleDB

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));
        }
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) DeleteAttributesRequest(com.amazonaws.services.simpledb.model.DeleteAttributesRequest) GetAttributesRequest(com.amazonaws.services.simpledb.model.GetAttributesRequest) GetAttributesResult(com.amazonaws.services.simpledb.model.GetAttributesResult) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

Example 15 with AmazonSimpleDB

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));
    }
}
Also used : Item(com.amazonaws.services.simpledb.model.Item) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) PutAttributesRequest(com.amazonaws.services.simpledb.model.PutAttributesRequest) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute)

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