Java Code Examples for org.openrdf.repository.RepositoryConnection#remove()

The following examples show how to use org.openrdf.repository.RepositoryConnection#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SesameTransformationRepairSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activate(final Collection<SesameSwitchSetMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI currentPositionProperty = vf.createURI(BASE_PREFIX + CURRENTPOSITION);

	for (final SesameSwitchSetMatch match : matches) {
		final Resource sw = match.getSw();
		final Value position = match.getPosition();
		final Value currentPosition = match.getCurrentPosition();

		final RepositoryResult<Statement> statementsToRemove = con.getStatements(sw, currentPositionProperty, currentPosition, false);
		while (statementsToRemove.hasNext()) {
			con.remove(statementsToRemove.next());
		}

		con.add(sw, currentPositionProperty, position);
	}
}
 
Example 2
Source File: SesameTransformationRepairConnectedSegments.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activate(final Collection<SesameConnectedSegmentsMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI connectsTo = vf.createURI(BASE_PREFIX + CONNECTS_TO);
	for (final SesameConnectedSegmentsMatch match : matches) {
		// delete segment2 by removing all (segment2, _, _) and (_, _, segment2) triples
		final RepositoryResult<Statement> outgoingEdges = con.getStatements(match.getSegment2(), null, null, true);
		while (outgoingEdges.hasNext()) {
			con.remove(outgoingEdges.next());
		}
		final RepositoryResult<Statement> incomingEdges = con.getStatements(null, null, match.getSegment2(), true);
		while (incomingEdges.hasNext()) {
			con.remove(incomingEdges.next());
		}

		// insert (segment1)-[:connectsTo]->(segment3) edge
		con.add(match.getSegment1(), connectsTo, match.getSegment3());
	}
}
 
Example 3
Source File: SesameTransformationRepairPosLength.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activate(final Collection<SesamePosLengthMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI lengthProperty = vf.createURI(BASE_PREFIX + LENGTH);

	for (final SesamePosLengthMatch match : matches) {
		final Resource segment = match.getSegment();
		final Value length = match.getLength();

		final RepositoryResult<Statement> statementsToRemove = con.getStatements(segment, lengthProperty, length, true);
		while (statementsToRemove.hasNext()) {
			final Statement oldStatement = statementsToRemove.next();
			con.remove(oldStatement);
		}

		final Integer lengthInteger = new Integer(length.stringValue());
		final Integer newLengthInteger = -lengthInteger + 1;
		final Literal newLength = vf.createLiteral(newLengthInteger);
		final Statement newStatement = vf.createStatement(segment, lengthProperty, newLength);
		con.add(newStatement);
	}
}
 
Example 4
Source File: SesameTransformationInjectPosLength.java    From trainbenchmark with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void activate(final Collection<SesamePosLengthInjectMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI typeURI = vf.createURI(BASE_PREFIX + ModelConstants.LENGTH);
	final Literal zeroLiteral = vf.createLiteral(0);

	for (final SesamePosLengthInjectMatch match : matches) {
		final URI segment = match.getSegment();

		final RepositoryResult<Statement> statementsToRemove = con.getStatements(segment, typeURI, null, true);
		con.remove(statementsToRemove);

		con.add(segment, typeURI, zeroLiteral);
	}
}
 
Example 5
Source File: RdfIndexerService.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void removeEntityStates( Iterable<EntityState> entityStates, RepositoryConnection connection )
    throws RepositoryException
{
    List<URI> removedStates = new ArrayList<>();
    for( EntityState entityState : entityStates )
    {
        if( entityState.status().equals( EntityStatus.REMOVED ) )
        {
            removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) );
        }
        else if( entityState.status().equals( EntityStatus.UPDATED ) )
        {
            removedStates.add( stateSerializer.createEntityURI( getValueFactory(), entityState.entityReference() ) );
        }
    }

    if( !removedStates.isEmpty() )
    {
        Resource[] resources = removedStates.toArray( new Resource[ removedStates.size() ] );
        connection.remove( null, null, null, resources );
    }
}
 
