public class InProgress extends Object
InProgress
object.
InProgress
allows for multiple transacts to be performed in a single transaction.
Each transact performed results in a TxReport
that can be used to gather information
to be used in subsequent transacts.
Committing an InProgress
commits all the transacts that have been performed using
that InProgress
.
Rolling back and InProgress
rolls back all the transacts that have been performed
using that InProgress
.
do {
let inProgress = try mentat.beginTransaction()
let txReport = try inProgress.transact(transaction: "[[:db/add "a" :foo/long 22]]")
let aEntid = txReport.entid(forTempId: "a")
let report = try inProgress.transact(transaction: "[[:db/add "b" :foo/ref \(aEntid)] [:db/add "b" :foo/boolean true]]")
try inProgress.commit()
} catch {
...
}
InProgress
also provides a number of functions to generating an builder to assert datoms
programatically. The two types of builder are InProgressBuilder
and EntityBuilder
.
InProgressBuilder
takes the current InProgress
and provides a programmatic
interface to add and retract values from entities for which there exists an `Entid`. The provided
InProgress
is used to perform the transacts.
long aEntid = txReport.getEntidForTempId("a");
long bEntid = txReport.getEntidForTempId("b");
InProgress inProgress = mentat.beginTransaction();
InProgressBuilder builder = inProgress.builder();
builder.add(bEntid, ":foo/boolean", true);
builder.add(aEntid, ":foo/instant", newDate);
inProgress = builder.transact().getInProgress();
inProgress.transact("[[:db/add \(aEntid) :foo/long 22]]");
inProgress.commit();
}
EntityBuilder
takes the current InProgress
and either an `Entid` or a `tempid` to
provide a programmatic interface to add and retract values from a specific entity. The provided
InProgress
is used to perform the transacts.
long aEntid = txReport.getEntidForTempId("a");
long bEntid = txReport.getEntidForTempId("b");
InProgress inProgress = mentat.beginTransaction();
EntityBuilder builder = inProgress.builderForEntid(bEntid);
builder.add(":foo/boolean", true);
builder.add(":foo/instant", newDate);
inProgress = builder.transact().getInProgress();
inProgress.transact("[[:db/add \(aEntid) :foo/long 22]]");
inProgress.commit();
Constructor and Description |
---|
InProgress(JNA.InProgress pointer) |
Modifier and Type | Method and Description |
---|---|
InProgressBuilder |
builder()
Creates an
InProgressBuilder using this InProgress . |
EntityBuilder |
builderForEntid(long entid)
Creates an `EntityBuilder` using this `InProgress` for the entity with `entid`.
|
EntityBuilder |
builderForTempid(String tempid)
Creates an `EntityBuilder` using this `InProgress` for a new entity with `tempid`.
|
void |
close() |
void |
commit()
Commits all the transacts that have been performed on this `InProgress`, either directly
or through a Builder.
|
protected void |
destroyPointer(JNA.InProgress p) |
protected void |
finalize() |
void |
rollback()
Rolls back all the transacts that have been performed on this `InProgress`, either directly
or through a Builder.
|
TxReport |
transact(String transaction)
Transacts the `transaction`
This does not commit the transaction.
|
public InProgress(JNA.InProgress pointer)
public InProgressBuilder builder()
InProgressBuilder
using this InProgress
.InProgressBuilder
for this InProgress
public EntityBuilder builderForEntid(long entid)
entid
- The `Entid` for this entity.public EntityBuilder builderForTempid(String tempid)
tempid
- The temporary identifier for this entity.public TxReport transact(String transaction)
transaction
- The EDN string to be transacted.public void commit()
InProgress
such
that no further assertions can be performed after the `commit` has completed.
TODO throw exception if error occurspublic void rollback()
protected void destroyPointer(JNA.InProgress p)
public void close()
close
in interface AutoCloseable