Esempio n. 1
0
        // TODO check whether transactions are supported by the storage provider to make those as atomical as possible
        /// <summary>
        /// Flushes changes to the dataset
        /// TODO handle dataset changes as updates instread of overwriting it to make it workable in a concurrent environment.
        /// </summary>
        public void Flush()
        {
            if (!Configuration.IsChanged)
            {
                return;
            }
            // TODO check if the updates did not raise any constraint violation, otherwise reject the Flush request
            // TODO related to the concurrency policy problem : handle any concurrent updates may have happened and succeded between the first modification and here
            SpinDatasetDescription updatedSourceDataset = new SpinDatasetDescription(Configuration.SourceUri);

            updatedSourceDataset.Assert(Configuration.GetTriplesWithPredicateObject(RDF.PropertyType, SPIN.ClassLibraryOntology));
            updatedSourceDataset.Assert(Configuration.GetTriplesWithPredicateObject(RDF.PropertyType, SD.ClassGraph));

            foreach (SpinWrappedGraph g in Configuration.ModificableGraphs)
            {
                Uri updatedGraphUri = Configuration.GetUpdateControlUri(g.BaseUri);
                Uri sourceGraph     = g.BaseUri;

                if (Configuration.IsGraphReplaced(sourceGraph))
                {
                    Storage.Update("WITH <" + updatedGraphUri.ToString() + "> DELETE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p } WHERE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p }"); // For safety only
                    Storage.Update("MOVE GRAPH <" + updatedGraphUri.ToString() + "> TO <" + sourceGraph.ToString() + ">");
                }
                else if (Configuration.IsGraphUpdated(sourceGraph))
                {
                    Storage.Update("DELETE { GRAPH <" + updatedGraphUri.ToString() + "> { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p } . GRAPH <" + sourceGraph.ToString() + "> { ?s ?p ?o } } USING <" + updatedGraphUri.ToString() + "> USING NAMED <" + g.BaseUri.ToString() + "> WHERE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p . GRAPH <" + g.BaseUri.ToString() + "> { ?s ?p ?o} }");
                    Storage.Update("ADD GRAPH <" + updatedGraphUri.ToString() + "> TO <" + sourceGraph.ToString() + ">");
                }
                else
                {
                    updatedSourceDataset.Retract(Configuration.GetTriplesWithSubject(RDFUtil.CreateUriNode(sourceGraph)));
                }
            }
            // TODO update the original dataset instead of overwriting it
            Storage.SaveGraph(updatedSourceDataset);
            DisposeUpdateControlledDataset();
        }
Esempio n. 2
0
 /// <summary>
 /// Inititalize a SpinWrapperDataset upon a storage engine using a RDF SparqlDataset definition.
 /// </summary>
 /// <param name="datasetUri"></param>
 /// <param name="storage"></param>
 public SpinWrappedDataset(Uri datasetUri, IUpdateableStorage storage)
 {
     Storage       = storage;
     Configuration = SpinDatasetDescription.Load(Storage, datasetUri);
     Initialise();
 }
Esempio n. 3
0
 /// <summary>
 /// Inititalize a SpinWrapperDataset upon a storage engine using all the graphs in the store.
 /// </summary>
 /// <param name="storage"></param>
 internal SpinWrappedDataset(IUpdateableStorage storage)
 {
     Storage       = storage;
     Configuration = SpinDatasetDescription.Load(Storage);
     Initialise();
 }
Esempio n. 4
0
 /// <summary>
 /// Inititalize a SPIN model upon a storage engine using a RDF SparqlDataset definition composed of the specified graphs.
 /// </summary>
 /// <param name="datasetUri"></param>
 /// <param name="storage"></param>
 /// <param name="graphUris"></param>
 public SpinWrappedDataset(Uri datasetUri, IUpdateableStorage storage, IEnumerable <Uri> graphUris)
 {
     Storage       = storage;
     Configuration = SpinDatasetDescription.Load(Storage, datasetUri, graphUris);
     Initialise();
 }