Example 6
Source File: SesameTransformationInjectSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<SesameSwitchSetInjectMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI currentPositionProperty = vf.createURI(BASE_PREFIX + CURRENTPOSITION);

	for (final SesameSwitchSetInjectMatch match : matches) {
		final URI sw = match.getSw();
		final RepositoryResult<Statement> statements = con.getStatements(sw, currentPositionProperty, null, true);
		if (!statements.hasNext()) {
			continue;
		}

		final Statement oldStatement = statements.next();

		// delete old statement
		con.remove(oldStatement);

		// get next enum value
		final URI currentPositionURI = (URI) oldStatement.getObject();
		final String currentPositionRDFString = currentPositionURI.getLocalName();
		final String currentPositionString = RdfHelper.removePrefix(Position.class, currentPositionRDFString);
		final Position currentPosition = Position.valueOf(currentPositionString);
		final Position newCurrentPosition = Position.values()[(currentPosition.ordinal() + 1) % Position.values().length];
		final String newCurrentPositionString = RdfHelper.addEnumPrefix(newCurrentPosition);
		final URI newCurrentPositionUri = vf.createURI(BASE_PREFIX + newCurrentPositionString);

		// set new value
		con.add(sw, currentPositionProperty, newCurrentPositionUri);
	}
}
 
Example 7
Source File: SesameTransformationInjectConnectedSegments.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<SesameConnectedSegmentsInjectMatch> matches) throws Exception {
	final RepositoryConnection connection = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI length = vf.createURI(BASE_PREFIX + LENGTH);
	final URI connectsTo = vf.createURI(BASE_PREFIX + CONNECTS_TO);
	final URI monitoredBy = vf.createURI(BASE_PREFIX + MONITORED_BY);
	final URI segmentType = vf.createURI(BASE_PREFIX + SEGMENT);
	final Literal lengthLiteral = vf.createLiteral(TrainBenchmarkConstants.DEFAULT_SEGMENT_LENGTH);

	for (final SesameConnectedSegmentsInjectMatch match : matches) {
		// create (segment2) node
		final Long newVertexId = driver.generateNewVertexId();
		final URI segment2 = vf.createURI(BASE_PREFIX + ID_PREFIX + newVertexId);
		connection.add(segment2, RDF.TYPE, segmentType);
		connection.add(segment2, length, lengthLiteral);

		// (segment1)-[:connectsTo]->(segment2)
		connection.add(match.getSegment1(), connectsTo, segment2);
		// (segment2)-[:connectsTo]->(segment3)
		connection.add(segment2, connectsTo, match.getSegment3());

		// (segment2)-[:monitoredBy]->(sensor)
		connection.add(segment2, monitoredBy, match.getSensor());

		// remove (segment1)-[:connectsTo]->(segment3)
		connection.remove(match.getSegment1(), connectsTo, match.getSegment3());
	}
}
 
Example 8
Source File: SesameTransformationInjectRouteSensor.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<SesameRouteSensorInjectMatch> matches) throws RepositoryException {
	final RepositoryConnection connection = driver.getConnection();
	final ValueFactory vf = connection.getValueFactory();

	final List<Statement> statementsToRemove = new ArrayList<>(matches.size());
	final URI requires = vf.createURI(BASE_PREFIX + ModelConstants.REQUIRES);
	for (final SesameRouteSensorInjectMatch match : matches) {
		final Statement statement = vf.createStatement(match.getRoute(), requires, match.getSensor());
		statementsToRemove.add(statement);
	}
	connection.remove(statementsToRemove);
}
 
Example 9
Source File: PropertyTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testRemoveLiteral() throws Exception {
	Person jbroeks = (Person) manager.getObject(jbroeksURI);
	assertNotNull(jbroeks);
	jbroeks.setFoafBirthday("01-01");
	assertEquals("01-01", jbroeks.getFoafBirthday());
	RepositoryConnection connection = manager;
	connection.remove(new URIImpl(jbroeksURI.getNamespace() + jbroeksURI.getLocalName()), new URIImpl(FOAF_BIRTHDAY),
			null);
	jbroeks = manager.refresh(jbroeks);
	assertEquals(null, jbroeks.getFoafBirthday());
}
 
