当前位置: 首页>>代码示例>>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;未经允许,请勿转载。