public void simpleAddContentSourcesToRepo(Subject subject, int repoId, int[] contentSourceIds) throws Exception { Repo repo = entityManager.find(Repo.class, repoId); if (repo == null) { throw new Exception("There is no repo with an ID [" + repoId + "]"); } for (int id : contentSourceIds) { ContentSource cs = entityManager.find(ContentSource.class, id); if (cs == null) { throw new Exception("There is no content source with id [" + id + "]"); } RepoContentSource ccsmapping = repo.addContentSource(cs); entityManager.persist(ccsmapping); } }
/** * Directly assign a repo to this content source. * * @param repo * * @return the mapping that was added */ public RepoContentSource addRepo(Repo repo) { if (this.repoContentSources == null) { this.repoContentSources = new HashSet<RepoContentSource>(); } RepoContentSource mapping = new RepoContentSource(repo, this); this.repoContentSources.add(mapping); repo.addContentSource(this); return mapping; }
RepoContentSource repoContentSourceMapping = repo.addContentSource(contentSource); entityManager.persist(repoContentSourceMapping);