Allow passing a TermBuilder to be transacted by InProgress; add TermBuilder::is_empty. r=emily
This commit is contained in:
parent
27dde378e0
commit
a5cda7c3e9
2 changed files with 19 additions and 9 deletions
10
src/conn.rs
10
src/conn.rs
|
@ -83,6 +83,7 @@ use uuid::Uuid;
|
||||||
use entity_builder::{
|
use entity_builder::{
|
||||||
BuildTerms,
|
BuildTerms,
|
||||||
InProgressBuilder,
|
InProgressBuilder,
|
||||||
|
TermBuilder,
|
||||||
};
|
};
|
||||||
|
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
@ -390,6 +391,15 @@ impl<'a, 'c> InProgress<'a, 'c> {
|
||||||
self.use_caching = yesno;
|
self.use_caching = yesno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If you only have a reference to an `InProgress`, you can't use the easy builder.
|
||||||
|
/// This exists so you can make your own.
|
||||||
|
pub fn transact_builder(&mut self, builder: TermBuilder) -> Result<TxReport> {
|
||||||
|
builder.build()
|
||||||
|
.and_then(|(terms, tempid_set)| {
|
||||||
|
self.transact_terms(terms, tempid_set)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn transact_terms<I>(&mut self, terms: I, tempid_set: InternSet<TempId>) -> Result<TxReport> where I: IntoIterator<Item=TermWithTempIds> {
|
pub fn transact_terms<I>(&mut self, terms: I, tempid_set: InternSet<TempId>) -> Result<TxReport> where I: IntoIterator<Item=TermWithTempIds> {
|
||||||
let w = InProgressTransactWatcher::new(
|
let w = InProgressTransactWatcher::new(
|
||||||
&mut self.tx_observer_watcher,
|
&mut self.tx_observer_watcher,
|
||||||
|
|
|
@ -161,6 +161,10 @@ impl TermBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.terms.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn numbered_tempid(&mut self, id: i64) -> TempIdHandle {
|
pub fn numbered_tempid(&mut self, id: i64) -> TempIdHandle {
|
||||||
self.tempids.intern(TempId::Internal(id))
|
self.tempids.intern(TempId::Internal(id))
|
||||||
|
@ -213,15 +217,11 @@ impl<'a, 'c> InProgressBuilder<'a, 'c> {
|
||||||
/// step fails, roll back. Return the `TxReport`.
|
/// step fails, roll back. Return the `TxReport`.
|
||||||
pub fn commit(self) -> Result<TxReport> {
|
pub fn commit(self) -> Result<TxReport> {
|
||||||
let mut in_progress = self.in_progress;
|
let mut in_progress = self.in_progress;
|
||||||
self.builder
|
in_progress.transact_builder(self.builder)
|
||||||
.build()
|
|
||||||
.and_then(|(terms, tempid_set)| {
|
|
||||||
in_progress.transact_terms(terms, tempid_set)
|
|
||||||
.and_then(|report| {
|
.and_then(|report| {
|
||||||
in_progress.commit()?;
|
in_progress.commit()?;
|
||||||
Ok(report)
|
Ok(report)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue