Java Code Examples for com.bigdata.rdf.store.AbstractTripleStore#getIndexManager()

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#getIndexManager() . 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: TestMockUtility.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a mocked context associated with the given abstract triple store,
 * with index manager properly initialized.
 * 
 * @param kb
 * @return
 */
public static BOpContext<IBindingSet> mockContext(final AbstractTripleStore kb) {
   
   final UUID queryId = UUID.randomUUID();
   final IQueryContext queryContext = new MockQueryContext(queryId);
   final IRunningQuery runningQuery = new MockRunningQuery(null/* fed */
         , kb.getIndexManager()/* indexManager */,queryContext
   );
   
   final BOpStats stats = new BOpStats();
   final PipelineOp mockQuery = new MockQuery();
   final IAsynchronousIterator<IBindingSet[]> source = new ThickAsynchronousIterator<IBindingSet[]>(
           new IBindingSet[][] { });
   final IBlockingBuffer<IBindingSet[]> sink = new BlockingBufferWithStats<IBindingSet[]>(
           mockQuery, stats);
   final BOpContext<IBindingSet> context = new BOpContext<IBindingSet>(
           runningQuery, -1/* partitionId */
           , stats, mockQuery/* op */, true/* lastInvocation */, source, sink,
           null/* sink2 */
   );
   
   return context;
}
 
Example 2
Source File: ExportKB.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Export the configuration properties for the kb.
     * 
     * @throws IOException
     */
    public void exportProperties() throws IOException {
        prepare();
        final AbstractTripleStore kb = conn.getTripleStore();
        // Prepare a comment block for the properties file.
        final StringBuilder comments = new StringBuilder(
                "Configuration properties.\n");
        if (kb.getIndexManager() instanceof IRawStore) {
            comments.append("source="
                    + ((IRawStore) kb.getIndexManager()).getFile() + "\n");
            comments.append("namespace=" + namespace + "\n");
            // The timestamp of the KB view.
            comments.append("timestamp=" + kb.getTimestamp() + "\n");
            // The date and time when the KB export began. (Automatically added by Java).
//            comments.append("exportDate=" + new Date() + "\n");
            // The approximate #of statements (includes axioms, inferences, and
            // deleted statements).
            comments.append("fastStatementCount="
                    + kb.getStatementCount(false/* exact */) + "\n");
            // The #of URIs in the lexicon indices.
            comments.append("uriCount=" + kb.getURICount() + "\n");
            // The #of Literals in the lexicon indices.
            comments.append("literalCount=" + kb.getLiteralCount() + "\n");
            // The #of blank nodes in the lexicon indices.
            comments.append("bnodeCount=" + kb.getBNodeCount() + "\n");
        }
        // Flatten the properties so inherited defaults will also be written
        // out.
        final Properties properties = flatCopy(kb.getProperties());
        // Write the properties file.
        final File file = new File(kbdir, "kb.properties");
        System.out.println("Writing " + file);
        final OutputStream os = new BufferedOutputStream(new FileOutputStream(
                file));
        try {
            properties.store(os, comments.toString());
        } finally {
            os.close();
        }
    }
 
Example 3
Source File: FulltextSearchServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static Properties getStoreProps(final ServiceCallCreateParams params) {
   final AbstractTripleStore store = params.getTripleStore();

   return store.getIndexManager()!=null &&
      store.getIndexManager() instanceof AbstractJournal  ?
      ((AbstractJournal)store.getIndexManager()).getProperties() : null;
}
 
Example 4
Source File: HistoryServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
         * Return the revision time that will be used for all changes written
         * onto the history index by this {@link IChangeLog} listener.
         * 
         * @see HistoryChangeRecord#getRevisionTime()
         */
        static private long getRevisionTimestamp(
                final AbstractTripleStore tripleStore) {

            final long revisionTimestamp;
            
            final IIndexManager indexManager = tripleStore.getIndexManager();

            revisionTimestamp = indexManager.getLastCommitTime() + 1;

//            if (indexManager instanceof IJournal) {
//
//                revisionTimestamp = indexManager.getLastCommitTime() + 1;
////                        ((IJournal) indexManager)
////                        .getLocalTransactionManager().nextTimestamp();
//                
//            } else if (indexManager instanceof IBigdataFederation) {
//                
//                try {
//                
//                    revisionTimestamp = ((IBigdataFederation<?>) indexManager)
//                            .getTransactionService().nextTimestamp();
//                    
//                } catch (IOException e) {
//                    
//                    throw new RuntimeException(e);
//                    
//                }
//
//            } else {
//            
//                throw new AssertionError("indexManager="
//                        + indexManager.getClass());
//                
//            }

            return revisionTimestamp;
        }
 
