@Override public Void call() throws Exception { try { final AtomicReference<Provider<ReviewDb>> dbRef = Atomics.newReference(); RequestContext newCtx = new RequestContext() { @Override public Provider<ReviewDb> getReviewDbProvider() { Provider<ReviewDb> db = dbRef.get(); if (db == null) { try { db = Providers.of(schemaFactory.open()); } catch (OrmException e) { ProvisionException pe = new ProvisionException("error opening ReviewDb"); pe.initCause(e); throw pe; } dbRef.set(db); } return db; } @Override public CurrentUser getCurrentUser() { throw new OutOfScopeException("No user during ChangeIndexer"); } }; RequestContext oldCtx = context.setContext(newCtx); try { ChangeData cd = changeDataFactory.create(newCtx.getReviewDbProvider().get(), id); for (ChangeIndex i : getWriteIndexes()) { i.replace(cd); } return null; } finally { context.setContext(oldCtx); Provider<ReviewDb> db = dbRef.get(); if (db != null) { db.get().close(); } } } catch (Exception e) { log.error(String.format("Failed to index change %d", id.get()), e); throw e; } }
protected ChangeInserter newChange( TestRepository<Repo> repo, @Nullable RevCommit commit, @Nullable String key, @Nullable Integer owner, @Nullable String branch) throws Exception { if (commit == null) { commit = repo.parseBody(repo.commit().message("message").create()); } Account.Id ownerId = owner != null ? new Account.Id(owner) : userId; branch = MoreObjects.firstNonNull(branch, "refs/heads/master"); if (!branch.startsWith("refs/heads/")) { branch = "refs/heads/" + branch; } Project.NameKey project = new Project.NameKey(repo.getRepository().getDescription().getRepositoryName()); Change.Id id = new Change.Id(db.nextChangeId()); if (key == null) { key = "I" + Hashing.sha1() .newHasher() .putInt(id.get()) .putString(project.get(), UTF_8) .putString(commit.name(), UTF_8) .putInt(ownerId.get()) .putString(branch, UTF_8) .hash() .toString(); } Change change = new Change( new Change.Key(key), id, ownerId, new Branch.NameKey(project, branch), TimeUtil.nowTs()); IdentifiedUser user = userFactory.create(Providers.of(db), ownerId); return changeFactory.create(projectControlFactory.controlFor(project, user), change, commit); }
@Override protected void onLoad() { if (!loaded) { RestApi call = ChangeApi.detail(changeId.get()); ChangeList.addOptions( call, EnumSet.of(ListChangesOption.ALL_COMMITS, ListChangesOption.ALL_REVISIONS)); call.get( new AsyncCallback<ChangeInfo>() { @Override public void onSuccess(ChangeInfo result) { if (edit != null) { edit.setName(edit.commit().commit()); result.revisions().put(edit.name(), RevisionInfo.fromEdit(edit)); } render(result.revisions()); loaded = true; } @Override public void onFailure(Throwable caught) {} }); } }
@Override public String toString() { return "index-change-" + id.get(); }