Thanks Barry, yes, that solved the problem!
On 30 April 2013 12:06, Barry Norton <barry.nor...@ontotext.com> wrote: > > Danica, I'm not sure if it explains your problem, but you're not closing > all your objects: > > http://trippi.sourceforge.net/api/org/trippi/impl/sesame/SesameTupleIterator.html#close() > > Barry > > > > On 30/04/2013 12:01, Danica Damljanovic wrote: > > Hi all > > Just struggling with: > "Unable to start transaction: data file is locked or read-only" > > which seems to disappear as soon as I manually delete my 'repositories' > dir. > > It seems that we are somehow not closing the connection or repository > properly, but in the code if you look below we actually do. > > Any hints much appreciated! > > I also attach our owim.ttl file (and the Java class which includes the > code below). > > Mac OS X, OWLIM Lite 5.1 > > > private void createAndInitialiseLocalRepository() { > > > // Parse the configuration file, assuming it is in Turtle format > > Graph repositoryRdfDescription = null; > > > File configFile = null; > > > try { > > ResourcePatternResolver resolver = > newPathMatchingResourcePatternResolver(); > > Resource[] resources = resolver.getResources(config); > > > > > > //configFile = (File) config.getFile(); > > configFile = (File) resources[0].getFile(); > > log.info("Using configuration file: " + > configFile.getAbsolutePath()); > > repositoryRdfDescription = parseFile(configFile, RDFFormat. > TURTLE, "http://gate.ac.uk/ns/gate-kb#"); > > log.info("Done reading config: " + > configFile.getAbsolutePath()); > > } catch (OpenRDFException e) { > > log.info("There was an error reading/parsing the Turtle > configuration file '" + config > > + "': " + e.getMessage()); > > } catch (FileNotFoundException e) { > > log.info("The turtle configuration file '" + config > > + "' was not found, please check the '" + "' > parameter"); > > } catch (IOException e) { > > log.info("An I/O error occurred while processing the > configuration file '" + config > > + "': " + e.getMessage()); > > } > > > if (repositoryRdfDescription == null) { > > throw new RuntimeException("Failed to create > repositoryRdfDescription"); > > } > > > // Look for the subject of the first matching statement for > > // "?s type Repository" > > final String repositoryUri = " > http://www.openrdf.org/config/repository#Repository"; > > final String repositoryIdUri = " > http://www.openrdf.org/config/repository#repositoryID"; > > Iterator<Statement> iter = > > repositoryRdfDescription.match(null, RDF.TYPE, > newURIImpl(repositoryUri)); > > org.openrdf.model.Resource repositoryNode = null; > > if (iter.hasNext()) { > > Statement st = iter.next(); > > repositoryNode = st.getSubject(); > > } > > if (repositoryNode == null) { > > String msg = "The turtle configuration file '" > > + configFile.getName() > > + "' does not contain a valid repository > description, because it is missing a resource with rdf:type <" > > + repositoryUri + ">"; > > log.info(msg); > > throw new RuntimeException(msg); > > } > > > // Get the repository ID (and ignore the one passed with the > > // 'repository' parameter > > iter = repositoryRdfDescription.match(repositoryNode, > newURIImpl(repositoryIdUri), > null); > > if (iter.hasNext()) { > > Statement st = iter.next(); > > repositoryId = st.getObject().stringValue(); > > } else { > > String msg = "The turtle configuration file '" > > + configFile.getName() > > + "' does not contain a valid repository > description, because it is missing a <" > > + repositoryUri + "> with a property <" + > repositoryIdUri + ">"; > > log.info(msg); > > throw new RuntimeException(msg); > > } > > > try { > > // Create a manager for local repositories and initialise it > > repositoryManager = new LocalRepositoryManager(new File( > localRepositoryManagerDir)); > > repositoryManager.initialize(); > > } catch (RepositoryException e) { > > log.info(e.getMessage()); > > throw new RuntimeException(e); > > } > > > try { > > // Create a configuration object from the configuration file > and > > // add it to the repositoryManager > > RepositoryConfig repositoryConfig = > RepositoryConfig.create(repositoryRdfDescription, repositoryNode); > > repositoryManager.addRepositoryConfig(repositoryConfig); > > > > } catch (OpenRDFException e) { > > String msg = "Unable to process the repository configuration: > " + e.getMessage(); > > log.info(msg); > > throw new RuntimeException(msg); > > } > > > } > > > @PostConstruct > > public void afterPropertiesSet() throws Exception { > > if (repositoryURL != null && !"".equals(repositoryURL)) { > > if (username != null && password != null) { > > rep = new HTTPRepository(repositoryURL, repositoryId); > > ((HTTPRepository) rep).setUsernameAndPassword(username, > password); > > } else { > > throw new Exception("Not valid username & password for > the http repository"); > > } > > loaded = true; > > } else { > > // construct local repository > > // rep = new SailRepository(new MemoryStore()); > > createAndInitialiseLocalRepository(); > > rep = repositoryManager.getRepository("owlim"); // TODOshould be > repositoryId ?? > > loaded = false; > > } > > try { > > rep.initialize(); > > log.info("Successfully connected to the Sesame Repository > using impl: " > > + rep.getClass().getName()); > > connection = rep.getConnection(); > > if (connection != null) { > > log.debug("Connection established"); > > } > > > if (loaded) { > > populateCache(); > > } > > > } catch (final RepositoryException e) { > > log.info("Not being able to connect to the HTTPRepository:" + > repositoryURL + "|" > > + repositoryId); > > e.printStackTrace(); > > } > > > } > > > @PreDestroy > > public void destroy() throws Exception { > > rep.shutDown(); > > repositoryManager.shutDown(); > > connection.close(); > > } > > public void loadResources(Resource[] resources) throwsRDFParseException, > RepositoryException, > > IOException { > > int numberOfFilesToLoad = resources.length; > > int currentFileNumber = 1; > > for (Resource resource : resources) { > > String uri = resource.getURI().toString(); > > String ext = uri.substring(uri.lastIndexOf('.') + 1); > > RDFFormat format = null; > > boolean skip = false; > > if ("owl".equalsIgnoreCase(ext) || "rdf".equalsIgnoreCase(ext) > > || "rdfs".equalsIgnoreCase(ext)) { > > format = RDFFormat.RDFXML; > > } else if ("nt".equalsIgnoreCase(ext)) { > > format = RDFFormat.NTRIPLES; > > } else if ("n3".equalsIgnoreCase(ext)) { > > format = RDFFormat.N3; > > } else if ("ttl".equalsIgnoreCase(ext)) { > > format = RDFFormat.TURTLE; > > } else { > > log.info("Skipping uri:" + uri); > > skip = true; > > } > > if (!skip) { > > assert format != null : ext; > > log.info("Started loading " + uri + "(" + > currentFileNumber + "/" > > + numberOfFilesToLoad + ")"); > > try { > > > connection.add(resource.getInputStream(), " > http://example.org#", format); > > log.info(uri + " loaded."); > > } catch (Exception e) { > > log.info("There was a problem with this uri, uri not > loaded:" + uri + "\n" > > + e.getMessage()); > > e.printStackTrace(); > > } > > > } > > currentFileNumber++; > > > } > > } > > > public int loadData() throws Exception { > > // File ontologyDir = preloadDir.getFile(); > > // log.debug("Loading from: " + preloadDir.getFilename()); > > ResourcePatternResolver resolver = > newPathMatchingResourcePatternResolver(); > > Resource[] resources = resolver.getResources(ontologyLoadPattern); > > loadResources(resources); > > return populateCache(); > > } > > > > > /** > > * Parse the given RDF file and return the contents as a Graph > > * > > * @param configurationFile The file containing the RDF data > > * @return The contents of the file as an RDF graph > > * @throws RDFHandlerException > > * @throws RDFParseException > > * @throws IOException > > */ > > private Graph parseFile(File configurationFile, RDFFormat format, > String defaultNamespace) > > throws RDFParseException, RDFHandlerException, > IOException { > > Reader reader = new FileReader(configurationFile); > > > final Graph graph = new GraphImpl(); > > RDFParser parser = Rio.createParser(format); > > RDFHandler handler = new RDFHandler() { > > @Override > > public void endRDF() throws RDFHandlerException {} > > > @Override > > public void handleComment(String arg0) throwsRDFHandlerException > {} > > > @Override > > public void handleNamespace(String arg0, String arg1) > throwsRDFHandlerException {} > > > @Override > > public void handleStatement(Statement statement) > throwsRDFHandlerException { > > graph.add(statement); > > } > > > @Override > > public void startRDF() throws RDFHandlerException {} > > }; > > parser.setRDFHandler(handler); > > parser.parse(reader, defaultNamespace); > > return graph; > > } > > > Thanks > Danica > > > _______________________________________________ > Owlim-discussion mailing > listOwlim-discussion@ontotext.comhttp://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion > > > > _______________________________________________ > Owlim-discussion mailing list > Owlim-discussion@ontotext.com > http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion > >
_______________________________________________ Owlim-discussion mailing list Owlim-discussion@ontotext.com http://ontomail.semdata.org/cgi-bin/mailman/listinfo/owlim-discussion