Example 5
Source File: GASService.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the object used to access the as-configured graph.
 */
private IGraphAccessor newGraphAccessor(final AbstractTripleStore kb) {

    /*
     * Use a read-only view (sampling depends on access to the BTree rather
     * than the ReadCommittedIndex).
     */
    final BigdataGraphAccessor graphAccessor = new BigdataGraphAccessor(
            kb.getIndexManager(), kb.getNamespace(), kb
                    .getIndexManager().getLastCommitTime());

    return graphAccessor;
    
}
 
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: GeoSpatialServiceFactory.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public BigdataServiceCall create(final ServiceCallCreateParams createParams) {

      if (createParams == null)
         throw new IllegalArgumentException();

      final AbstractTripleStore store = createParams.getTripleStore();

      final Properties props = store.getIndexManager() != null
            && store.getIndexManager() instanceof AbstractJournal ? ((AbstractJournal) store
            .getIndexManager()).getProperties() : null;

      final GeoSpatialDefaults dflts = new GeoSpatialDefaults(props);

      final ServiceNode serviceNode = createParams.getServiceNode();

      if (serviceNode == null)
         throw new IllegalArgumentException();

      /*
       * Validate the geospatial predicates for a given search variable.
       */
      final Map<IVariable<?>, Map<URI, StatementPatternNode>> map = verifyGraphPattern(
            store, serviceNode.getGraphPattern());

      if (map == null)
         throw new RuntimeException("Not a geospatial service request.");

      if (map.size() != 1)
         throw new RuntimeException(
               "Multiple geospatial service requests may not be combined.");

      final Map.Entry<IVariable<?>, Map<URI, StatementPatternNode>> e = map
            .entrySet().iterator().next();

      final IVariable<?> searchVar = e.getKey();

      final Map<URI, StatementPatternNode> statementPatterns = e.getValue();

      validateSearch(searchVar, statementPatterns);

      /**
       * Get the service call configuration from annotations (attachable via query hints).
       * Here's how to define the hints:
       * 
       * <code>
          hint:Prior <http://www.bigdata.com/queryHints#maxParallel> "20" .
          hint:Prior <http://www.bigdata.com/queryHints#com.bigdata.relation.accesspath.BlockingBuffer.chunkOfChunksCapacity> "10" .
          hint:Prior <http://www.bigdata.com/queryHints#com.bigdata.relation.accesspath.IBuffer.chunkCapacity> "100" .
          hint:Prior <http://www.bigdata.com/queryHints#com.bigdata.bop.join.PipelineJoin.avgDataPointsPerThread> "25000" .
         </code>
       */
      final Integer maxParallel = 
         serviceNode.getQueryHintAsInteger(
            PipelineOp.Annotations.MAX_PARALLEL, 
            PipelineOp.Annotations.DEFAULT_MAX_PARALLEL);
      final Integer minDatapointsPerTask =
         serviceNode.getQueryHintAsInteger(
            Annotations.MIN_DATAPOINTS_PER_TASK, 
            Annotations.DEFAULT_MIN_DATAPOINTS_PER_TASK);              
      final Integer numTasksPerThread = 
         serviceNode.getQueryHintAsInteger(
            Annotations.NUM_TASKS_PER_THREAD, 
            Annotations.DEFAULT_NUM_TASKS_PER_THREAD);
      final Integer threadLocalBufferCapacity = 
         serviceNode.getQueryHintAsInteger(
            BufferAnnotations.CHUNK_CAPACITY, 
            BufferAnnotations.DEFAULT_CHUNK_CAPACITY);
      final Integer globalBufferChunkOfChunksCapacity = 
         serviceNode.getQueryHintAsInteger(
            BufferAnnotations.CHUNK_OF_CHUNKS_CAPACITY, 
            BufferAnnotations.DEFAULT_CHUNK_OF_CHUNKS_CAPACITY);
  
      if (DEBUG) {
         log.debug("maxParallel=" + maxParallel);
         log.debug("numTasksPerThread=" + numTasksPerThread);
         log.debug("threadLocalBufferCapacity=" + threadLocalBufferCapacity);
         log.debug("globalBufferChunkOfChunksCapacity=" + globalBufferChunkOfChunksCapacity);
      }
      
      if (!store.getLexiconRelation().getLexiconConfiguration().isGeoSpatial()) {
          throw new GeoSpatialSearchException(
              "Geospatial is disabled. Please enable geospatial and reload your data.");
      }
      
      /*
       * Create and return the geospatial service call object, which will
       * execute this search request.
       */
      return new GeoSpatialServiceCall(searchVar, statementPatterns,
            getServiceOptions(), dflts, store, maxParallel, 
            numTasksPerThread*maxParallel /* max num tasks to generate */, 
            minDatapointsPerTask, threadLocalBufferCapacity, 
            globalBufferChunkOfChunksCapacity, createParams.getStats());

   }
 
