当前位置: 首页>>代码示例>>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;未经允许,请勿转载。