Package com.hp.hpl.jena.tdb

Examples of com.hp.hpl.jena.tdb.StoreConnection


   
    @Test
    public void store_0()
    {
        // Expel.
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ;
        dsgW1.commit() ;
        dsgW1.end() ;
        StoreConnection.release(sConn.getLocation()) ;
        StoreConnection sConn2 = getStoreConnection() ;
    }
View Full Code Here


   
    @Test
    public void store_1()
    {
        // Expel.
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ;
        DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ;
        dsgW1.add(q1) ;
        dsgW1.commit() ;
        dsgW1.end() ;
        dsgR1.end();
       
        StoreConnection.release(sConn.getLocation()) ;
        sConn = null ;
       
        StoreConnection sConn2 = getStoreConnection() ;
    }
View Full Code Here

    @Test(expected=TDBTransactionException.class)
    public void store_2()
    {
        // Expel.
        // Only applies to non-memory.
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ;
        StoreConnection.release(sConn.getLocation()) ;
    }
View Full Code Here

    @Test(expected=TDBTransactionException.class)
    public void store_3()
    {
        // Expel.
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.WRITE) ;
        StoreConnection.release(sConn.getLocation()) ;
    }
View Full Code Here

    }
   
    @Test
    public void store_4()
    {
        StoreConnection sConn = getStoreConnection() ;
        DatasetGraphTxn dsgR1 = sConn.begin(ReadWrite.READ) ;
        DatasetGraphTxn dsgW1 = sConn.begin(ReadWrite.WRITE) ;
        dsgW1.add(q1) ;
        dsgW1.commit() ;
        dsgW1.end() ;
        dsgR1.end();
       
        StoreConnection.release(sConn.getLocation()) ;
        sConn = null ;
       
        StoreConnection sConn2 = getStoreConnection() ;
        DatasetGraphTxn dsgW2 = sConn2.begin(ReadWrite.WRITE) ;
        dsgW2.add(q2) ;
        dsgW2.commit() ;
        dsgW2.end() ;
       
        DatasetGraphTxn dsgR2 = sConn2.begin(ReadWrite.READ) ;
        long x = Iter.count(dsgR2.find()) ;
        assertEquals(2, x) ;
    }
View Full Code Here

    @Test
    public void store_5()
    {
        // No transaction.  Make sure StoreConnection.release cleans up OK. 
        StoreConnection sConn = getStoreConnection() ;
        Location loc = sConn.getLocation() ;
        DatasetGraph dsg = sConn.getBaseDataset() ;
        dsg.add(q) ;
        assertTrue(dsg.contains(q)) ;
       
        StoreConnection.release(loc) ;
        sConn = StoreConnection.make(loc) ;
        dsg = sConn.getBaseDataset() ;
        assertTrue(dsg.contains(q)) ;
    }
View Full Code Here

    public void store_6()
    {
        // Transaction - release - reattach
        // This tests that the dataset is sync'ed when going into transactional mode.
       
        StoreConnection sConn = getStoreConnection() ;
        Location loc = sConn.getLocation() ;

        DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE) ;

        dsgTxn.add(q1) ;
        assertTrue(dsgTxn.contains(q1)) ;
        dsgTxn.commit() ;
        dsgTxn.end() ;

        sConn.forceRecoverFromJournal() ;
        assertTrue(sConn.getBaseDataset().contains(q1)) ;
       
        StoreConnection.release(loc) ;
        sConn = StoreConnection.make(loc) ;
        DatasetGraph dsg2 = sConn.getBaseDataset() ;
        assertTrue(dsg2.contains(q1)) ;
       
        DatasetGraphTxn dsgTxn2 = sConn.begin(ReadWrite.READ) ;
        assertTrue(dsgTxn2.contains(q1)) ;
        dsgTxn2.end() ;
    }