Example 10
Source File: StressTest_ClosedByInterrupt_RW.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void doDelete(final RepositoryConnection conn, final int loop, final int index)
        throws RepositoryException {
    final ValueFactory vf = conn.getValueFactory();
    final URI context = vf.createURI("context:loop:" + loop + ":item:" + index);
    final Collection<Statement> statements = getStatementsForContext(conn, context);
    for (Statement statement : statements) {
        conn.remove(statement, context);
    }
}
 
Example 11
Source File: CustomSesameDataset.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public void remove(Resource s, URI p, Value o, Resource... context) {
	try {
		RepositoryConnection con = currentRepository.getConnection();
		try {
			ValueFactory myFactory = con.getValueFactory();
			Statement st = myFactory.createStatement((Resource) s, p,
					(Value) o);
			con.remove(st, context);
		} finally {
			con.close();
		}
	} catch (Exception e) {
		// handle exception
	}
}
 
Example 12
Source File: StatementHandler.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Delete data from the repository.
 * 
 * @param repository the Repository object
 * @param request the HttpServletRequest object
 * @param response the HttpServletResponse object
 * @return EmptySuccessView if success
 * @throws HTTPException throws when there are repository update errors
 */
private ModelAndView getDeleteDataResult(final Repository repository, final HttpServletRequest request,
		final HttpServletResponse response)
		throws HTTPException {
	ProtocolUtil.logRequestParameters(request);

	ValueFactory vf = repository.getValueFactory();

	Resource subj = ProtocolUtil.parseResourceParam(request, SUBJECT_PARAM_NAME, vf);
	URI pred = ProtocolUtil.parseURIParam(request, PREDICATE_PARAM_NAME, vf);
	Value obj = ProtocolUtil.parseValueParam(request, OBJECT_PARAM_NAME, vf);
	Resource[] contexts = ProtocolUtil.parseContextParam(request, CONTEXT_PARAM_NAME, vf);

	try {
		RepositoryConnection repositoryCon = repository.getConnection();
		synchronized (repositoryCon) {
			repositoryCon.remove(subj, pred, obj, contexts);
		}
		repositoryCon.close();
		return new ModelAndView(EmptySuccessView.getInstance());
	} catch (RepositoryException e) {
		if (e.getCause() != null && e.getCause() instanceof HTTPException) {
			// custom signal from the backend, throw as HTTPException directly
			// (see SES-1016).
			throw (HTTPException) e.getCause();
		} else {
			throw new ServerHTTPException("Repository update error: " + e.getMessage(), e);
		}
	}
}
 
Example 13
Source File: RDFSingleDataSet.java    From mustard with MIT License 5 votes vote down vote up
@Override
public void removeStatements(Resource subject, URI predicate, Value object) {
	try {
		RepositoryConnection repCon = rdfRep.getConnection();

		try {
			repCon.remove(subject, predicate, object);
		} finally {
			repCon.close();
		}

	} catch (Exception e) {
		e.printStackTrace();
	}	
}
 
Example 14
Source File: TestHelper.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 
 * @param args
 * @throws Exception
 */
static public void main(final String[] args) throws Exception {

   if (args.length != 1) {

      System.err.println("usage: SPARQL-Endpoint-URL");

      System.exit(1);

   }

   final String sparqlEndpointURL = args[0];

   final RemoteRepositoryManager mgr = new RemoteRepositoryManager(
         "localhost:" + Config.BLAZEGRAPH_HTTP_PORT /* serviceURLIsIngored */);

   try {

      final BigdataSailRemoteRepository repo = mgr.getRepositoryForURL(
            sparqlEndpointURL).getBigdataSailRemoteRepository();

      RepositoryConnection cxn = null;
      try {

         cxn = repo.getConnection();

         cxn.remove(null/* s */, RDF.TYPE, FOAF.PERSON, (Resource[]) null/* c */);

      } finally {

         if (cxn != null) {
            cxn.close();
            cxn = null;
         }

         repo.shutDown();

      }

   } finally {

      mgr.close();

   }

}