AGRepositoryRemoveStatements.java
package com.franz.ag.repository.examples;
import static com.franz.ag.repository.examples.AGRepositoryValueFactory.*;
import info.aduna.iteration.CloseableIteration;
import com.franz.ag.repository.AGRepository;
import com.franz.agbase.AllegroGraph;
import com.franz.agbase.AllegroGraphConnection;
import com.franz.agbase.AllegroGraphException;
import com.franz.agbase.examples.AGPaths;
import org.openrdf.model.Statement;
import org.openrdf.model.ValueFactory;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
public class AGRepositoryRemoveStatements {
@param
@throws
public static void main(String[] args) throws Exception {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("repositorytuplequery", AGPaths.TRIPLE_STORES);
Repository repo = new AGRepository(ts);
repo.initialize();
RepositoryConnection repoConn = repo.getConnection();
ValueFactory vf = repo.getValueFactory();
createExampleValues(vf);
repoConn.add(bob, name, nameBob);
repoConn.add(alice, name, nameAlice);
repoConn.remove(bob, name, nameBob);
System.out.println("Repository has bob statement?: " + repoConn.hasStatement(bob, name, nameBob, false));
System.out.println("Repository has alice statement?: " + repoConn.hasStatement(alice, name, nameAlice, false));
repoConn.remove(alice, null, null);
System.out.println("Repository still has alice statement?: " + repoConn.hasStatement(alice, name, nameAlice, false));
System.out.println("Repository is empty?: " + repoConn.isEmpty());
repoConn.add(alice, name, nameAlice);
repoConn.add(bob, name, nameBob);
System.out.println("Repository has bob statement again?: " + repoConn.hasStatement(bob, name, nameBob, false));
System.out.println("Repository has alice statement again?: " + repoConn.hasStatement(alice, name, nameAlice, false));
CloseableIteration<? extends Statement, RepositoryException> iter = repoConn
.getStatements(null, null, null, false);
try {
repoConn.remove(iter);
} finally {
iter.close();
}
System.out.println("Repository is empty?: " + repoConn.isEmpty());
repoConn.close();
repo.shutDown();
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next