Package org.hibernate.test.cache.infinispan.functional

Examples of org.hibernate.test.cache.infinispan.functional.Customer


      tm.begin();

      try {
         Session session = sessionFactory.getCurrentSession();
         Customer customer = new Customer();
         customer.setName("JBoss");
         Set<Contact> contacts = new HashSet<Contact>();

         Contact kabir = new Contact();
         kabir.setCustomer(customer);
         kabir.setName("Kabir");
         kabir.setTlf("1111");
         contacts.add(kabir);

         Contact bill = new Contact();
         bill.setCustomer(customer);
         bill.setName("Bill");
         bill.setTlf("2222");
         contacts.add(bill);

         customer.setContacts(contacts);

         session.save(customer);
         tm.commit();

         IdContainer ids = new IdContainer();
         ids.customerId = customer.getId();
         Set contactIds = new HashSet();
         contactIds.add(kabir.getId());
         contactIds.add(bill.getId());
         ids.contactIds = contactIds;
View Full Code Here


   private Customer getCustomer(Integer id, SessionFactory sessionFactory, TransactionManager tm) throws Exception {
      log.debug("Find customer with id=" + id);
      tm.begin();
      try {
         Session session = sessionFactory.getCurrentSession();
         Customer customer = doGetCustomer(id, session, tm);
         tm.commit();
         return customer;
      } catch (Exception e) {
         try {
            tm.rollback();
View Full Code Here

         log.debug("Find customer ended.");
      }
   }
  
   private Customer doGetCustomer(Integer id, Session session, TransactionManager tm) throws Exception {
      Customer customer = (Customer) session.get(Customer.class, id);
      // Access all the contacts
      for (Iterator it = customer.getContacts().iterator(); it.hasNext();) {
         ((Contact) it.next()).getName();
      }
      return customer;
   }
View Full Code Here

      tm.begin();
      try {
         Session session = sessionFactory.getCurrentSession();
         IdContainer ids = new IdContainer();
         Set contactIds = new HashSet();
         Customer customer = doGetCustomer(id, session, tm);
         customer.setName("NewJBoss");
         ids.customerId = customer.getId();
         Set<Contact> contacts = customer.getContacts();
         for (Contact c : contacts) {
            contactIds.add(c.getId());
         }
         Contact contact = contacts.iterator().next();
         contacts.remove(contact);
View Full Code Here

   private void cleanup(SessionFactory sessionFactory, TransactionManager tm) throws Exception {
      tm.begin();
      try {
         Session session = sessionFactory.getCurrentSession();
         Customer c = (Customer) session.get(Customer.class, CUSTOMER_ID);
         if (c != null) {
            Set contacts = c.getContacts();
            for (Iterator it = contacts.iterator(); it.hasNext();)
               session.delete(it.next());
            c.setContacts(null);
            session.delete(c);
         }

         tm.commit();
      } catch (Exception e) {
View Full Code Here

   }

   private Customer createCustomer(int id) throws Exception {
      System.out.println("CREATE CUSTOMER " + id);
      try {
         Customer customer = new Customer();
         customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
         Set<Contact> contacts = new HashSet<Contact>();

         Contact kabir = new Contact();
         kabir.setCustomer(customer);
         kabir.setName("Kabir");
         kabir.setTlf("1111");
         contacts.add(kabir);

         Contact bill = new Contact();
         bill.setCustomer(customer);
         bill.setName("Bill");
         bill.setTlf("2222");
         contacts.add(bill);

         customer.setContacts(contacts);

         Session s = openSession();
         s.getTransaction().begin();
         s.persist(customer);
         s.getTransaction().commit();
View Full Code Here

  }

  private Customer createCustomer(int id) throws Exception {
    System.out.println( "CREATE CUSTOMER " + id );
    try {
      Customer customer = new Customer();
      customer.setName( (id % 2 == 0) ? "JBoss" : "Red Hat" );
      Set<Contact> contacts = new HashSet<Contact>();

      Contact kabir = new Contact();
      kabir.setCustomer( customer );
      kabir.setName( "Kabir" );
      kabir.setTlf( "1111" );
      contacts.add( kabir );

      Contact bill = new Contact();
      bill.setCustomer( customer );
      bill.setName( "Bill" );
      bill.setTlf( "2222" );
      contacts.add( bill );

      customer.setContacts( contacts );

      Session s = openSession();
      s.getTransaction().begin();
      s.persist( customer );
      s.getTransaction().commit();
View Full Code Here

    tm.begin();

    try {
      Session session = sessionFactory.getCurrentSession();
      Customer customer = new Customer();
      customer.setName( "JBoss" );
      Set<Contact> contacts = new HashSet<Contact>();

      Contact kabir = new Contact();
      kabir.setCustomer( customer );
      kabir.setName( "Kabir" );
      kabir.setTlf( "1111" );
      contacts.add( kabir );

      Contact bill = new Contact();
      bill.setCustomer( customer );
      bill.setName( "Bill" );
      bill.setTlf( "2222" );
      contacts.add( bill );

      customer.setContacts( contacts );

      session.save( customer );
      tm.commit();

      IdContainer ids = new IdContainer();
      ids.customerId = customer.getId();
      Set contactIds = new HashSet();
      contactIds.add( kabir.getId() );
      contactIds.add( bill.getId() );
      ids.contactIds = contactIds;
View Full Code Here

  private Customer getCustomer(Integer id, SessionFactory sessionFactory, TransactionManager tm) throws Exception {
    log.debug( "Find customer with id=" + id );
    tm.begin();
    try {
      Session session = sessionFactory.getCurrentSession();
      Customer customer = doGetCustomer( id, session, tm );
      tm.commit();
      return customer;
    }
    catch (Exception e) {
      try {
View Full Code Here

      log.debug( "Find customer ended." );
    }
  }

  private Customer doGetCustomer(Integer id, Session session, TransactionManager tm) throws Exception {
    Customer customer = (Customer) session.get( Customer.class, id );
    // Access all the contacts
    for ( Iterator it = customer.getContacts().iterator(); it.hasNext(); ) {
      ((Contact) it.next()).getName();
    }
    return customer;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.test.cache.infinispan.functional.Customer

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.