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

The following examples show how to use com.bigdata.rdf.sail.BigdataSail#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: BigdataGraphFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new local in-memory bigdata instance with the supplied value
 * factory.
 */
public static BigdataGraph create(final BlueprintsValueFactory vf, 
        final Properties props) throws Exception {
    final BigdataSail sail = (BigdataSail) BigdataSailFactory.createSail();
    sail.initialize();
    return new BigdataGraphEmbedded(sail, vf, props);
}
 
Example 2
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void createTripleStore(
         final IIndexManager indexManager, final String namespace,
         final Properties properties) throws InterruptedException,
         ExecutionException, SailException {

		if(log.isInfoEnabled())
			log.info("KB namespace=" + namespace);

       boolean ok = false;
       final BigdataSail sail = new BigdataSail(namespace,indexManager);
       try {
           sail.initialize();
           sail.create(properties);
        if(log.isInfoEnabled())
        	log.info("Created tripleStore: " + namespace);
           ok = true;
           return;
       } finally {
           if (!ok)
               sail.shutDown();
       }
       
//      AbstractApiTask.submitApiTask(indexManager, new CreateKBTask(namespace,
//            properties)).get();
//		
//        /**
//         * Return a view of the new KB to the caller.
//         * 
//         * Note: The caller MUST NOT attempt to modify this KB view outside of
//         * the group commit mechanisms. Therefore I am now returning a read-only
//         * view.
//         */
//      final AbstractTripleStore tripleStore = (AbstractTripleStore) indexManager
//            .getResourceLocator().locate(namespace, ITx.READ_COMMITTED);
//
//      assert tripleStore != null;
//
//      return tripleStore;
      
    }
 
