Java Code Examples for com.bigdata.rdf.sail.BigdataSailRepository#initialize()

The following examples show how to use com.bigdata.rdf.sail.BigdataSailRepository#initialize() . 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: TripleStoreBlazegraph.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public TripleStoreBlazegraph() {
    final Properties props = new Properties();
    props.put(Options.BUFFER_MODE, "MemStore");
    props.put(AbstractTripleStore.Options.QUADS_MODE, "true");
    props.put(BigdataSail.Options.TRUTH_MAINTENANCE, "false");

    // Quiet
    System.getProperties().setProperty("com.bigdata.Banner.quiet", "true");
    System.getProperties().setProperty("com.bigdata.util.config.LogUtil.quiet", "true");

    BigdataSail sail = new BigdataSail(props); // instantiate a sail
    repo = new BigdataSailRepository(sail); // create a Sesame repository

    try {
        repo.initialize();
    } catch (RepositoryException x) {
        LOG.error("Repository could not be created {}", x.getMessage());
    }
}
 
Example 2
Source File: LocalGOMTestCase.java    From database with GNU General Public License v2.0 5 votes vote down vote up
protected void setUp() throws Exception {

        // instantiate a sail and a Sesame repository
        m_sail = new BigdataSail(getProperties());
        m_repo = new BigdataSailRepository(m_sail);
        m_repo.initialize();
        m_vf = m_sail.getValueFactory();
        // Note: This uses a mock endpoint URL.
        om = new ObjectManager("http://localhost"
                + BigdataStatics.getContextPath() + "/sparql", m_repo);

    }
 
Example 3
Source File: TestRollbacks.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void doTest(final int maxCounter) throws InterruptedException, Exception {

        /*
         * Note: Each run needs to be in a distinct namespace since we otherwise
         * can have side-effects through the BigdataValueFactoryImpl for a given
         * namespace.
         */
        
        final Properties properties = new Properties(getProperties());
        
        properties.setProperty(BigdataSail.Options.NAMESPACE,
                "kb" + runCount.incrementAndGet());
        
        final BigdataSail sail = getSail(properties);
        
        try {
        	// Note: Modified to use the BigdataSailRepository rather than the base SailRepository class.
            final BigdataSailRepository repo = new BigdataSailRepository(sail);
            repo.initialize();
            runConcurrentStuff(repo,maxCounter);
        } finally {
			final IIndexManager db = sail.getIndexManager();
			try {
				if (sail.isOpen()) {
					try {
						sail.shutDown();
					} catch (Throwable t) {
						log.error(t, t);
					}
				}
			} finally {
				db.destroy();
			}
        }
    }
 
Example 4
Source File: TestRemoteGOM.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void setUp() throws Exception {

        final Properties properties = new Properties();

        // create a backing file for the database
        final File journal = File.createTempFile("bigdata", ".jnl");
        properties.setProperty(BigdataSail.Options.FILE, journal
                .getAbsolutePath());
        properties.setProperty(Options.BUFFER_MODE, BufferMode.DiskRW
                .toString());
        properties.setProperty(AbstractTripleStore.Options.TEXT_INDEX, "false");
        properties.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");
//        properties.setProperty(
//                IndexMetadata.Options.WRITE_RETENTION_QUEUE_CAPACITY, "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.spo.SPO.com.bigdata.btree.BTree.branchingFactor",
//                        "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.spo.POS.com.bigdata.btree.BTree.branchingFactor",
//                        "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.spo.OSP.com.bigdata.btree.BTree.branchingFactor",
//                        "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.spo.BLOBS.com.bigdata.btree.BTree.branchingFactor",
//                        "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.lex.TERM2ID.com.bigdata.btree.BTree.branchingFactor",
//                        "200");
//        properties
//                .setProperty(
//                        "com.bigdata.namespace.kb.lex.ID2TERM.com.bigdata.btree.BTree.branchingFactor",
//                        "200");

        // instantiate a sail and a Sesame repository
        final BigdataSail sail = new BigdataSail(properties);
        repo = new BigdataSailRepository(sail);
        repo.initialize();

        //m_cxn = repo.getConnection();
        //m_cxn.setAutoCommit(false);

        m_namespace = BigdataSail.Options.DEFAULT_NAMESPACE;

        final Map<String, String> initParams = new LinkedHashMap<String, String>();
        {

            initParams.put(ConfigParams.NAMESPACE, m_namespace);

            initParams.put(ConfigParams.CREATE, "false");

        }
        
        m_indexManager = repo.getSail().getIndexManager();
        m_server = NanoSparqlServer.newInstance(0/* port */, m_indexManager,
                initParams);

        m_server.start();

        final int port = NanoSparqlServer.getLocalPort(m_server);

        final String hostAddr = NicUtil.getIpAddress("default.nic", "default",
                true/* loopbackOk */);

        if (hostAddr == null) {

            fail("Could not identify network address for this host.");

        }

        m_serviceURL = new URL("http", hostAddr, port,
                BigdataStatics.getContextPath()/* file */)
        		// BigdataStatics.getContextPath() + "/sparql"/* file */)
                .toExternalForm();

        // final HttpClient httpClient = new DefaultHttpClient();

        // m_cm = httpClient.getConnectionManager();
        
       	m_client = HttpClientConfigurator.getInstance().newInstance();

        m_repo = new RemoteRepositoryManager(m_serviceURL, m_client, m_indexManager.getExecutorService());

    }
 
