use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testCommitUpdatesRemoteRefs.
@Test
public void testCommitUpdatesRemoteRefs() throws Exception {
// make a commit
insertAndAdd(points1);
RevCommit headCommit = geogig.command(CommitOp.class).call();
geogig.command(RemoteAddOp.class).setName("upstream").setURL("http://test.com/geogig/upstream").call();
final String remoteRef = "refs/remotes/upstream/master";
final String unchangedRemoteRef = "refs/remotes/upstream/testbranch";
Ref remoteHead = geogig.command(UpdateRef.class).setName(remoteRef).setNewValue(headCommit.getId()).call().get();
assertEquals(headCommit.getId(), remoteHead.getObjectId());
geogig.command(UpdateRef.class).setName(unchangedRemoteRef).setNewValue(headCommit.getId()).call().get();
// start a transaction
GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
// make a commit
insertAndAdd(tx, points2);
RevCommit newcommit = tx.command(CommitOp.class).call();
// upadte remote
Ref txRemoteHead = tx.command(UpdateRef.class).setName(remoteRef).setNewValue(newcommit.getId()).call().get();
assertEquals(newcommit.getId(), txRemoteHead.getObjectId());
// commit transaction
tx.commit();
txRemoteHead = geogig.command(RefParse.class).setName(remoteRef).call().get();
assertEquals(newcommit.getId(), txRemoteHead.getObjectId());
txRemoteHead = geogig.command(RefParse.class).setName(unchangedRemoteRef).call().get();
assertEquals(headCommit.getId(), txRemoteHead.getObjectId());
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testTransaction.
@Test
public void testTransaction() throws Exception {
LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>();
LinkedList<RevCommit> expectedTransaction = new LinkedList<RevCommit>();
// make a commit
insertAndAdd(points1);
RevCommit commit = geogig.command(CommitOp.class).call();
expectedMain.addFirst(commit);
expectedTransaction.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();
expectedTransaction.addFirst(commit);
// 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);
// Verify that the transaction has the commit
logs = t.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedTransaction, logged);
// Commit the transaction
geogig.command(TransactionEnd.class).setTransaction(t).setRebase(true).call();
// Verify that the base repository has the changes from the transaction
logs = geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedTransaction, logged);
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testEndWithinTransaction.
@Test
public void testEndWithinTransaction() throws Exception {
// make a commit
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
// start a transaction
GeogigTransaction t = geogig.command(TransactionBegin.class).call();
// perform a commit in the transaction
insertAndAdd(t, points2);
t.command(CommitOp.class).call();
// End the transaction
exception.expect(IllegalStateException.class);
t.command(TransactionEnd.class).setTransaction(t).call();
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class TransactionBegin method _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) {
Throwables.propagate(e);
}
try {
// Copy original refs
t.create();
} finally {
// Unlock the repository
refDatabase().unlock();
}
// Return the transaction
return t;
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeoGigDataStore method createSchema.
/**
* Creates a new feature type tree on the {@link #getOrFigureOutBranch() current branch}.
* <p>
* Implementation detail: the operation is the homologous to starting a transaction, checking
* out the current/configured branch, creating the type tree inside the transaction, issueing a
* geogig commit, and committing the transaction for the created tree to be merged onto the
* configured branch.
*/
@Override
public void createSchema(SimpleFeatureType featureType) throws IOException {
if (!allowTransactions) {
throw new IllegalStateException("Configured head " + refspec + " is not a branch; transactions are not supported.");
}
GeogigTransaction tx = getCommandLocator(null).command(TransactionBegin.class).call();
boolean abort = false;
try {
String treePath = featureType.getName().getLocalPart();
// check out the datastore branch on the transaction space
final String branch = getOrFigureOutBranch();
tx.command(CheckoutOp.class).setForce(true).setSource(branch).call();
// now we can use the transaction working tree with the correct branch checked out
WorkingTree workingTree = tx.workingTree();
workingTree.createTypeTree(treePath, featureType);
tx.command(AddOp.class).addPattern(treePath).call();
tx.command(CommitOp.class).setMessage("Created feature type tree " + treePath).call();
tx.commit();
} catch (IllegalArgumentException alreadyExists) {
abort = true;
throw new IOException(alreadyExists.getMessage(), alreadyExists);
} catch (Exception e) {
abort = true;
throw Throwables.propagate(e);
} finally {
if (abort) {
tx.abort();
}
}
}
Aggregations