Allow passing a TermBuilder to be transacted by InProgress; add TermBuilder::is_empty. r=emily

This commit is contained in:
Richard Newman 2018-04-03 19:22:10 -07:00
parent 27dde378e0
commit a5cda7c3e9
2 changed files with 19 additions and 9 deletions

View file

@ -83,6 +83,7 @@ use uuid::Uuid;
use entity_builder::{
BuildTerms,
InProgressBuilder,
TermBuilder,
};
use errors::*;
@ -390,6 +391,15 @@ impl<'a, 'c> InProgress<'a, 'c> {
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> {
let w = InProgressTransactWatcher::new(
&mut self.tx_observer_watcher,

View file

@ -161,6 +161,10 @@ impl TermBuilder {
}
}
pub fn is_empty(&self) -> bool {
self.terms.is_empty()
}
#[allow(dead_code)]
pub fn numbered_tempid(&mut self, id: i64) -> TempIdHandle {
self.tempids.intern(TempId::Internal(id))
@ -213,15 +217,11 @@ impl<'a, 'c> InProgressBuilder<'a, 'c> {
/// step fails, roll back. Return the `TxReport`.
pub fn commit(self) -> Result<TxReport> {
let mut in_progress = self.in_progress;
self.builder
.build()
.and_then(|(terms, tempid_set)| {
in_progress.transact_terms(terms, tempid_set)
.and_then(|report| {
in_progress.commit()?;
Ok(report)
})
})
in_progress.transact_builder(self.builder)
.and_then(|report| {
in_progress.commit()?;
Ok(report)
})
}
}