You could look at the jena permissinos layer.  Using that you can make the
underlying Model read only.  If you want to make the OntModel read only I
think you could create the OntDocumentManager and get the Model and wrap it
with the permissions layer and then put it back in the OntDocumentManager.
I think that it is possible to make it read only this way.

{code}
OntDocumentManager odm = OntDocumentManager.getInstance();
OntModel ontModel =odm.getOntology(ontologyURI,ontModelSpec);
SecuredModel wrappedMode = org.apache.jena.permissions.factory(
securityEvaluator, ontologyURI, ontModel.getModel() )
odm.setModel( ontologyURI, wrappedModel );
// now
OntModel ontModel =.getOntology(ontologyURI, ontModelSpec);
// should return a permissions restricted ontology model.
{code}

You will need to create a simple SecurityEvaluator that denies create,
update and delete on the ontologyURI model.


If this doesn't work it should be fairly simple to extend the permissions
package to include the ontology package.

Claude

On Mon, Oct 17, 2016 at 8:37 PM, Martynas Jusevičius <marty...@graphity.org>
wrote:

> This is Jena 3.0.1 by the way.
>
> On Mon, Oct 17, 2016 at 9:36 PM, Martynas Jusevičius
> <marty...@graphity.org> wrote:
> > Hey,
> >
> > I am looking for a way to either
> > a) clone an OntModel in a performant way
> > b) make OntModel instance in OntDocumentManager read-only
> >
> > The use case goes like this: JAX-RS retrieves an OntModel instance
> > from OntModel manager per each request, adds to it or changes it, and
> > discards it after the request.
> >
> > We cannot directly change the OntModel instance in OntDocumentManager,
> > because that would pollute it with changes from each request and the
> > size would grow very quickly.
> >
> > So I went for the easy way out and cloned the OntModel on each
> > request, like this:
> >
> >         OntModel ontModel =
> > OntDocumentManager.getInstance().getOntology(ontologyURI,
> > ontModelSpec);
> >
> >         // lock and clone the model to avoid
> ConcurrentModificationExceptions
> >         ontModel.enterCriticalSection(Lock.READ);
> >         try
> >         {
> >             Model baseModel =
> > ModelFactory.createDefaultModel().add(ontModel.getBaseModel());
> >             OntModel clonedModel =
> > ModelFactory.createOntologyModel(ontModelSpec, baseModel);
> >             if (log.isDebugEnabled()) log.debug("Sitemap model size:
> > {}", clonedModel.size());
> >             return clonedModel;
> >         }
> >         finally
> >         {
> >             ontModel.leaveCriticalSection();
> >         }
> >
> > That works, but the problem is that cloning using add() performs very
> > poorly. According to my profiling, this code takes almost a second to
> > execute with under 6000 statements, spent mostly in hasNext() of
> > various iterators.
> >
> > Not sure if it's relevant, but the OntModelSpec uses GenericRuleReasoner.
> >
> > Is there a faster way or can you maybe suggest a different approach
> altogether?
> >
> > Thanks.
> >
> >
> > Martynas
>



-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Reply via email to