Package org.objectweb.speedo.pobjects.basic

Examples of org.objectweb.speedo.pobjects.basic.Product


  //  test delete and make an object persistent in the same transaction
    public void testDeleteMakePersistent() {
    long pIdentifier = 1;
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      Product p = new Product(pIdentifier);
      p.setCost("cost1");
      p.setProductName("product1");
      //make a product persistent
      pm.currentTransaction().begin();
      pm.makePersistent(p);
      Object pId = pm.getObjectId(p);
      Assert.assertNotNull("null object identifier", pId);
      pm.currentTransaction().commit();

      p = null;
      p = (Product) pm.getObjectById(pId, true);
      Assert.assertNotNull("null instance returned by getObjectById", p);
      Assert.assertEquals("Bad product id", pIdentifier, p.getId());
      //delete it
      //and recreate a new one with the same id
      pm.currentTransaction().begin();
      pm.deletePersistent(p);
      Product newP = new Product(pIdentifier);
      newP.setCost("cost2");
      newP.setProductName("product2");
      pm.makePersistent(newP);
      pm.currentTransaction().commit();
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here


        logger.log(BasicLevel.DEBUG, "testUserCacheSingle");
        PersistenceManager pm = pmf.getPersistenceManager();
        pm.currentTransaction().begin();
        final String n = "testUserCacheSingle_";
        for(int i=0; i<10; i++) {
            Product p = new Product(i);
            p.setProductName(n + i);
            pm.makePersistent(p);
        }
        pm.currentTransaction().commit();
        try {
            pm.currentTransaction().begin();
            Query query = pm.newQuery(Product.class);
            query.setFilter("productName == p");
            query.declareParameters("String p");
            query.setUnique(true);
            final String id = n + 3;
            Product p = (Product) query.execute(id); //no query
            assertNotNull("Null value for " + id, p);
            p.setProductName(id + "bis");

            //Check that the old value is unbound
            p = (Product) query.execute(id); //query
            assertNull("Old value not unbound from the user cache, " + id, p);
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.basic.Product

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.