コード例 #1
0
ファイル: ChangeIndexer.java プロジェクト: kinglcc/gerrit
    @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;
      }
    }
コード例 #2
0
ファイル: ChangeIndexer.java プロジェクト: kinglcc/gerrit
 /**
  * Synchronously index a change.
  *
  * @param cd change to index.
  */
 public void index(ChangeData cd) throws IOException {
   for (ChangeIndex i : getWriteIndexes()) {
     i.replace(cd);
   }
 }