On 09/05/13 17:00, David Jordan wrote:
The class Database is my little utility class that hide whether I am using TDB 
or SDB.
For the TDB case, the only code that executes is
return TDBFactory.assembleDataset(TDB_ASSEMBLER_FILE);

And the assembler file?

(All these details may matter or may not - but it's easier for me to start from something that illustrates the problem - anything else is guessing and risks not guessing the right details)

Or does it illustrate the same situation with TDFFactory.createDataset?

        Andy


Right now I have a long running program that needs to finish, but I am fairly 
confident that when I ran this the database had the two named models stored in 
the database. So the model name was already being used in the database. I'll 
verify this and get back to you.


-----Original Message-----
From: Andy Seaborne [mailto:[email protected]]
Sent: Thursday, May 09, 2013 11:54 AM
To: [email protected]
Subject: Re: TDBException: Allocation attempt on NodeTableReadonly

                String modelName = args[0];
                Dataset dataset = Database.getDataset();

(Database.getDataset()??)

David -

Is the database empyy to start with?
Is the model name previously unused?

        Andy




On 09/05/13 15:16, David Jordan wrote:

Andy,
I have included the complete program below. My code seems to be read only. It 
works with a model stored in non-inferenced form. But I have another model that 
I have pre-inferenced and stored, pre-inferenced using OWL_MEM_MICRO_RULE_INF 
(if that is relevant). In this second case, I get this exception when I call 
createOntologyModel.

So there are only two lines in the transaction before I get the
exception TDBException: Allocation attempt on NodeTableReadonly Model
model = dataset.getNamedModel(modelName); OntModel omodel =
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model); The variable 
omodel is a transient model. Does passing the stored model referenced by the 
variable model try to perform an update, in particular in the case where that 
model has been pre-inferenced?


import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.ReadWrite; import
com.hp.hpl.jena.rdf.model.Model; import
com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class ListClassesAndNumInstances {
        public static void main(String[] args) {
                String modelName = args[0];
                Dataset dataset = Database.getDataset();
                try {
                        dataset.begin(ReadWrite.READ);
                        Model model = dataset.getNamedModel(modelName);
                        OntModel omodel = 
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
                        ExtendedIterator<OntClass> classes = 
omodel.listClasses();
                        int totalClasses = 0;
                        int totalInstances = 0;
                        while( classes.hasNext() ){
                                OntClass oclass = classes.next();
                                totalClasses++;
                                String cname = oclass.getURI();
                                int cnt = 0;
                                ExtendedIterator<OntResource> instances = 
(ExtendedIterator<OntResource>) oclass.listInstances();
                                while( instances.hasNext() ){
                                        OntResource resource = instances.next();
                                        cnt++;
                                }
                                totalInstances += cnt;
                                System.out.print(cname);
                                System.out.print(",");
                                System.out.println(cnt);
                        }
                        System.out.print("Total classes: ");
                        System.out.println(totalClasses);
                        System.out.print("Total instances: ");
                        System.out.println(totalInstances);
                } finally {
                        dataset.end();
                }
        }
}


-----Original Message-----
From: Andy Seaborne [mailto:[email protected]]
Sent: Thursday, May 09, 2013 5:14 AM
To: [email protected]
Subject: Re: TDBException: Allocation attempt on NodeTableReadonly

On 08/05/13 21:02, David Jordan wrote:

What is the typical cause for the following exception?

Some kind of write action inside a read transaction.  Read transactions really are 
"read only" and it's enforced.

Here, it looks like it's the setNsPrefix of a prefix. That's fine if the profix 
already exists  so it does not in this case.

Do you have a complete, minimal example?  TDBFactory has a method to make an in-memory 
dataset that behaves exactly liek a disk-backed one (it uses a crude "RAM 
disk").  Good for testing and portable examples.

        Andy

       [java] Exception in thread "main" com.hp.hpl.jena.tdb.TDBException: 
Allocation attempt on NodeTableReadonly
       [java]     at 
com.hp.hpl.jena.tdb.nodetable.NodeTableReadonly.getAllocateNodeId(NodeTableReadonly.java:37)
       [java]     at 
com.hp.hpl.jena.tdb.nodetable.NodeTupleTableConcrete.addRow(NodeTupleTableConcrete.java:84)
       [java]     at 
com.hp.hpl.jena.tdb.store.DatasetPrefixesTDB.insertPrefix(DatasetPrefixesTDB.java:122)
       [java]     at 
com.hp.hpl.jena.sparql.graph.GraphPrefixesProjection.set(GraphPrefixesProjection.java:84)
       [java]     at 
com.hp.hpl.jena.shared.impl.PrefixMappingImpl.setNsPrefix(PrefixMappingImpl.java:70)
       [java]     at 
com.hp.hpl.jena.graph.compose.PolyadicPrefixMappingImpl.setNsPrefix(PolyadicPrefixMappingImpl.java:52)
       [java]     at 
com.hp.hpl.jena.rdf.model.impl.ModelCom.setNsPrefix(ModelCom.java:975)
       [java]     at 
com.hp.hpl.jena.ontology.impl.OntModelImpl.<init>(OntModelImpl.java:159)
       [java]     at 
com.hp.hpl.jena.ontology.impl.OntModelImpl.<init>(OntModelImpl.java:123)
       [java]     at 
com.hp.hpl.jena.rdf.model.ModelFactory.createOntologyModel(ModelFactory.java:370)
       [java]     at 
com.sas.ta.om.ListClassesAndNumInstances.main(ListClassesAndNumInstances.java:26)

David Jordan
Senior Software Developer
SAS Institute Inc.
Health & Life Sciences, Research & Development Bldg R ▪ Office 4467
600 Research Drive ▪ Cary, NC 27513
Tel: 919 531 1233 ▪ [email protected]<mailto:[email protected]>
www.sas.com<http://www.sas.com/>
SAS® … THE POWER TO KNOW®






Reply via email to