@Move public void move(Musician musician, MusiciansController newParent, String newName) { Transaction tx = SessionManager.session().beginTransaction(); musician.setName(newName); if (musician.getContactUid() == null) { musician.setContactUid(UUID.randomUUID().toString()); } SessionManager.session().save(musician); SessionManager.session().flush(); tx.commit(); }
@Delete public void deleteMusician(Musician musician) { Transaction tx = SessionManager.session().beginTransaction(); if (musician.getBandMembers() != null) { for (BandMember bm : musician.getBandMembers()) { SessionManager.session().delete(bm); } } SessionManager.session().delete(musician); SessionManager.session().flush(); tx.commit(); }
@MakeCollection public Musician createAndSaveMusician(MusiciansController root, String newName) { Transaction tx = SessionManager.session().beginTransaction(); Musician m = new Musician(); m.setCreatedDate(new Date()); m.setModifiedDate(new Date()); m.setName(newName); SessionManager.session().save(m); SessionManager.session().flush(); tx.commit(); return m; }
@Post(bindData = true) public Musician saveMusician(Musician musician) { log.info("saveMusician: " + musician.getName()); Transaction tx = SessionManager.session().beginTransaction(); if (musician.getContactUid() == null) { musician.setContactUid(UUID.randomUUID().toString()); } musician.setModifiedDate(new Date()); SessionManager.session().save(musician); SessionManager.session().flush(); tx.commit(); log.info("saved musician"); return musician; }
@ChildrenOf @Users // ties in with the @AccessControlList and @Authenticate methods below public List<Musician> getMusicians(MusiciansController root) { List<Musician> list = Musician.findAll(SessionManager.session()); System.out.println("musicians=" + list.size()); return list; }
@ChildOf @Users public Musician findMusicianByName(MusiciansController root, String name) { return Musician.find(name, SessionManager.session()); }