Example 5
Source File: TestBLZG1943.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testTicketBlzg1943() throws Exception {

        
        final BigdataSail sail = getSail();
        final BigdataSailRepository repo = new BigdataSailRepository(sail);

        try {

            repo.initialize();
            
            BigdataSailRepositoryConnection conn = repo.getConnection();
            
            // init repository
            conn.setAutoCommit(false);
            for (int i=0; i<500; i++) {
                final Statement s1 = new StatementImpl(new URIImpl("http://s" + i), new URIImpl("http://lat"), new LiteralImpl("10.24884"));
                final Statement s2 = new StatementImpl(new URIImpl("http://s" + i), new URIImpl("http://lon"), new LiteralImpl("73.24884"));
                
                conn.add(s1);
                conn.add(s2);
            }
            conn.commit();

            // validate data has been loaded
            final TupleQuery validate = conn.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * WHERE { ?s ?p ?o }");
            final TupleQueryResult res = validate.evaluate();
            int numTriples = 0;
            while (res.hasNext()) { res.next(); numTriples++; }
            assertEquals(numTriples, 1000);
            res.close();
            conn.close();

            // submit update query inducing geospatial literal construction
            conn = repo.getConnection();
            for (int i=0; i<100; i++) { // repeat a couple of times to increase the chance for thread collisions
                // send update
                final StringBuilder sb = new StringBuilder();
                sb.append("PREFIX ogc: <http://www.opengis.net/ont/geosparql#> ");
                sb.append("insert { ?s ogc:asWKT ?wkt } where { "
                        + "    ?s <http://lat> ?lat. ?s <http://lon> ?long. "
                        + "    bind(strdt(concat(\"POINT(\",str(?long),\" \",str(?lat),\")\"),ogc:wktLiteral) as ?wkt) }");
    
                final Update update = conn.prepareUpdate(QueryLanguage.SPARQL, sb.toString());
                update.execute();
            }
            conn.close();


        } catch (Exception e) {
            
            System.err.println("EXCEPTION: " + e.getMessage());
            throw(e);
            
        } finally {        

            repo.shutDown();
            
        }
    }
 
Example 6
Source File: AbstractApiTask.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
    * This version uses the namespace and timestamp provided by the caller.
    *
    * @param namespace
    * @param timestamp
    * @return
    * @throws RepositoryException
    * @throws DatasetNotFoundException
    */
protected BigdataSailRepositoryConnection getQueryConnection(
		final String namespace, final long timestamp)
		throws RepositoryException {

       // Wrap with SAIL.
       final BigdataSail sail = new BigdataSail(namespace, getIndexManager());

       final BigdataSailRepository repo = new BigdataSailRepository(sail);

       repo.initialize();

       if (TimestampUtility.isReadOnly(timestamp)) {

           return (BigdataSailRepositoryConnection) repo.getReadOnlyConnection(timestamp);

       }

       // Read-write connection.
       final BigdataSailRepositoryConnection conn = repo.getConnection();

       conn.setAutoCommit(false);

       return conn;

   }
 
