Allows RepositoryConnection to keep a state by making edit actions take a mut reference

pull/10/head
Tpt 5 years ago
parent 3d1cb137d9
commit ab08308bb6
  1. 2
      lib/src/lib.rs
  2. 18
      lib/src/repository.rs
  3. 2
      lib/src/store/memory.rs
  4. 8
      lib/src/store/mod.rs
  5. 2
      lib/src/store/rocksdb.rs
  6. 12
      lib/tests/sparql_test_cases.rs
  7. 4
      server/src/main.rs

@ -15,7 +15,7 @@
//! use rudf::sparql::QueryResult;
//!
//! let repository = MemoryRepository::default();
//! let connection = repository.connection().unwrap();
//! let mut connection = repository.connection().unwrap();
//!
//! // insertion
//! let ex = NamedNode::parse("http://example.com").unwrap();

@ -18,7 +18,7 @@ use std::io::BufRead;
/// use rudf::sparql::QueryResult;
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let ex = NamedNode::parse("http://example.com").unwrap();
@ -68,7 +68,7 @@ pub trait RepositoryConnection: Clone {
/// use rudf::sparql::QueryResult;
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertions
/// let ex = NamedNode::parse("http://example.com").unwrap();
@ -91,7 +91,7 @@ pub trait RepositoryConnection: Clone {
/// use rudf::{Repository, RepositoryConnection, MemoryRepository, Result};
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let ex = NamedNode::parse("http://example.com").unwrap();
@ -120,7 +120,7 @@ pub trait RepositoryConnection: Clone {
/// use rudf::{Repository, RepositoryConnection, MemoryRepository, Result, GraphSyntax};
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> .";
@ -132,7 +132,7 @@ pub trait RepositoryConnection: Clone {
/// assert_eq!(vec![Quad::new(ex.clone(), ex.clone(), ex.clone(), None)], results.unwrap());
/// ```
fn load_graph(
&self,
&mut self,
reader: impl BufRead,
syntax: GraphSyntax,
to_graph_name: Option<&NamedOrBlankNode>,
@ -147,7 +147,7 @@ pub trait RepositoryConnection: Clone {
/// use rudf::{Repository, RepositoryConnection, MemoryRepository, Result, DatasetSyntax};
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let file = b"<http://example.com> <http://example.com> <http://example.com> <http://example.com> .";
@ -159,7 +159,7 @@ pub trait RepositoryConnection: Clone {
/// assert_eq!(vec![Quad::new(ex.clone(), ex.clone(), ex.clone(), Some(ex.into()))], results.unwrap());
/// ```
fn load_dataset(
&self,
&mut self,
reader: impl BufRead,
syntax: DatasetSyntax,
base_iri: Option<&str>,
@ -169,8 +169,8 @@ pub trait RepositoryConnection: Clone {
fn contains(&self, quad: &Quad) -> Result<bool>;
/// Adds a quad to this repository
fn insert(&self, quad: &Quad) -> Result<()>;
fn insert(&mut self, quad: &Quad) -> Result<()>;
/// Removes a quad from this repository
fn remove(&self, quad: &Quad) -> Result<()>;
fn remove(&mut self, quad: &Quad) -> Result<()>;
}

@ -20,7 +20,7 @@ use std::sync::RwLockWriteGuard;
/// use rudf::sparql::QueryResult;
///
/// let repository = MemoryRepository::default();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let ex = NamedNode::parse("http://example.com").unwrap();

@ -119,7 +119,7 @@ impl<S: StoreConnection> RepositoryConnection for StoreRepositoryConnection<S> {
}
fn load_graph(
&self,
&mut self,
reader: impl BufRead,
syntax: GraphSyntax,
to_graph_name: Option<&NamedOrBlankNode>,
@ -140,7 +140,7 @@ impl<S: StoreConnection> RepositoryConnection for StoreRepositoryConnection<S> {
}
fn load_dataset(
&self,
&mut self,
reader: impl BufRead,
syntax: DatasetSyntax,
base_iri: Option<&str>,
@ -157,11 +157,11 @@ impl<S: StoreConnection> RepositoryConnection for StoreRepositoryConnection<S> {
.contains(&self.inner.encoder().encode_quad(quad)?)
}
fn insert(&self, quad: &Quad) -> Result<()> {
fn insert(&mut self, quad: &Quad) -> Result<()> {
self.inner.insert(&self.inner.encoder().encode_quad(quad)?)
}
fn remove(&self, quad: &Quad) -> Result<()> {
fn remove(&mut self, quad: &Quad) -> Result<()> {
self.inner.remove(&self.inner.encoder().encode_quad(quad)?)
}
}

@ -30,7 +30,7 @@ use std::sync::Mutex;
/// use rudf::sparql::QueryResult;
///
/// let repository = RocksDbRepository::open("example.db").unwrap();
/// let connection = repository.connection().unwrap();
/// let mut connection = repository.connection().unwrap();
///
/// // insertion
/// let ex = NamedNode::parse("http://example.com").unwrap();

@ -136,12 +136,12 @@ fn sparql_w3c_query_evaluation_testsuite() -> Result<()> {
} else if test.kind == "QueryEvaluationTest" {
let repository = MemoryRepository::default();
if let Some(data) = &test.data {
load_graph_to_repository(&data, &repository.connection()?, None)?;
load_graph_to_repository(&data, &mut repository.connection()?, None)?;
}
for graph_data in &test.graph_data {
load_graph_to_repository(
&graph_data,
&repository.connection()?,
&mut repository.connection()?,
Some(&NamedNode::parse(graph_data)?.into()),
)?;
}
@ -206,7 +206,7 @@ fn repository_to_string(repository: impl Repository) -> String {
fn load_graph(url: &str) -> Result<SimpleGraph> {
let repository = MemoryRepository::default();
load_graph_to_repository(url, &repository.connection().unwrap(), None)?;
load_graph_to_repository(url, &mut repository.connection().unwrap(), None)?;
Ok(repository
.connection()
.unwrap()
@ -217,7 +217,7 @@ fn load_graph(url: &str) -> Result<SimpleGraph> {
fn load_graph_to_repository(
url: &str,
connection: &<&MemoryRepository as Repository>::Connection,
connection: &mut <&MemoryRepository as Repository>::Connection,
to_graph_name: Option<&NamedOrBlankNode>,
) -> Result<()> {
let syntax = if url.ends_with(".nt") {
@ -234,7 +234,7 @@ fn load_graph_to_repository(
fn load_sparql_query_result_graph(url: &str) -> Result<SimpleGraph> {
let repository = MemoryRepository::default();
let connection = repository.connection()?;
let mut connection = repository.connection()?;
if url.ends_with(".srx") {
for t in to_graph(
QueryResult::read(read_file(url)?, QueryResultSyntax::Xml)?,
@ -243,7 +243,7 @@ fn load_sparql_query_result_graph(url: &str) -> Result<SimpleGraph> {
connection.insert(&t.in_graph(None))?;
}
} else {
load_graph_to_repository(url, &connection, None)?;
load_graph_to_repository(url, &mut connection, None)?;
}
Ok(connection
.quads_for_pattern(None, None, None, Some(None))

@ -13,7 +13,7 @@ use rudf::{
use std::io::{BufReader, Read};
use std::sync::Arc;
const MAX_SPARQL_BODY_SIZE: u64 = 1048576;
const MAX_SPARQL_BODY_SIZE: u64 = 1_048_576;
const HTML_ROOT_PAGE: &str = include_str!("../templates/query.html");
pub fn main() {
@ -59,7 +59,7 @@ where
fn handle_request<R: RepositoryConnection>(
request: &Request,
connection: R,
mut connection: R,
host: &str,
) -> Response {
match (request.url().as_str(), request.method()) {

Loading…
Cancel
Save