Example 3
Source File: BigdataGASRunner.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadFiles() throws IOException {

    final BigdataOptionData opt = getOptionData();

    final Journal jnl = opt.jnl;
    final String namespace = opt.namespace;
    final String[] loadSet = opt.loadSet.toArray(new String[0]);

    // Load data using the unisolated view.
    final AbstractTripleStore kb = (AbstractTripleStore) jnl
            .getResourceLocator().locate(namespace, ITx.UNISOLATED);

    if (opt.newKB && loadSet.length > 0) {

        final BigdataSail sail = new BigdataSail(kb);
        try {
            try {
                sail.initialize();
                loadFiles(sail, loadSet);
            } finally {
                if (sail.isOpen())
                    sail.shutDown();
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    // total #of edges in that graph.
    opt.nedges = kb.getStatementCount();

}
 
Example 4
Source File: BigdataGraphFactory.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Open an existing persistent local bigdata instance.  If a journal does
 * not exist at the specified location and the boolean create flag is true
 * a journal will be created at that location.
 */
public static BigdataGraph open(final String file, final boolean create) throws Exception {
    final BigdataSail sail = (BigdataSail) BigdataSailFactory.openSail(file, create);
    sail.initialize();
    return new BigdataGraphEmbedded(sail);
}
 
Example 5
Source File: BigdataGraphFactory.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
* Create a persistent local bigdata instance. If a journal does not exist
* at the specified location, then a journal will be created at that
* location.
*/
  public static BigdataGraph create(final String file) throws Exception {
      final BigdataSail sail = (BigdataSail) BigdataSailFactory.openSail(file, true);
      sail.initialize();
      return new BigdataGraphEmbedded(sail);
  }
 
Example 6
Source File: TestServiceRegistry.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unit test a {@link CustomServiceFactory} which hooks the connection start
 * for the {@link BigdataSail}.
 * 
 * @throws SailException
 */
public void test_customService() throws SailException {

    final URI serviceURI1 = new URIImpl("http://www.bigdata.com/myService/"
            + getName() + "/" + UUID.randomUUID());

    final MyCustomServiceFactory serviceFactory = new MyCustomServiceFactory(
            new OpenrdfNativeServiceOptions());

    try {

        // Verify not registered.
        assertNull(ServiceRegistry.getInstance().get(serviceURI1));

        // Register.
        ServiceRegistry.getInstance().add(serviceURI1, serviceFactory);

        // Verify discovery.
        assertNotNull(ServiceRegistry.getInstance().get(serviceURI1));

        // Verify same object.
        assertTrue(serviceFactory == ServiceRegistry.getInstance().get(
                serviceURI1));

        /*
         * Verify custom service visitation.
         */
        {

            final Iterator<CustomServiceFactory> itr = ServiceRegistry
                    .getInstance().customServices();

            boolean found = false;

            while (itr.hasNext()) {

                final CustomServiceFactory t = itr.next();

                if (t == serviceFactory) {

                    found = true;

                }

            }

            assertTrue(found);

        }

        /*
         * Verify hooked on connection start.
         */
        {
            final AbstractTripleStore store = getStore(getProperties());
            try {

                final BigdataSail sail = new BigdataSail(store.getNamespace(),store.getIndexManager());
                try {
                    sail.initialize();
                    // Nothing started yet.
                    assertEquals("nstarted", 0,
                            serviceFactory.nstarted.get());
                    final BigdataSailConnection conn = sail.getConnection();
                    try {
                        // Verify the service was notified.
                        assertEquals("nstarted", 1,
                                serviceFactory.nstarted.get());
                    } finally {
                        conn.close();
                    }

                } finally {
                    sail.shutDown();
                }

            } finally {
                store.destroy();
            }
        }

        // Verify the service was notified just once.
        assertEquals("nstarted", 1, serviceFactory.nstarted.get());

    } finally {

        // De-register.
        ServiceRegistry.getInstance().remove(serviceURI1);

    }

    // Verify not registered.
    assertNull(ServiceRegistry.getInstance().get(serviceURI1));

}
 
Example 7
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 4 votes vote down vote up
protected Server newFixture(final String lnamespace) throws Exception {

	   final IIndexManager indexManager = getIndexManager();
		
		final Properties properties = getProperties();

		// Create the triple store instance.
        createTripleStore(indexManager, lnamespace, properties);
        
        // Open an unisolated connection on that namespace and figure out what
        // mode the namespace is using.
        {
            final BigdataSail sail = new BigdataSail(lnamespace, indexManager);
            try {
                sail.initialize();
                final BigdataSailConnection con = sail.getUnisolatedConnection();
                try {
                    final AbstractTripleStore tripleStore = con.getTripleStore();
        if (tripleStore.isStatementIdentifiers()) {
			testMode = TestMode.sids;
        } else if (tripleStore.isQuads()) {
            testMode = TestMode.quads;
        } else {
            testMode = TestMode.triples;
        }
                } finally {
                    con.close();
                }
            } finally {
                sail.shutDown();
            }
        }

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

            initParams.put(ConfigParams.NAMESPACE, lnamespace);

            initParams.put(ConfigParams.CREATE, "false");
            
        }
        // Start server for that kb instance.
        final Server fixture = NanoSparqlServer.newInstance(0/* port */,
                indexManager, initParams);

        fixture.start();
		
        return fixture;
	}
 
Example 8
Source File: NSSEmbeddedExample.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Start and run an {@link NanoSparqlServer} instance from embedded code.
 * 
 * @param args
 *            ignored.
 *            
 * @throws Exception
 */
public static void main(final String[] args) throws Exception {

    final int port = 0; // random port.

    /*
     * Create or re-open a durable database instance using default
     * configuration properties. There are other constructors that allow you
     * to take more control over this process.
     */
    final BigdataSail sail = new BigdataSail();

    sail.initialize();

    try {

        final IIndexManager indexManager = sail.getDatabase()
                .getIndexManager();

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

        new Thread(new NSSEmbeddedExample(port, indexManager, initParams))
                .run();

    } finally {

        sail.shutDown();

    }

}
 
Example 9
Source File: TestPaths.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void testSimpleSSSP() throws Exception {

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

		final BigdataSailRepositoryConnection cxn = repo.getConnection();
		cxn.setAutoCommit(false);

		try {

			cxn.add(open("sssp.ttl"), "", RDFFormat.TURTLE);
			cxn.commit();

			log.trace("\n" + cxn.getTripleStore().dumpStore());

			final String query = IOUtils.toString(open("sssp.rq"));

			log.trace("\n" + query);

			final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL,
					query);

			final TupleQueryResult result = tqr.evaluate();

			while (result.hasNext()) {

				log.trace(result.next());

			}

			result.close();

		} finally {
			cxn.close();
			sail.__tearDownUnitTest();
		}

	}
 
Example 10
Source File: AbstractApiTask.java    From database with GNU General Public License v2.0 3 votes vote down vote up
protected BigdataSailConnection getUnisolatedSailConnection() throws SailException, InterruptedException {
    
    // Wrap with SAIL.
    final BigdataSail sail = new BigdataSail(namespace, getIndexManager());

    sail.initialize();

    final BigdataSailConnection conn = sail.getUnisolatedConnection();
    
    // Setup a change listener. It will notice the #of mutations.
    conn.addChangeLog(new SailChangeLog());
    
    return conn;

}
 
Example 11
Source File: BigdataGraphFixture.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public BigdataGraphFixture(final Properties properties)
        throws SailException {

    sail = new BigdataSail(properties);

    sail.initialize();

}
 
Example 12
Source File: BigdataGraphFixture.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public BigdataGraphFixture(final AbstractTripleStore kb)
        throws SailException {

    sail = new BigdataSail(kb);

    sail.initialize();

}