當前位置: 首頁>>代碼示例>>Java>>正文


Java RepositoryConnection.close方法代碼示例

本文整理匯總了Java中org.openrdf.repository.RepositoryConnection.close方法的典型用法代碼示例。如果您正苦於以下問題:Java RepositoryConnection.close方法的具體用法?Java RepositoryConnection.close怎麽用?Java RepositoryConnection.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openrdf.repository.RepositoryConnection的用法示例。


在下文中一共展示了RepositoryConnection.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDistinctObj

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Get total number of distinct objects for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static long getDistinctObj(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objs) " + // 
			"WHERE " +
			"{" +
       		"?s <" + pred + "> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objs").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例2: testUpdateDate2

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
@Test
public void testUpdateDate2() throws Exception {
	Repository repo = new SailRepository( new MemoryStore() );
	repo.initialize();
	RepositoryConnection rc = repo.getConnection();
	
	URI base = Utility.getUniqueUri();
	Date now = new Date();
	rc.add( new StatementImpl( base, MetadataConstants.DCT_MODIFIED,
			rc.getValueFactory().createLiteral( now ) ) );

	AbstractSesameEngine.updateLastModifiedDate( rc, null );

	List<Statement> stmts = Iterations.asList( eng.getRawConnection().
			getStatements( eng.getBaseUri(), MetadataConstants.DCT_MODIFIED,
					null, false ) );
	Literal val = Literal.class.cast( stmts.get( 0 ).getObject() );
	Date upd = getDate( val.calendarValue() );

	rc.close();
	repo.shutDown();

	// the 100 is to remove the ms, which aren't always the same because
	// they're not stored in the RDF
	assertEquals( now.getTime(), upd.getTime(), 100 );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:27,代碼來源:InMemorySesameEngineTest.java

示例3: getSubjectCount

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Get total number of distinct subjects of a dataset
 * @return count 
 */
public static long getSubjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?s) AS ?sbjts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("sbjts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例4: getObjectCount

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Get total number of distinct objects of a dataset
 * @return count
 */
public static long getObjectCount(String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(DISTINCT ?o) AS ?objts) " + // 
			"WHERE " +
			"{" +
       		"?s ?p ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("objts").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:23,代碼來源:SemagrowSummariesGenerator.java

示例5: getTripleCount

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Get total number of triple for a predicate
 * @param pred Predicate
 * @param m model
 * @return triples
 */
public static Long getTripleCount(String pred, String endpoint) throws Exception {
	String strQuery = "SELECT  (COUNT(?s) AS ?triples) " + // 
			"WHERE " +
			"{" +
       		"?s <"+pred+"> ?o " +
       		"} " ;
	SPARQLRepository repo = new SPARQLRepository(endpoint);
	repo.initialize();
	RepositoryConnection conn = repo.getConnection();
	try {
		TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, strQuery); 
		TupleQueryResult rs = query.evaluate();
		return Long.parseLong(rs.next().getValue("triples").stringValue());
	} finally {
		conn.close();
		repo.shutDown();
	}
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:25,代碼來源:SemagrowSummariesGenerator.java

示例6: Literal

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Literal factory
 * 
 * @param s
 *            the literal value
 * @param typeuri
 *            uri representing the type (generally xsd)
 * @return
 */
public org.openrdf.model.Literal Literal(String s, URI typeuri) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			ValueFactory vf = con.getValueFactory();
			if (typeuri == null) {
				return vf.createLiteral(s);
			} else {
				return vf.createLiteral(s, typeuri);
			}
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:28,代碼來源:SimpleGraph.java

示例7: tuplePattern

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Tuple pattern query - find all statements with the pattern, where null is
 * a wild card
 * 
 * @param s
 *            subject (null for wildcard)
 * @param p
 *            predicate (null for wildcard)
 * @param o
 *            object (null for wildcard)
 * @return serialized graph of results
 */
public List tuplePattern(URI s, URI p, Value o) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			RepositoryResult repres = con.getStatements(s, p, o, true, new Resource[0]);
			ArrayList reslist = new ArrayList();
			while (repres.hasNext()) {
				reslist.add(repres.next());
			}
			return reslist;
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:31,代碼來源:SimpleGraph.java

示例8: runSPARQL

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Execute a CONSTRUCT/DESCRIBE SPARQL query against the graph
 * 
 * @param qs
 *            CONSTRUCT or DESCRIBE SPARQL query
 * @param format
 *            the serialization format for the returned graph
 * @return serialized graph of results
 */
public String runSPARQL(String qs, RDFFormat format) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			GraphQuery query = con.prepareGraphQuery(org.openrdf.query.QueryLanguage.SPARQL, qs);
			StringWriter stringout = new StringWriter();
			RDFWriter w = Rio.createWriter(format, stringout);
			query.evaluate(w);
			return stringout.toString();
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:27,代碼來源:SimpleGraph.java

示例9: close

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Closes a repository connection if it is open. Does nothing if it is
 * already closed.
 *
 * @param conn the connection to close
 * @throws WebApplicationException if there was a problem while closing the
 * connection
 */
protected void close(RepositoryConnection conn) {
	if (conn != null) {
		try {
			if (conn.isOpen()) {
				conn.close();
			}
		} catch (RepositoryException ex) {
			throw new WebApplicationException(ex);
		}
	}
}
 
開發者ID:lszeremeta,項目名稱:neo4j-sparql-extension-yars,代碼行數:20,代碼來源:AbstractSailResource.java

示例10: close

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Closes a connection if it is open.
 * 
 * This method is intended to close a connection after an exception
 * occured. Any occuring exceptions while closing will be added as
 * suppressed exceptions to the given exception.
 * @param conn the connection that should be closed
 * @param ex an exception that caused the closing
 */
protected void close(RepositoryConnection conn, Exception ex) {
	if (conn != null) {
		try {
			if (conn.isOpen()) {
				conn.close();
			}
			Repository rep = conn.getRepository();
		} catch (RepositoryException ex2) {
			ex.addSuppressed(ex2);
		}
	}
}
 
開發者ID:lszeremeta,項目名稱:neo4j-sparql-extension-yars,代碼行數:22,代碼來源:AbstractStreamingOutput.java

示例11: getExpectedGraph

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
private static Model getExpectedGraph( File rdf ) {
	SailRepository repo = new SailRepository( new MemoryStore() );
	RepositoryConnection expectedrc = null;
	List<Statement> stmts = new ArrayList<>();
	try {
		repo.initialize();
		expectedrc = repo.getConnection();
		expectedrc.add( rdf, null, RDFFormat.TURTLE );
		stmts.addAll( Iterations.asList( expectedrc.getStatements( null, null,
				null, true ) ) );
	}
	catch ( RepositoryException | IOException | RDFParseException e ) {
	}
	finally {
		if ( null != expectedrc ) {
			try {
				expectedrc.close();
			}
			catch ( Exception ex ) {
				// don't care
			}

			try {
				repo.shutDown();
			}
			catch ( Exception exc ) {
				// don't care
			}
		}
	}

	return new LinkedHashModel( stmts );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:34,代碼來源:AbstractEdgeModelerTest.java

示例12: evaluate

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
public List<List<Object>> evaluate(String queries) throws Exception {
	List<List<Object>> report = new ArrayList<List<Object>>();
			
	List<String> qnames = Arrays.asList(queries.split(" "));
	for (String curQueryName : qnames)
	{
		List<Object> reportRow = new ArrayList<Object>();
		report.add(reportRow);
		String curQuery = qp.getQuery(curQueryName);
		reportRow.add(curQueryName);
		
		long startTime = System.currentTimeMillis();
		//ParsedOperation pO = QueryParserUtil.parseOperation(QueryLanguage.SPARQL, curQuery, null);
		RepositoryConnection repCon = this.repository.getConnection();
		try {
			Query tempq = repCon.prepareQuery(QueryLanguage.SPARQL, curQuery);
			TupleQuery q = (TupleQuery)tempq;
			
			SyncTupleQueryResultHandler rhandler = new SyncTupleQueryResultHandler();
            q.evaluate(rhandler);
            		
		    long runTime = System.currentTimeMillis() - startTime;
		    reportRow.add((Long)rhandler.resultCount); reportRow.add((Long)runTime);

		    log.info(curQueryName + ": Query exection time (msec): "+ runTime + ", Total Number of Records: " + rhandler.resultCount);
		} catch (Exception e) {
			reportRow.add(null); reportRow.add(null);
		} finally {
			repCon.close();
        }
	}
	return report;
}
 
開發者ID:dice-group,項目名稱:CostFed,代碼行數:34,代碼來源:QueryEvaluation.java

示例13: testCreateFromRepository

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
@Test
public void testCreateFromRepository() throws Exception {
	Repository repo = new SailRepository( new MemoryStore() );
	repo.initialize();
	RepositoryConnection rc = repo.getConnection();
	rc.add( SRCFILE, null, RDFFormat.TURTLE );
	rc.commit();
	rc.close();

	InsightManager imi = InsightManagerImpl.createFromRepository( repo );
	repo.shutDown();

	assertEquals( 1, imi.getPerspectives().size() );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:15,代碼來源:InsightManagerImplTest.java

示例14: dumpRDF

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * dump RDF graph
 * 
 * @param out
 *            output stream for the serialization
 * @param outform
 *            the RDF serialization format for the dump
 * @return
 */
public void dumpRDF(OutputStream out, RDFFormat outform) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			RDFWriter w = Rio.createWriter(outform, out);
			con.export(w, new Resource[0]);
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:23,代碼來源:SimpleGraph.java

示例15: addURI

import org.openrdf.repository.RepositoryConnection; //導入方法依賴的package包/類
/**
 * Import data from URI source Request is made with proper HTTP ACCEPT
 * header and will follow redirects for proper LOD source negotiation
 * 
 * @param urlstring
 *            absolute URI of the data source
 * @param format
 *            RDF format to request/parse from data source
 */
public void addURI(String urlstring, RDFFormat format) {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			con.add(new URL(urlstring), null, format);
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:22,代碼來源:SimpleGraph.java


注:本文中的org.openrdf.repository.RepositoryConnection.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。