Skip to content

Commit

Permalink
added commit and rollback methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed May 17, 2013
1 parent 45bc0a3 commit 0c1dcde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Expand Up @@ -92,7 +92,7 @@ public Transaction commit(@PathParam("txid")
throw new RepositoryException("Transaction with id " + txid +
" is not available");
}
tx.getSession().save();
tx.commit();
tx.setState(State.COMMITED);
return tx;
}
Expand All @@ -118,6 +118,7 @@ public Response createObjectInTransaction(@PathParam("txid")
final String txid, @PathParam("path")
final List<PathSegment> pathlist) throws RepositoryException {
Transaction tx = transactions.get(txid);
tx.updateExpiryDate();
if (tx == null) {
throw new RepositoryException("Transaction with id " + txid +
" is not available");
Expand Down
30 changes: 22 additions & 8 deletions fcrepo-kernel/src/main/java/org/fcrepo/Transaction.java
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;
import java.util.UUID;

import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand All @@ -28,7 +29,7 @@ public enum State {
private final Date created;

@XmlAttribute(name = "expires")
private final Date expires;
private Date expires;

private State state = State.NEW;

Expand All @@ -43,14 +44,8 @@ public Transaction(Session session) {
super();
this.session = session;
this.created = new Date();
long duration;
if (System.getProperty("fcrepo4.tx.timeout") != null){
duration = Long.parseLong(System.getProperty("fcrepo4.tx.timeout"));
}else{
duration = 1000l * 60l * 3l;
}
this.expires = new Date(System.currentTimeMillis() + duration);
this.id = UUID.randomUUID().toString();
this.updateExpiryDate();
}

public Session getSession() {
Expand All @@ -77,4 +72,23 @@ public Date getExpires() {
return expires;
}

public void commit() throws RepositoryException{
this.state = State.COMMITED;
this.session.save();
}

public void rollback() throws RepositoryException {
this.state = State.ROLLED_BACK;
}

public void updateExpiryDate() {
long duration;
if (System.getProperty("fcrepo4.tx.timeout") != null){
duration = Long.parseLong(System.getProperty("fcrepo4.tx.timeout"));
}else{
duration = 1000l * 60l * 3l;
}
this.expires = new Date(System.currentTimeMillis() + duration);
}

}

0 comments on commit 0c1dcde

Please sign in to comment.