Beispiel #1
0
        /// <summary>
        /// Executes a query on the store which does not expect a result.
        /// </summary>
        /// <param name="update">SPARQL Update to be executed.</param>
        /// <param name="transaction">An optional transaction.</param>
        public override void ExecuteNonQuery(SparqlUpdate update, ITransaction transaction = null)
        {
            if (!_connector.UpdateSupported)
            {
                throw new Exception("This store does not support SPARQL update.");
            }

            string q = update.ToString();

            if (_stardogTransaction?.IsActive ?? false)
            {
                Log?.Invoke($"**{q}");

                var converter = new StardogUpdateSparqlConverter(this);
                converter.ParseQuery(q);

                Log?.Invoke($"UpdateGraph,{converter.Additions.Count},{converter.Removals.Count},{JsonConvert.SerializeObject(converter.Additions)},{JsonConvert.SerializeObject(converter.Removals)}");

                _stardogTransaction.AddTripleCount    += converter.Additions.Count;
                _stardogTransaction.RemoveTripleCount += converter.Removals.Count;

                _connector.UpdateGraph(converter.GraphUri, converter.Additions, converter.Removals);
            }
            else
            {
                // No transaction so just call update with the query
                Log?.Invoke(q);

                _connector.Update(q);
            }
        }
Beispiel #2
0
        public void TestLoad()
        {
            SparqlUpdate update = new SparqlUpdate(@"LOAD <http://gov.tso.co.uk/research/sparql> INTO <ex:TestModel>");

            _model.ExecuteUpdate(update);

            SparqlQuery query = new SparqlQuery(@"SELECT * WHERE { ?s ?p ?o . }");

            Assert.Greater(_model.ExecuteQuery(query).GetBindings().Count(), 0);
        }
        /// <summary>
        /// Executes a query on the store which does not expect a result.
        /// </summary>
        /// <param name="query">The update query</param>
        /// <param name="transaction">An associated transaction</param>
        public override void ExecuteNonQuery(SparqlUpdate query, ITransaction transaction = null)
        {
            string q = query.ToString();

            Log?.Invoke(q);

            SparqlUpdateCommandSet cmds = _parser.ParseFromString(q);

            _updateProcessor.ProcessCommandSet(cmds);
        }
        public void TestLoad()
        {
            Assert.Inconclusive();
            SparqlUpdate update = new SparqlUpdate(@"LOAD <http://eurostat.linked-statistics.org/sparql> INTO <ex:TestModel>");

            _model.ExecuteUpdate(update);

            SparqlQuery query = new SparqlQuery(@"SELECT * WHERE { ?s ?p ?o . }");

            Assert.Greater(_model.ExecuteQuery(query).GetBindings().Count(), 0);
        }
Beispiel #5
0
        public void TestInsert()
        {
            SparqlUpdate update = new SparqlUpdate(@"INSERT DATA INTO <ex:TestModel> { ex:book dc:title 'This is an example title' . }");

            _model.ExecuteUpdate(update);

            SparqlQuery query = new SparqlQuery(@"ASK WHERE { ?s dc:title 'This is an example title' . }");

            ISparqlQueryResult result = _model.ExecuteQuery(query);

            Assert.AreEqual(true, result.GetAnwser());
        }
Beispiel #6
0
        /// <summary>
        /// Removes model from the store.
        /// </summary>
        /// <param name="uri">Uri of the model which is to be removed.</param>
        public override void RemoveModel(Uri uri)
        {
            try
            {
                SparqlUpdate clear = new SparqlUpdate(string.Format("CLEAR GRAPH <{0}>", uri.AbsoluteUri));

                ExecuteNonQuery(clear);
            }
            catch (Exception)
            {
            }
        }
Beispiel #7
0
        public void TestClear()
        {
            SparqlUpdate update = new SparqlUpdate(@"INSERT DATA INTO <ex:TestModel> { ex:book dc:title 'This is an example title' . }");

            _model.ExecuteUpdate(update);

            update = new SparqlUpdate(@"CLEAR GRAPH <ex:TestModel>");

            _model.ExecuteUpdate(update);

            SparqlQuery query = new SparqlQuery(@"ASK WHERE { ?s dc:title 'This is an example title' . }");

            Assert.AreEqual(false, _model.ExecuteQuery(query).GetAnwser());
        }
Beispiel #8
0
        public void TestUpdateParameters()
        {
            SparqlUpdate update = new SparqlUpdate(@"
                DELETE { ?s ?p @oldValue . }
                INSERT { ?s ?p @newValue . }
                WHERE { ?s ?p ?o . }");

            update.Bind("@oldValue", "Fail");
            update.Bind("@newValue", "Success");

            string updateString = update.ToString();

            Assert.IsFalse(string.IsNullOrEmpty(updateString));

            _model.ExecuteUpdate(update);
        }
Beispiel #9
0
 public void RemoveModel(Uri uri)
 {
     using (ITransaction transaction = this.BeginTransaction(IsolationLevel.ReadCommitted))
     {
         try
         {
             SparqlUpdate update = new SparqlUpdate(string.Format("CLEAR GRAPH <{0}>", uri.AbsoluteUri));
             ExecuteNonQuery(update, transaction);
             update = new SparqlUpdate(string.Format("DROP GRAPH <{0}>", uri.AbsoluteUri));
             ExecuteNonQuery(update, transaction);
             transaction.Commit();
         }
         catch (Exception)
         {
         }
     }
 }
Beispiel #10
0
        public void TestModify()
        {
            SparqlUpdate update = new SparqlUpdate(@"
                INSERT DATA INTO <ex:TestModel> { ex:book dc:title 'This is an example title' . }");

            _model.ExecuteUpdate(update);

            update = new SparqlUpdate(@"
                DELETE DATA FROM <ex:TestModel> { ex:book dc:title 'This is an example title' . }
                INSERT DATA INTO <ex:TestModel> { ex:book dc:title 'This is an example title too' . }");

            _model.ExecuteUpdate(update);

            SparqlQuery query = new SparqlQuery(@"
                ASK WHERE { ?s dc:title 'This is an example title' . }");

            Assert.AreEqual(false, _model.ExecuteQuery(query).GetAnwser());

            query = new SparqlQuery(@"
                ASK WHERE { ?s dc:title 'This is an example title too' . }");

            Assert.AreEqual(true, _model.ExecuteQuery(query).GetAnwser());
        }
 public void ExecuteNonQuery(SparqlUpdate queryString, ITransaction transaction = null)
 {
     return;
 }
Beispiel #12
0
        public override void ExecuteNonQuery(SparqlUpdate query, ITransaction transaction = null)
        {
            string queryString = string.Format("SPARQL {0}", query.ToString());

            ExecuteDirectQuery(queryString, transaction);
        }
Beispiel #13
0
        public void ExecuteNonQuery(SparqlUpdate query, ITransaction transaction = null)
        {
            SparqlUpdateCommandSet cmds = _parser.ParseFromString(query.ToString());

            _updateProcessor.ProcessCommandSet(cmds);
        }