Andy, Rob,

Thanks for the responses.
I'm using Jena 2.11.2 (same version for both TDB and ARQ).

Below are the relevant pieces of code.

Code to delete a graph:

    public boolean deleteGraph(String datasetID, String graphName) {
        if (!graphName.contentEquals(FusekiConfig.DEFAULT_GRAPH_NAME)) {
            if (!graphExists(datasetID, graphName)) {
                log.debug("[FusekiProxy] deleteGraph() - graph not found");
                return false;
            }
        }
        String directory = DBpath.concat("/" + datasetID);
        Dataset dataset = TDBFactory.createDataset(directory);
        dataset.begin(ReadWrite.WRITE);
        try {
            if (graphName.contentEquals(FusekiConfig.DEFAULT_GRAPH_NAME)) {
                // special handling for default graph: we replace it with an 
empty graph
                dataset.getDefaultModel().removeAll();
            } else {
                dataset.removeNamedModel(graphName);
            }
        } catch(Exception ex) {
            log.error("[FusekiProxy] deleteGraph() - " + ex.toString());
            return false;
        } finally {
            dataset.commit();
            dataset.end();
            return true;
        }
    }

Code to retrieve a graph:

    public String getGraph(String datasetID, String graphName, String format) {
        String directory = DBpath.concat("/" + datasetID);
        Dataset dataset = TDBFactory.createDataset(directory);

        Model model = null;
        OutputStream out = new ByteArrayOutputStream();
        try {
            dataset.begin(ReadWrite.READ);
            if (!graphName.contentEquals(FusekiConfig.DEFAULT_GRAPH_NAME))
                model = dataset.getNamedModel(graphName);
            else
                model = dataset.getDefaultModel();
            if (model == null) {
                return null;
            }
            // Converting retrieved graph to desired format.
                /.../
        } catch(Exception ex) {
            log.error("[FusekiProxy getGraph() -  " + ex.toString());
            return null;
        } finally {
            dataset.end();
        }
        return out.toString();
    }

As explained in the previous email, when testing the 2 methods above, I could 
successfully retrieve a deleted graph (empty).
Following your explanation I added a test to verify that the graph exists in 
the getGraph() method.
I now see a correct behaviour. Thanks :)

I see your point about not adding graph management at the dataset level.
I was just mislead by the name removeNamedModel().
I'd recommend adding some explanation in the Javadoc so people don't make the 
same assumption.

Thanks a lot,
Hubert


On Aug 23, 2014, at 1:42 AM, Andy Seaborne <[email protected]> wrote:

> Hubert,
> 
> A complete, minimal example makes it much easier to answer questions or fix 
> bugs.
> 
> In TDB, getNamedModel will always return a Model.  You can check whether it 
> current exists with containsNamedModel.
> 
> TDB does not track empty graphs - it just has a set of quads and a set of 
> triples.
> 
> containsNamedModel => there is at least one quad with the G field begin the 
> URI given.
> 
>        Dataset ds = TDBFactory.createDataset() ;
>        boolean b = ds.containsNamedModel("http://example/";) ;
>        System.out.println("contains: "+b) ;
>        Model m = ds.getNamedModel("http://example/";) ;
>        System.out.println("Is model null?: "+(m==null)) ;
> 
> Adding management of graph names would be quite a burden, impacting 
> efficiency as well as complicating many application tasks.
> 
> The general purpose dataset performs the role of being able to incorporate 
> any model from any storage system.  Adding a model is like adding to a map 
> (in fact it is adding to a map!). TDB doesn't do that; adding a model is a 
> copy into TDB storage.
> 
>       Andy
> 
> On 23/08/14 05:01, Rob Vesse wrote:
>> Hubert
>> 
>> Please show your actual code otherwise we can't tell what (if anything)
>> you might be doing wrong
>> 
>> Also versions matter, what versions of ARQ and TDB are you using?
>> 
>> Rob
>> 
>> On 22/08/2014 16:52, "Hubert A Le Van Gong" <[email protected]> wrote:
>> 
>>> Hello,
>>> 
>>> For some reason I just can't seem to be able to completely delete a named
>>> model from a dataset...
>>> 
>>> I initially thought of simply using removeNamedModel() - didn't work
>>> (model & statements still available).
>>> 
>>> I've searched the mailing list and found a similar (old) thread where it
>>> was recommended to do
>>> a removeAll() which I did. This effectively empties the model but a
>>> getNamedModel() will return
>>> the Model (albeit empty).
>>> I even tried to do both removeAll() followed by a removeNameModel() but
>>> no success.
>>> 
>>> In case it makes a difference, I'm using TDB.
>>> 
>>> What am I doing wrong?
> 
>       Andy
> 
>>> 
>>> Cheers,
>>> Hubert
>>> 
>> 
>> 
>> 
>> 
> 

Reply via email to