DB2 Version 10.1 for Linux, UNIX, and Windows

Creating an RDF store using graph-level access control

You can create an RDF store that uses graph-level access control.

Before you begin

Determine the RDF predicates whose triples are used to control access to the RDF graph. For example, you can use the ContextId (http://myapp.net/xmlns/CONTEXTID) and AppId (http://myapp.net/xmlns/APPID) predicates. The filters that you use to control access to the graph are also known as filter predicates.

Determine the DB2® data types for the RDF object values for these predicates. Currently, only the DB2 VARCHAR data type is supported.

Procedure

To creating an RDF store that uses graph-level access control , write a program that uses the createStore() method of the StoreManager class. This method takes a properties argument. Specify the filter predicates by using the following properties format: <RDF_PREDICATE> = <DB2_DATATYPE>.

Example

The following Java™ program demonstrates how you can use the StoreManager class to create an RDF store with graph-level access control:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import com.ibm.rdf.store.StoreManager;

public class CreateStoreGraphAccessControl {

	/* Access to the graph is controlled based on the 
   * following two RDF predicates.
	 */
private final static String APPID = 
"http://myapp.net/xmlns/APPID";
	private final static String CONTEXTID = 
"http://myapp.net/xmlns/CONTEXTID";
	
	/**
	 * The DB2 data type for these predicates is assigned.
	 */
	private final static String APPID_DATATYPE = "VARCHAR(60)";
	private final static String CONTEXTID_DATATYPE = "VARCHAR(60)";
		
	

/*
	 * Create a java.util.properties file that lists these two 
   * properties and their data types, where  
   * propertyName is the RDF predicate and  
   * propertyValue is the data type for the RDF predicate.
	 */
	private static Properties filterPredicateProps = new 
Properties();
	static {
		filterPredicateProps.setProperty(APPID, APPID_DATATYPE);
		filterPredicateProps.setProperty(CONTEXTID, 
CONTEXTID_DATATYPE);
	}


	public static void main(String[] args) throws SQLException {
		
		Connection conn = null;
				
		// Get a connection to the DB2 database.
		try {
			Class.forName("com.ibm.db2.jcc.DB2Driver");
			conn = DriverManager.getConnection(
					"jdbc:db2://localhost:50000/dbrdf", 
"db2admin",	"db2admin");
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		
		/*
		 *  Create the store with the access control predicates.
		*/
		StoreManager.createStore(conn, "db2admin", 
"SampleAccessControl", null,
			filterPredicateProps);
	}
}