Methods Summary |
---|
public void | createContacts()
for (int i = 0; i < 10; i++)
createCustomer(i);
|
private Customer | createCustomer(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 int | deleteContacts()
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 Contact | getContact(java.lang.Integer id)
return manager.find(Contact.class, id);
|
public java.util.List | getContactsByCustomer(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.List | getContactsByTLF(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 void | remove()
|
public int | updateContacts(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;
|