/** * Saves any changed items in the session by recalculating hashes and persisting new items to the * repository, and returns a list of root tree items which represent changed trees. That list will * contain the root of the tree which this session directly represents, but it will also contain * the roots of trees which have been affected through linked item updates * * @return */ public String save(Profile currentUser) throws IOException { recalcHashes(rootDataNode); String newHash = rootDataNode.hash; Commit newCommit = new Commit(); newCommit.setCreatedDate(currentDateService.getNow()); newCommit.setEditor(currentUser); newCommit.setItemHash(newHash); session.save(newCommit); System.out.println("commit hash: " + newHash + " id " + newCommit.getId()); branch.setHead(newCommit); session.save(branch); return rootDataNode.hash; }
/** * Creates and saves a new branch, including setting up initial commit etc * * @param name * @param user * @param session * @return */ public Branch createBranch(String name, Profile user, Session session) { Commit head = new Commit(); head.setCreatedDate(new Date()); head.setEditor(user); head.setItemHash(null); session.save(head); Branch b = new Branch(); b.setName(Branch.TRUNK); b.setRepository(this); b.setHead(head); session.save(b); if (getBranches() == null) { setBranches(new ArrayList<Branch>()); } getBranches().add(b); return b; }