AGSailRemoveStatements.java

package com.franz.agsail.examples;

import com.knowledgereefsystems.agsail.*;

import java.io.File;

import org.openrdf.model.Literal;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.sail.*;

public class AGSailRemoveStatements {

    /**
     * Demonstrates removing statements from a Sail
     * 
     * @param args unused
     * @throws AllegroGraphException
     */
    public static void main(String[] args) throws SailException {
        
        // Specify the SAIL, including AllegroGraph server and store parameters
        Sail sail = new AllegroSail("localhost", 4567, false, "store", new File(AGPaths.TRIPLE_STORES), 0, 0, false, false);
        
        // Connect to the server and open the specified store (create it if necessary)  
        sail.initialize();
        SailConnection sc = sail.getConnection();

        // Removes all statements from the repository.
        sc.clear();
        
        // Create some Values to work with
        ValueFactory f = sail.getValueFactory();
        String ex = "http://example.org/person/";
        URI alice = f.createURI(ex, "alice");
        URI knows = f.createURI(ex, "knows");
        URI age = f.createURI(ex, "age");
        URI bob = f.createURI(ex, "bob");
        Literal lit42 = f.createLiteral(42);
        
        // Add some statements to the store
        sc.addStatement(alice, knows, bob);
        sc.addStatement(alice, age, lit42);
        System.out.println("Sail Connection size after add: " + sc.size());
        
        // Remove any statements involving predicate ex:age from the store
        sc.removeStatements(null, age, null);
        System.out.println("Sail Connection size after remove: " + sc.size());
        
        // Close the connection and shut down the Sail
        sc.close();
        sail.shutDown();
    }
    
}

Up | Next