📄 rdfadmin.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.admin;import java.io.IOException;import java.io.InputStream;import java.io.Reader;import java.text.NumberFormat;import org.openrdf.model.Resource;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.sesame.constants.RDFFormat;import org.openrdf.sesame.repository.local.LocalService;import org.openrdf.sesame.sail.RdfRepository;import org.openrdf.sesame.sail.SailUpdateException;/** * The RdfAdmin module that can upload files to an RdfRepository and remove sets * of statements from it. **/public class RdfAdmin {/*--------------------------------------+| Variables |+--------------------------------------*/ private RdfRepository _rdfRepository; private LocalService _service; private NumberFormat _nf;/*--------------------------------------+| Constructors |+--------------------------------------*/ /** * Creates a new RdfAdmin that will use the supplied RdfRepository for * administrating the data. * * @exception IllegalArgumentException If the supplied rdfRepository is equal * to null. **/ public RdfAdmin(RdfRepository rdfRepository, LocalService service) { this(rdfRepository); _service = service; } public RdfAdmin(RdfRepository rdfRepository) { if (rdfRepository == null) { throw new IllegalArgumentException("rdfRepository must not be null"); } _rdfRepository = rdfRepository; _nf = NumberFormat.getInstance(); } /** * Reads and parses a XML-serialized RDF file from the supplied * InputStream and adds the triples to the RdfRepository of this RdfAdmin. * * @return the number of processed statements **/ public int addRdfModel(InputStream in, String baseURL, AdminListener report, boolean verifyData) throws IOException, UpdateException { return addRdfModel(in, baseURL, report, RDFFormat.RDFXML, verifyData); } /** * Reads and parses an RDF file from the supplied InputStream and adds * the triples to the RdfRepository of this RdfAdmin. * * @param in The InputStream containing the RDF data. * @param baseURL The base URL of the data for resolving any relative URIs. * @param report An AdminListener that will receive feedback about the * progress and of any errors in the data. * @param dataFormat Either RDFFormat.RDFXML if the RDF data is XML-encoded * RDF, or RDFFormat.NTRIPLES if the RDF data is in N-Triples format. * @param verifyData If set to 'true', the data will first be checked for * errors. This flag should only be set to false if the input is known for * sure to be correct. * @return The number of processed statements. **/ public int addRdfModel(InputStream in, String baseURL, AdminListener report, RDFFormat dataFormat, boolean verifyData) throws IOException, UpdateException { Upload upload = new SesameUpload(_rdfRepository, _service); return upload.addRdfModel(in, baseURL, report, dataFormat, verifyData); } /** * Reads and parses an RDF file from the supplied Reader and adds * the triples to the RdfRepository of this RdfAdmin. * * @param reader The Reader containing the RDF data. * @param baseURL The base URL of the data for resolving any relative URIs. * @param report An AdminListener that will receive feedback about the * progress and of any errors in the data. * @param dataFormat Either RDFFormat.RDFXML if the RDF data is XML-encoded * RDF, or RDFFormat.NTRIPLES if the RDF data is in N-Triples format. * @param verifyData If set to 'true', the data will first be checked for * errors. This flag should only be set to false if the input is known for * sure to be correct. * @return The number of processed statements. **/ public int addRdfModel(Reader reader, String baseURL, AdminListener report, RDFFormat dataFormat, boolean verifyData) throws IOException, UpdateException { Upload upload = new SesameUpload(_rdfRepository, _service); return upload.addRdfModel(reader, baseURL, report, dataFormat, verifyData); } /** * Removes statements matching pattern (subject, predicate, object). * * @param subject the subject of a statement, or null to indicate a * match with any resource. * @param predicate the predicate of a statement, or null to indicate a * match with any URI. * @param object the object of a statement, or null to indicate a * match with any value. **/ public void removeStatements(Resource subject, URI predicate, Value object, AdminListener report) throws UpdateException { try { report.transactionStart(); _rdfRepository.startTransaction(); int count = _rdfRepository.removeStatements(subject, predicate, object); _rdfRepository.commitTransaction(); report.notification("Removed " + count + " statements", -1, -1, null); report.transactionEnd(); } catch (SailUpdateException e) { //report.error("Unable to remove statements matching", subject, predicate, object); throw new UpdateException(e); } catch (Exception e) { throw new UpdateException(e); } } /** * Clears the repository of this RdfAdmin. * * @param report An <tt>AdminListener</tt> to report administrative message to. * @exception UpdateException If an error occured while clearing the repository. **/ public void clearRepository(AdminListener report) throws UpdateException { try { report.transactionStart(); _rdfRepository.startTransaction(); report.status("Clearing repository...", -1, -1); _rdfRepository.clearRepository(); _rdfRepository.commitTransaction(); report.status("Repository cleared", -1, -1); report.transactionEnd(); } catch (SailUpdateException e) { throw new UpdateException(e); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -