FileDocCategorySizeDatePackage
BulkOperationsTestBean.javaAPI DocJBoss 4.2.15002Fri Jul 13 20:53:06 BST 2007org.jboss.ejb3.test.clusteredentity

BulkOperationsTestBean

public class BulkOperationsTestBean extends Object implements BulkOperationsTest
author
Brian Stansberry
version
$Revision$

Fields Summary
private EntityManager
manager
Constructors Summary
Methods Summary
public voidcreateContacts()

      for (int i = 0; i < 10; i++)
         createCustomer(i);
   
private CustomercreateCustomer(int id)

      System.out.println("CREATE CUSTOMER " + id);
      try
      {
         Customer customer = new Customer();
         customer.setId(id);
         customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
         Set<Contact> contacts = new HashSet<Contact>();
         
         Contact kabir = new Contact();
         kabir.setId(1000 + id);
         kabir.setCustomer(customer);
         kabir.setName("Kabir");
         kabir.setTlf("1111");
         contacts.add(kabir);
         
         Contact bill = new Contact();
         bill.setId(2000 +id);
         bill.setCustomer(customer);
         bill.setName("Bill");
         bill.setTlf("2222");
         contacts.add(bill);

         customer.setContacts(contacts);

         manager.persist(customer);
         return customer;
      }
      catch (RuntimeException e)
      {
         throw e;
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
      finally
      {
         System.out.println("CREATE CUSTOMER " +  id + " -  END");         
      }
   
public intdeleteContacts()

      String deleteHQL = "delete Contact where customer in ";
      deleteHQL += " (select customer FROM Customer as customer ";
      deleteHQL += " where customer.name = :cName)";

      int rowsAffected = manager.createQuery(deleteHQL)
                                .setFlushMode(FlushModeType.AUTO)
                                .setParameter("cName", "Red Hat")
                                .executeUpdate();
      return rowsAffected;
   
public ContactgetContact(java.lang.Integer id)

      return manager.find(Contact.class, id);
   
public java.util.ListgetContactsByCustomer(java.lang.String customerName)

      String selectHQL = "select contact.id from Contact contact";
      selectHQL += " where contact.customer.name = :cName";
   
      List results = manager.createQuery(selectHQL)
                            .setFlushMode(FlushModeType.AUTO)
                            .setParameter("cName", customerName)
                            .getResultList();
      
      return results;      
   
public java.util.ListgetContactsByTLF(java.lang.String tlf)

      String selectHQL = "select contact.id from Contact contact";
      selectHQL += " where contact.tlf = :cTLF";
   
      List results = manager.createQuery(selectHQL)
                            .setFlushMode(FlushModeType.AUTO)
                            .setParameter("cTLF", tlf)
                            .getResultList();
      
      return results;      
   
public voidremove()

      
   
public intupdateContacts(java.lang.String name, java.lang.String newTLF)

      String updateHQL = "update Contact set tlf = :cNewTLF where name = :cName";

      int rowsAffected = manager.createQuery(updateHQL)
                                .setFlushMode(FlushModeType.AUTO)
                                .setParameter("cNewTLF", newTLF)
                                .setParameter("cName", name)
                                .executeUpdate();
      return rowsAffected;