View Full Code Here

        // No transaction, plain update, then transaction.
        // This tests that the dataset is sync'ed when going into transactional mode.
       
        boolean nonTxnData = true ;
       
        StoreConnection sConn = getStoreConnection() ;
        Location loc = sConn.getLocation() ;
        DatasetGraph dsg = sConn.getBaseDataset() ;
        if ( nonTxnData )
        {
            dsg.add(q) ;
            TDB.sync(dsg) ;
            assertTrue(dsg.contains(q)) ;
        }

        DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE) ;
        if ( nonTxnData )
            assertTrue(dsgTxn.contains(q)) ;
        dsgTxn.add(q1) ;
        assertTrue(dsgTxn.contains(q1)) ;
        if ( nonTxnData )
            assertTrue(dsgTxn.contains(q)) ;
        dsgTxn.commit() ;
        dsgTxn.end() ;

        // Should have flushed to disk.
        if ( nonTxnData )
        {
            sConn.forceRecoverFromJournal() ;
            assertTrue(dsg.contains(q)) ;
        }
        assertTrue(dsg.contains(q1)) ;
       
        // release via the transactional machinery
        StoreConnection.release(loc) ;
        sConn = null ;
       
        StoreConnection sConn2 = StoreConnection.make(loc) ;
        DatasetGraph dsg2 = sConn2.getBaseDataset() ;
       
        if ( nonTxnData )
            assertTrue(dsg2.contains(q)) ;
        assertTrue(dsg2.contains(q1)) ;
       
        DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ) ;
        if ( nonTxnData )
            assertTrue(dsgTxn2.contains(q)) ;
        assertTrue(dsgTxn2.contains(q1)) ;
        dsgTxn2.end() ;
View Full Code Here

        }
    }
   
    //@Test
    public void test() {
        final StoreConnection storeConnection =
                StoreConnection.make(Location.mem());

        //ExecutorService executor = Executors.newCachedThreadPool()  ;     // Not seen blocking.
        // 4 blocks maybe 1 in 4 times
        // 8 blocks (quad core) 2 in 3 times.
        ExecutorService executor = Executors.newFixedThreadPool(8) ;

        final AtomicInteger nbQuadruplesAdded = new AtomicInteger();

        final CountDownLatch doneSignal =
                new CountDownLatch(CONCURRENT_RANDOM_OPERATIONS);

        for (int i = 0; i < CONCURRENT_RANDOM_OPERATIONS; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (numberGenerator.nextInt(2) == 0) {
                            DatasetGraphTxn txnGraph =
                                    storeConnection.begin(ReadWrite.WRITE);
                            txnGraph.add(new Quad(
                                    NodeFactory.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    NodeFactory.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    NodeFactory.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    NodeFactory.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt())));
                            txnGraph.commit();
                            txnGraph.end();
                            nbQuadruplesAdded.incrementAndGet();
                        } else {
                            DatasetGraphTxn txnGraph =
                                    storeConnection.begin(ReadWrite.READ);
                            txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
                            //Iterator<Quad> iter = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
                            //Iter.count(iter) ; // Consume
                            txnGraph.end();
                        }
                    } finally {
                        doneSignal.countDown();
                    }
                }
            });
        }

        // shutdown is orderly so sync'ing up before the shutdown is nice but not needed.
        try {
            doneSignal.await();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            executor.shutdown();
        }

        DatasetGraphTxn txnGraph =
                storeConnection.begin(ReadWrite.READ);
        Iterator<Quad> result = txnGraph.find(
                Node.ANY, Node.ANY, Node.ANY, Node.ANY);
       
        long count = 0;
        while (result.hasNext()) {
            result.next();
            count++;
        }
       
        txnGraph.end();
       
        StoreConnection.release(storeConnection.getLocation());

        //System.out.println() ;
        System.out.println("FINISHED") ;
       
//        // This is unsafe - the quad adds may generate duplicates (ity's unlikly 4 random number reoccur but it's possible).
View Full Code Here

    private StoreConnection sConn ;
    private static Random random = new Random(System.currentTimeMillis()) ;

    protected synchronized StoreConnection getStoreConnection()
    {
        StoreConnection sConn = StoreConnection.make(LOCATIONS.get(random.nextInt(NUM_DATASETS))) ;
        //sConn.getTransMgr().recording(true) ;
        return sConn ;
    }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.tdb.StoreConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.