AGFederationRangeQueries.java
package com.franz.ag.examples;
import com.franz.ag.*;
import org.openrdf.model.Literal;
public class AGFederationRangeQueries {
    
@param
@throws
    public static void main(String[] args) throws AllegroGraphException {
    
        
        AllegroGraphConnection ags = new AllegroGraphConnection();
        try {
            ags.enable();
        } catch (Exception e) {
            throw new AllegroGraphException("Server connection problem", e);
        }
        
        ags.registerNamespace("ex","http://example.org/");
        
        
        AllegroGraph ts1 = ags.renew("store1", AGPaths.TRIPLE_STORES);
        AllegroGraph ts2 = ags.renew("store2", AGPaths.TRIPLE_STORES);
        
        AllegroGraph[] parts = {ts1,ts2};
        AllegroGraph fed = ags.federate("federation", parts, true);
        
        
        
        ts1.addStatement("!ex:person1","!ex:age", ts1.createEncodedLiteral(28,"int"));
        ts1.addStatement("!ex:person2","!ex:age", ts1.createEncodedLiteral(30,"int"));
        ts1.addStatement("!ex:person3","!ex:age", ts1.createEncodedLiteral(32,"int"));
        ts2.addStatement("!ex:person4","!ex:age", ts2.createEncodedLiteral(40,"int"));
        ts2.addStatement("!ex:person5","!ex:age", ts2.createEncodedLiteral(42,"int"));
        
        
        Literal low = fed.createEncodedLiteral(30,"int");
        Literal high = fed.createEncodedLiteral(40,"int");
        System.out.println("Retrieving triples with range 30 <= ex:age <= 40");
        Cursor cc = fed.getStatements(null, "!ex:age", low, high, null, null);
        AGUtils.showTriples(cc);
        
        fed.closeTripleStore();
        ts2.closeTripleStore();
        ts1.closeTripleStore();
        ags.disable();
    }
}
Up | 
Next