Package com.google.walkaround.util.server.appengine.CheckedDatastore

Examples of com.google.walkaround.util.server.appengine.CheckedDatastore.CheckedTransaction


  @Override
  public String loadAtVersion(SlobId slobId, @Nullable Long version)
      throws IOException, AccessDeniedException {
    accessChecker.checkCanRead(slobId);
    try {
      CheckedTransaction tx = datastore.beginTransaction();
      try {
        MutationLog l = mutationLogFactory.create(tx, slobId);
        return l.reconstruct(version).getState().snapshot();
      } finally {
        tx.rollback();
      }
    } catch (PermanentFailure e) {
      throw new IOException(e);
    } catch (RetryableFailure e) {
      throw new IOException(e);
View Full Code Here


        && endVersion == null) {
      return new HistoryResult(ImmutableList.<ChangeData<String>>of(), false);
    }
    final int MAX_MILLIS = 3 * 1000;
    try {
      CheckedTransaction tx = datastore.beginTransaction();
      try {
        // TODO(ohler): put current version into cache
        DeltaIterator result = mutationLogFactory.create(tx, slobId).forwardHistory(
            startVersion, endVersion);
        if (!result.hasNext()) {
          return new HistoryResult(ImmutableList.<ChangeData<String>>of(), false);
        }
        ImmutableList.Builder<ChangeData<String>> list = ImmutableList.builder();
        Stopwatch stopwatch = new Stopwatch().start();
        do {
          list.add(result.next());
        } while (result.hasNext() && stopwatch.elapsedMillis() < MAX_MILLIS);
        return new HistoryResult(list.build(), result.hasNext());
      } finally {
        tx.rollback();
      }
    } catch (PermanentFailure e) {
      throw new IOException(e);
    } catch (RetryableFailure e) {
      // TODO(danilatos): Retry?
View Full Code Here

      private void flush() throws PermanentFailure, ChangeRejected {
        @Nullable ChangeRejected rejected = new RetryHelper().run(
            new RetryHelper.Body<ChangeRejected>() {
              @Override public ChangeRejected run() throws RetryableFailure, PermanentFailure {
                CheckedTransaction tx = datastore.beginTransaction();
                try {
                  MutationLog mutationLog = convSlobFacilities.getMutationLogFactory().create(
                      tx, slobId);
                  MutationLog.Appender appender = mutationLog.prepareAppender().getAppender();
                  try {
                    appender.appendAll(buffer);
                  } catch (ChangeRejected e) {
                    return e;
                  }
                  appender.finish();
                  tx.commit();
                  return null;
                } finally {
                  tx.close();
                }
              }
            });
        if (rejected != null) {
          throw rejected;
View Full Code Here

    String snapshot = "";

    if (!id.isEmpty()) {
      try {
        SlobId objectId = new SlobId(id);
        CheckedTransaction tx = datastore.beginTransaction();
        try {
          MutationLog mutationLog = storeSelector.get(storeType).getMutationLogFactory()
              .create(tx, objectId);
          objectVersion = mutationLog.getVersion();
          if (!historyStart.isEmpty()) {
            long start = Long.parseLong(historyStart);
            DeltaIterator it = mutationLog.forwardHistory(start,
                historyEnd.isEmpty() ? start + 1000 : Long.parseLong(historyEnd));
            for (long version = start; it.hasNext(); version++) {
              items.add(Pair.of(version, "" + it.next()));
            }
          }
          if (!snapshotVersion.isEmpty()) {
            snapshot = mutationLog.reconstruct(Long.parseLong(snapshotVersion))
                .getState().snapshot();
          }
        } finally {
          tx.rollback();
        }
      } catch (NumberFormatException e) {
        throw new BadRequestException(e);
      } catch (PermanentFailure e) {
        throw new IOException(e);
View Full Code Here

TOP

Related Classes of com.google.walkaround.util.server.appengine.CheckedDatastore.CheckedTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.