Example 7
Source File: AbstractApiTask.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
* Return a connection for the namespace. If the task is associated with
* either a read/write transaction or an {@link ITx#UNISOLATED} view of the
* indices, the connection may be used to read or write on the namespace.
* Otherwise the connection will be read-only.
* 
* @return The connection.
* 
* @throws SailException
* @throws RepositoryException
* @throws DatasetNotFoundException
*            if the specified namespace does not exist.
*/
protected BigdataSailRepositoryConnection getConnection()
        throws SailException, RepositoryException {

    // Wrap with SAIL.
    final BigdataSail sail = new BigdataSail(namespace, getIndexManager());

    final BigdataSailRepository repo = new BigdataSailRepository(sail);

    repo.initialize();

    final BigdataSailRepositoryConnection conn = repo.getConnection();
    
    conn.setAutoCommit(false);
    
    // Setup a change listener. It will notice the #of mutations.
    conn.addChangeLog(new SailChangeLog());
    
    return conn;

}
 
Example 8
Source File: TestQuery2.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
	
	final String journalProps = "/Users/mikepersonick/Documents/workspace/bigdata-release-1.2/bigdata-perf/chem2bio2rdf/RWStore.properties";
	
	final String journal = "/Users/mikepersonick/Documents/nobackup/chem2bio2rdf/bigdata.RW.journal";
	
	final Reader reader = new FileReader(journalProps);

	final Properties props = new Properties();

	props.load(reader);

	reader.close();
	
	props.setProperty(Journal.Options.FILE, journal); 

	final BigdataSail sail = new BigdataSail(props);
	final BigdataSailRepository repo = new BigdataSailRepository(sail);
	repo.initialize();
	
	BigdataSailRepositoryConnection cxn = null;
	try {
		
		cxn = repo.getReadOnlyConnection();
		
		System.err.println(sail.getDatabase().predicateUsage().toString());
		
		long total = 0;
		
		for (int i = 0; i < 10; i++) {

			final long start = System.currentTimeMillis();
			
			final TupleQuery tq = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query);
			
			final TupleQueryResult result = tq.evaluate();
			
			int j = 0;
			while (result.hasNext()) {
				j++;
				result.next();
			}
			
			result.close();
			
			final long duration = System.currentTimeMillis() - start;
			
			total += duration;
			
			System.err.println("run " + i + ", " + duration + " millis, " + j + " results");
			
		}
		
		final long average = total / 10;
		
		System.err.println("average time: " + average + " millis");

	} catch (Exception ex) {
		
		ex.printStackTrace();
		
	} finally {
	
		if (cxn != null)
			cxn.close();
		
		repo.shutDown();
		
	}
	
	System.exit(0);
		
}
 
Example 9
Source File: RemoteGOMTestCase.java    From database with GNU General Public License v2.0 2 votes vote down vote up
@Override
public void setUp() throws Exception {

    // instantiate a sail and a Sesame repository
    final BigdataSail sail = new BigdataSail(getProperties());
    repo = new BigdataSailRepository(sail);
    repo.initialize();

    //m_cxn = repo.getConnection();
    //m_cxn.setAutoCommit(false);

    m_namespace = BigdataSail.Options.DEFAULT_NAMESPACE;

    final Map<String, String> initParams = new LinkedHashMap<String, String>();
    {

        initParams.put(ConfigParams.NAMESPACE, m_namespace);

        initParams.put(ConfigParams.CREATE, "false");

    }
    
    m_indexManager = repo.getSail().getIndexManager();
    m_server = NanoSparqlServer.newInstance(0/* port */, m_indexManager,
            initParams);

    m_server.start();

    final int port = NanoSparqlServer.getLocalPort(m_server);

    final String hostAddr = NicUtil.getIpAddress("default.nic", "default",
            true/* loopbackOk */);

    if (hostAddr == null) {

        fail("Could not identify network address for this host.");

    }

    m_serviceURL = new URL("http", hostAddr, port,
            BigdataStatics.getContextPath() /* file */)
    		// BigdataStatics.getContextPath() + "/sparql"/* file */)
            .toExternalForm();

    // final HttpClient httpClient = new DefaultHttpClient();

    // m_cm = httpClient.getConnectionManager();
   	m_client = HttpClientConfigurator.getInstance().newInstance();
    
    m_repo = new RemoteRepositoryManager(m_serviceURL, m_client, m_indexManager.getExecutorService());
    
    om = new NanoSparqlObjectManager(m_repo.getRepositoryForDefaultNamespace(),
            m_namespace); 

}
 
Example 10
Source File: GOMWebUtil.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return an {@link ObjectManager} instance that is scoped to the
 * <code>request</code>. The same {@link ObjectManager} instance will be
 * returned each time this method is invoked for the same
 * <code>request</code>. A distinct {@link ObjectManager} instance is
 * returned for each distinct <code>request</code>.
 * 
 * @param request
 *            The request.
 * @param timestamp
 *            The timestamp of the view.
 *            
 * @return The {@link ObjectManager}.
 * 
 * @throws Exception
 */
public static ObjectManager newObjectManager(
        final HttpServletRequest request, final long timestamp)
        throws RepositoryException {

    ObjectManager om = (ObjectManager) request.getAttribute(ATTRIBUTE_OM);
    
    if (om != null) {

        return om;

    }

    final ServletContext servletContext = request.getSession()
            .getServletContext();

    final BigdataRDFContext rdfContext = getBigdataRDFContext(servletContext);

    // The SPARQL endpoint.
    final String endpoint = request.getRequestURL().toString();
    
    final String namespace = rdfContext.getConfig().namespace;
    
    final AbstractTripleStore tripleStore = (AbstractTripleStore) rdfContext
            .getIndexManager().getResourceLocator()
            .locate(namespace, timestamp);

    if (tripleStore == null) {

        throw new RuntimeException("Not found: namespace=" + namespace);

    }

    // Wrap with SAIL.
    final BigdataSail sail = new BigdataSail(tripleStore);

    final BigdataSailRepository repo = new BigdataSailRepository(sail);

    repo.initialize();

    om = new ObjectManager(endpoint, repo);

    request.setAttribute(ATTRIBUTE_OM, om);

    return om;

}