Project

General

Profile

« Previous | Next » 

Revision ed6fc7fb

Added by Andreas Kohlbecker over 8 years ago

increasing efficiency by caching remote models per request

View differences:

src/main/java/org/bgbm/biovel/drf/query/SparqlClient.java
31 31
import org.apache.jena.rdf.model.ResIterator;
32 32
import org.apache.jena.rdf.model.Resource;
33 33
import org.apache.jena.rdf.model.StmtIterator;
34
import org.apache.jena.riot.RDFDataMgr;
35
import org.apache.jena.riot.RDFFormat;
34 36
import org.bgbm.biovel.drf.checklist.DRFChecklistException;
35 37
import org.bgbm.biovel.drf.checklist.EEA_BDC_Client.RdfSchema;
36 38
import org.bgbm.biovel.drf.store.TripleStore;
......
57 59
    /**
58 60
     * A model for caching
59 61
     */
60
    private final Model cache = null;
62
    private Model cache = null;
61 63

  
62 64

  
63 65
    /**
64
     *
66
     * SparqlClient will use an internal cache
65 67
     */
66 68
    public SparqlClient(String baseUri) {
67 69
        this.baseUri = baseUri;
70
        this.cache = ModelFactory.createDefaultModel();
68 71
    }
69 72

  
70 73
    /**
......
330 333
        }
331 334
    }
332 335

  
336
    /**
337
     * @param matchedResourceURI
338
     * @return
339
     * @throws DRFChecklistException
340
     */
341
    public Resource getFromUri(URI matchedResourceURI) {
342
        return getFromUri(matchedResourceURI.toString());
343
    }
344

  
333 345
    public Resource getFromUri(String uri) {
334 346

  
335 347
        Model model;
......
339 351
            model = dataset.getDefaultModel();
340 352
            dataset.end();
341 353
        } else {
354
            model = cache;
342 355
            // FIXME the same uri resource is loaded from remote multiple times
343 356
            //       create an in memory model as cache for the models loaded
344 357
            //       in the getFromUri
345 358
            //       so that all resources loaded are put into that model
346 359
            //       clean up the cache when it reaches a specific size
347 360
            logger.debug("loading remote UriResource " + uri);
348
            model = ModelFactory.createDefaultModel();
349 361
            model.read(uri);
350 362
        }
351 363
        if(logger.isDebugEnabled()) {
352
            model.write(System.err);
364
            // see https://jena.apache.org/documentation/io/rdf-output.html#examples
365
            RDFDataMgr.write(System.err, model, RDFFormat.TURTLE_PRETTY);
353 366
        }
354 367
        return model.getResource(uri);
355 368

  
356 369
    }
357 370

  
358
    /**
359
     * @param matchedResourceURI
360
     * @return
361
     * @throws DRFChecklistException
362
     */
363
    public Resource getFromUri(URI matchedResourceURI) {
364
        return getFromUri(matchedResourceURI.toString());
365
    }
366 371

  
367 372

  
368 373
}

Also available in: Unified diff