* Initialize the Database with new entities.
*/
public void init() {
// Do nothing if already defined
Employee test = findEmployeeWithItsGivenName("Florent");
if (test != null) {
return;
}
// The first employee
Employee florent = new Employee();
florent.setName("Florent");
florent.addNickName("flo");
florent.addNickName("FB");
florent.getLevelRights().add(EmployeeLevelType.ADMIN);
florent.getLevelRights().add(EmployeeLevelType.SUPER_ADMIN);
// Create addresses
Address florentWorkAddress = new Address();
florentWorkAddress.setTitle("work");
florentWorkAddress.setCity("Grenoble");
this.entityManager.persist(florentWorkAddress);
Address florentHomeAddress = new Address();
florentHomeAddress.setTitle("home");
florentHomeAddress.setCity("Grenoble");
this.entityManager.persist(florentHomeAddress);
florent.getAddresses().add(florentHomeAddress);
florent.getAddresses().add(florentWorkAddress);
Date now = new Date();
Calendar calendar = new GregorianCalendar();
calendar.set(2010, 11, 25);
Date christmas = calendar.getTime();
florent.getHistoryEvents().put(now, "Date of init");
florent.getHistoryEvents().put(christmas, "XMas Day");
this.entityManager.persist(florent);
// Another employee
Employee bean = new Employee();
bean.setName("EasyBeans");
bean.addNickName("The easy bean");
bean.addNickName("OW2 EasyBeans");
bean.getLevelRights().add(EmployeeLevelType.TRAINEE);
// Create addresses
Address beanFirstAddress = new Address();
beanFirstAddress.setTitle("work");
beanFirstAddress.setCity("Grenoble");
Address beanSecondAddress = new Address();
beanSecondAddress.setTitle("cofee");
beanSecondAddress.setCity("Java");
bean.getAddresses().add(beanFirstAddress);
bean.getAddresses().add(beanSecondAddress);
Calendar calendarRelease = new GregorianCalendar();
calendarRelease.set(2010, 01, 01);
Date release = calendarRelease.getTime();
bean.getHistoryEvents().put(release, "Date of the release");
this.entityManager.persist(bean);
}