Example 8
Source File: TestAsynchronousStatementBufferFactory.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Test with the "broken.rdf" data set (does not contain valid RDF). This
 * tests that the factory will shutdown correctly if there are processing
 * errors.
 * 
 * @throws Exception
 */
public void test_loadFails() throws Exception {
    
    final String resource = "/com/bigdata/rdf/rio/broken.rdf";

    final AbstractTripleStore store = getStore();
    try {
        
        if(!(store.getIndexManager() instanceof AbstractScaleOutFederation)) {
            
            log.warn("Test requires scale-out index views.");
            
            return;
            
        }

        if (store.isQuads()) {

            log.warn("Quads not supported yet.");
            
            return;
            
        }

        // only do load since we expect an error to be reported.
        final AsynchronousStatementBufferFactory<BigdataStatement, File> factory = doLoad2(
                store, new File(resource), parallel);
        
        assertEquals("errorCount", 1, factory.getDocumentErrorCount());
        
    } finally {
        
        store.__tearDownUnitTest();
        
    }

}
 
Example 9
Source File: TestTicket422.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_wrapTempTripleStore() throws SailException, ExecutionException, InterruptedException {

        final BigdataSail sail = getSail();
        
        try {

            sail.initialize();
            
            final String namespace = sail.getNamespace();
            
            final BigdataSailConnection mainConn = sail.getUnisolatedConnection();
            
            try {
            
                final AbstractTripleStore mainTripleStore = mainConn.getTripleStore();
    
                if (mainTripleStore == null)
                    throw new UnsupportedOperationException();
                
                final TempTripleStore tempStore = new TempTripleStore(//
                        sail.getIndexManager().getTempStore(), //
                        mainConn.getProperties(), mainTripleStore);
    
            try {
    
                    // Note: The namespace of the tempSail MUST be distinct from the namespace of the main Sail.
                    final BigdataSail tempSail = new BigdataSail(namespace+"-"+UUID.randomUUID(), tempStore.getIndexManager(),
                            mainTripleStore.getIndexManager());
    
                try {
    
                    tempSail.initialize();
    
                        tempSail.create(new Properties());
                        
                    final BigdataSailConnection con = tempSail.getConnection();
    
                    try {
    
                        final CloseableIteration<? extends Statement, SailException> itr = con
                                .getStatements((Resource) null, (URI) null,
                                        (Value) null, (Resource) null);
    
                        try {
    
                            while (itr.hasNext()) {
    
                                itr.next();
    
                            }
                                
                        } finally {
    
                            itr.close();
    
                        }
    
                    } finally {
    
                        con.close();
    
                    }
    
                } finally {
    
                    tempSail.shutDown();
                    
                }
    
            } finally {
    
                tempStore.close();
                
            }
            
        } finally {
                
                mainConn.close();
                
            }
            
        } finally {

            sail.__tearDownUnitTest();
            
        }
        
    }
 
Example 10
Source File: BigdataSail.java    From database with GNU General Public License v2.0 1 votes vote down vote up
/**
 * Core ctor. You must use this variant for a scale-out triple store.
 * <p>
 * To create a {@link BigdataSail} backed by an {@link IBigdataFederation}
 * use the {@link ScaleOutTripleStore} ctor and then
 * {@link AbstractTripleStore#create()} the triple store if it does not
 * exist.
 * <p>
 * Note: Since BLZG-2041, this delegates through to the core constructor
 * which accepts (namespace, IIndexManager). 
 * 
 * @param database
 *            An existing {@link AbstractTripleStore}.
 * @param mainIndexManager
 *            When <i>database</i> is a {@link TempTripleStore}, this is the
 *            {@link IIndexManager} used to resolve the
 *            {@link QueryEngine}. Otherwise it must be the same object as
 *            the <i>database</i>.
 */ 
public BigdataSail(final AbstractTripleStore database,
        final IIndexManager mainIndexManager) {

    this(database.getNamespace(), database.getIndexManager(), mainIndexManager);

}
 
Example 11
Source File: BigdataSail.java    From database with GNU General Public License v2.0 votes vote down vote up
/**
 * Constructor used to wrap an existing {@link AbstractTripleStore}
 * instance.
 * <p>
 * Note: Since BLZG-2041, this delegates through to the core constructor
 * which accepts (namespace, IIndexManager). 
 * 
 * @param database
 *            The instance.
 */
public BigdataSail(final AbstractTripleStore database) {
 
    this(database, database.getIndexManager());
    
}