當前位置: 首頁>>代碼示例>>Java>>正文


Java AtomicUpdate類代碼示例

本文整理匯總了Java中com.google.gwtorm.server.AtomicUpdate的典型用法代碼示例。如果您正苦於以下問題:Java AtomicUpdate類的具體用法?Java AtomicUpdate怎麽用?Java AtomicUpdate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AtomicUpdate類屬於com.google.gwtorm.server包,在下文中一共展示了AtomicUpdate類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setPrimaryStorageNoteDb

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
private void setPrimaryStorageNoteDb(Change.Id id, NoteDbChangeState expectedState)
    throws OrmException {
  db().changes()
      .atomicUpdate(
          id,
          new AtomicUpdate<Change>() {
            @Override
            public Change update(Change change) {
              NoteDbChangeState state = NoteDbChangeState.parse(change);
              if (!Objects.equals(state, expectedState)) {
                throw new OrmRuntimeException(badState(state, expectedState));
              }
              Timestamp until = state.getReadOnlyUntil().get();
              if (TimeUtil.nowTs().after(until)) {
                throw new OrmRuntimeException(
                    "read-only lease on change " + id + " expired at " + until);
              }
              change.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
              return change;
            }
          });
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:23,代碼來源:PrimaryStorageMigrator.java

示例2: setReadOnlyInReviewDb

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
private Change setReadOnlyInReviewDb(Change.Id id) throws OrmException {
  AtomicBoolean alreadyMigrated = new AtomicBoolean(false);
  Change result =
      db().changes()
          .atomicUpdate(
              id,
              new AtomicUpdate<Change>() {
                @Override
                public Change update(Change change) {
                  NoteDbChangeState state = NoteDbChangeState.parse(change);
                  if (state == null) {
                    // Could rebuild the change here, but that's more complexity, and this
                    // really shouldn't happen.
                    throw new OrmRuntimeException(
                        "change " + id + " has no note_db_state; rebuild it first");
                  }
                  // If the change is already read-only, then the lease is held by another
                  // (likely failed) migrator thread. Fail early, as we can't take over
                  // the lease.
                  NoteDbChangeState.checkNotReadOnly(change, skewMs);
                  if (state.getPrimaryStorage() != PrimaryStorage.NOTE_DB) {
                    Timestamp now = TimeUtil.nowTs();
                    Timestamp until = new Timestamp(now.getTime() + timeoutMs);
                    change.setNoteDbState(state.withReadOnlyUntil(until).toString());
                  } else {
                    alreadyMigrated.set(true);
                  }
                  return change;
                }
              });
  return alreadyMigrated.get() ? null : result;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:33,代碼來源:PrimaryStorageMigrator.java

示例3: setPrimaryStorageReviewDb

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
private void setPrimaryStorageReviewDb(Change.Id id, ObjectId newMetaId)
    throws OrmException, IOException {
  ImmutableMap.Builder<Account.Id, ObjectId> draftIds = ImmutableMap.builder();
  try (Repository repo = repoManager.openRepository(allUsers)) {
    for (Ref draftRef :
        repo.getRefDatabase().getRefs(RefNames.refsDraftCommentsPrefix(id)).values()) {
      Account.Id accountId = Account.Id.fromRef(draftRef.getName());
      if (accountId != null) {
        draftIds.put(accountId, draftRef.getObjectId().copy());
      }
    }
  }
  NoteDbChangeState newState =
      new NoteDbChangeState(
          id,
          PrimaryStorage.REVIEW_DB,
          Optional.of(RefState.create(newMetaId, draftIds.build())),
          Optional.empty());
  db().changes()
      .atomicUpdate(
          id,
          new AtomicUpdate<Change>() {
            @Override
            public Change update(Change change) {
              if (PrimaryStorage.of(change) != PrimaryStorage.NOTE_DB) {
                throw new OrmRuntimeException(
                    "change " + id + " is not NoteDb primary: " + change.getNoteDbState());
              }
              change.setNoteDbState(newState.toString());
              return change;
            }
          });
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:34,代碼來源:PrimaryStorageMigrator.java

示例4: atomicUpdate

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
@Override
public Change atomicUpdate(Change.Id key, AtomicUpdate<Change> update) throws OrmException {
  return delegate.atomicUpdate(key, update);
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:5,代碼來源:ReviewDbWrapper.java

示例5: atomicUpdate

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
@Override
public Change atomicUpdate(Change.Id key, AtomicUpdate<Change> update) {
  throw new UnsupportedOperationException(
      "do not call atomicUpdate; updateChange is always called within a transaction");
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:6,代碼來源:BatchUpdateReviewDb.java

示例6: atomicUpdate

import com.google.gwtorm.server.AtomicUpdate; //導入依賴的package包/類
@Override
public final T atomicUpdate(K key, AtomicUpdate<T> update) {
  return null;
}
 
開發者ID:gerrit-review,項目名稱:gerrit,代碼行數:5,代碼來源:NoChangesReviewDbWrapper.java


注:本文中的com.google.gwtorm.server.AtomicUpdate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。