public TestData startTransaction() { checkState(transaction == null, "There's a transaction already running"); GeogigTransaction tx = getContext().command(TransactionBegin.class).call(); setTransaction(tx); return this; }
/** * Creates a new transaction and returns it. * * @return the {@link GeogigTransaction} that was created by the operation */ @Override protected GeogigTransaction _call() { Preconditions.checkState(!(context instanceof GeogigTransaction), "Cannot start a new transaction within a transaction!"); GeogigTransaction t = new GeogigTransaction(context, UUID.randomUUID()); // Lock the repository try { refDatabase().lock(); } catch (TimeoutException e) { Throwables.propagate(e); } try { // Copy original refs t.create(); } finally { // Unlock the repository refDatabase().unlock(); } // Return the transaction return t; } }
@Override public void setTransaction(@Nullable final Transaction transaction) { Preconditions.checkArgument(!Transaction.AUTO_COMMIT.equals(transaction)); if (transaction != null && this.tx != null) { throw new IllegalStateException( "New transaction set without closing old transaction first."); } this.tx = transaction; if (transaction == null) { // Transaction.removeState has been called (during // transaction.close()) if (this.geogigTx != null) { // throw new // IllegalStateException("Transaction is attempting to " // + "close a non committed or aborted geogig transaction"); geogigTx.abort(); } this.geogigTx = null; } else { if (this.geogigTx != null) { geogigTx.abort(); } GeoGigDataStore dataStore = (GeoGigDataStore) entry.getDataStore(); Context commandLocator = dataStore.resolveContext(this.tx); this.geogigTx = commandLocator.command(TransactionBegin.class).call(); // checkout the working branch final String workingBranch = dataStore.getOrFigureOutHead(); this.geogigTx.command(CheckoutOp.class).setForce(true).setSource(workingBranch).call(); } }
/** * Creates a new transaction and returns it. * * @return the {@link GeogigTransaction} that was created by the operation */ @Override protected GeogigTransaction _call() { Preconditions.checkState(!(context instanceof GeogigTransaction), "Cannot start a new transaction within a transaction!"); GeogigTransaction t = new GeogigTransaction(context, UUID.randomUUID()); // Lock the repository try { refDatabase().lock(); } catch (TimeoutException e) { throw new RuntimeException(e); } try { // Copy original refs t.create(); } finally { // Unlock the repository refDatabase().unlock(); } // Return the transaction return t; } }
/** * Runs the command and builds the appropriate response. * * @param context - the context to use for this command * * @throws CommandSpecException */ @Override protected void runInternal(CommandContext context) { if (this.getTransactionId() != null) { throw new CommandSpecException("Tried to start a transaction within a transaction."); } final Repository geogig = context.getRepository(); final GeogigTransaction transaction = geogig.command(TransactionBegin.class).call(); context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeTransactionId(transaction.getTransactionId()); out.finish(); } }); }
GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); try { Optional<Ref> oldRef = tx.command(RefParse.class).setName(refspec).call();
/** * Creates a transaction on the given repository and stores the transaction id in the given * variable for later use. * * @param variableName the variable name to store the transaction id. * @param repoName the repository on which to create the transaction. */ @Given("^I have a transaction as \"([^\"]*)\" on the \"([^\"]*)\" repo$") public void beginTransactionAsVariable(final String variableName, final String repoName) { GeogigTransaction transaction = context.getRepo(repoName).command(TransactionBegin.class) .call(); context.setVariable(variableName, transaction.getTransactionId().toString()); // add the repo to the set so it can be closed openedRepos.add(repoName); }
@Test public void testBeginWithinTransaction() throws Exception { // make a commit insertAndAdd(points1); geogig.command(CommitOp.class).call(); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // start a transaction within the transaction exception.expect(IllegalStateException.class); t.command(TransactionBegin.class).call(); }
@Test public void testBeginWithinTransaction() throws Exception { // make a commit insertAndAdd(points1); geogig.command(CommitOp.class).call(); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // start a transaction within the transaction exception.expect(IllegalStateException.class); t.command(TransactionBegin.class).call(); }
GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); try { updateRemotes(tx, currentRemotes, newRemotes);
+ " is not a branch; transactions are not supported."); GeogigTransaction tx = resolveContext(null).command(TransactionBegin.class).call(); boolean abort = false; try {
@Test public void testResolveTransaction() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); }
@Test public void testResolveTransaction() throws Exception { GeogigTransaction tx = geogig.command(TransactionBegin.class).call(); Optional<GeogigTransaction> txNew = geogig.command(TransactionResolve.class) .setId(tx.getTransactionId()).call(); assertTrue(txNew.isPresent()); }
private PR prepare(PR pr) { Preconditions.checkNotNull(pr.getTransactionId()); Preconditions.checkNotNull(pr.getId()); getProgressListener().setDescription("Initializing pull request " + pr); com.google.common.base.Optional<GeogigTransaction> tx = command(TransactionResolve.class) .setId(pr.getTransactionId()).call(); if (!tx.isPresent()) { PRStatus status = command(PRHealthCheckOp.class).setRequest(pr).call(); checkState(!status.isMerged(), "Cannot re open pull request %s because it's already merged", pr.getId()); // reinitialize a transaction, pr was closes final GeogigTransaction txContext = command(TransactionBegin.class).call(); final UUID txId = txContext.getTransactionId(); pr.setTransactionId(txId); } if (remoteURI != null) pr.setRemote(remoteURI); if (remoteBranch != null) pr.setRemoteBranch(remoteBranch); if (targetBranch != null) pr.setTargetBranch(targetBranch); if (title != null) pr.setTitle(title); if (description != null) pr.setDescription(description); return pr; }
GeogigTransaction t = geogig.command(TransactionBegin.class).call();
GeogigTransaction t = geogig.command(TransactionBegin.class).call();
@Test public void testCancelTransaction() throws Exception { LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>(); // make a commit insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); expectedMain.addFirst(commit); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // perform a commit in the transaction insertAndAdd(t, points2); commit = t.command(CommitOp.class).call(); // Verify that the base repository is unchanged Iterator<RevCommit> logs = geogig.command(LogOp.class).call(); List<RevCommit> logged = new ArrayList<RevCommit>(); for (; logs.hasNext();) { logged.add(logs.next()); } assertEquals(expectedMain, logged); // Cancel the transaction geogig.command(TransactionEnd.class).setCancel(true).setTransaction(t).call(); // Verify that the base repository is unchanged logs = geogig.command(LogOp.class).call(); logged = new ArrayList<RevCommit>(); for (; logs.hasNext();) { logged.add(logs.next()); } assertEquals(expectedMain, logged); }
@Test public void testCancelTransaction() throws Exception { LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>(); // make a commit insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); expectedMain.addFirst(commit); // start a transaction GeogigTransaction t = geogig.command(TransactionBegin.class).call(); // perform a commit in the transaction insertAndAdd(t, points2); commit = t.command(CommitOp.class).call(); // Verify that the base repository is unchanged Iterator<RevCommit> logs = geogig.command(LogOp.class).call(); List<RevCommit> logged = new ArrayList<RevCommit>(); for (; logs.hasNext();) { logged.add(logs.next()); } assertEquals(expectedMain, logged); // Cancel the transaction geogig.command(TransactionEnd.class).setCancel(true).setTransaction(t).call(); // Verify that the base repository is unchanged logs = geogig.command(LogOp.class).call(); logged = new ArrayList<RevCommit>(); for (; logs.hasNext();) { logged.add(logs.next()); } assertEquals(expectedMain, logged); }
private PR build() { final GeogigTransaction txContext = command(TransactionBegin.class).call(); final UUID txId = txContext.getTransactionId(); final PR pr; pr = PR.builder()// .id(id)// .transactionId(txId).remote(remoteURI)// .remoteBranch(remoteBranch)// .targetBranch(targetBranch)// .title(title)// .description(description)// .build(); getProgressListener().setDescription("Creating pull request " + pr); return pr; }
GeogigTransaction t = geogig.command(TransactionBegin.class).call();