Package com.hp.hpl.jena.tdb.transaction

Examples of com.hp.hpl.jena.tdb.transaction.DatasetGraphTxn


            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (numberGenerator.nextInt(2) == 0) {
                            DatasetGraphTxn txnGraph =
                                    storeConnection.begin(ReadWrite.WRITE);
                            txnGraph.add(new Quad(
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.createURI("http://openjena.org/"
                                            + numberGenerator.nextInt()),
                                    Node.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") ;
View Full Code Here


   
        @Override
        public Object call()
        {
          StoreConnection sConn = tts.getStoreConnection() ;
            DatasetGraphTxn dsg = null ;
            try
            {
                int id = gen.incrementAndGet() ;
                for (int i = 0; i < repeats; i++)
                {
                    dsg = sConn.begin(ReadWrite.READ) ;
                    log.debug("reader start " + id + "/" + i) ;

                    int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    pause(maxpause) ;
                    int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    if (x1 != x2) log.warn(format("READER: %s Change seen: %d/%d : id=%d: i=%d",
                                                  dsg.getTransaction().getLabel(), x1, x2, id, i)) ;
                    log.debug("reader finish " + id + "/" + i) ;
                    dsg.end() ;
                    dsg = null ;
                }
                return null ;
            } catch (RuntimeException ex)
            {
                ex.printStackTrace(System.err) ;
                if ( dsg != null )
                {
                    dsg.abort() ;
                    dsg.end() ;
                    dsg = null ;
                }
                return null ;
            }
        }
View Full Code Here

       
        @Override
        public Object call()
        {
          StoreConnection sConn = tts.getStoreConnection() ;
            DatasetGraphTxn dsg = null ;
            try {
                int id = gen.incrementAndGet() ;
                for ( int i = 0 ; i < repeats ; i++ )
                {
                    log.debug("writer start "+id+"/"+i) ;               
                    dsg = sConn.begin(ReadWrite.WRITE) ;

                    int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    int z = change(dsg, id, i) ;
                    pause(maxpause) ;
                    int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    if ( x1+z != x2 )
                    {
                        TransactionManager txnMgr = dsg.getTransaction().getTxnMgr() ;
                        SysTxnState state = txnMgr.state() ;
                        String label = dsg.getTransaction().getLabel() ;
                        log.warn(format("WRITER: %s Change seen: %d + %d != %d : id=%d: i=%d", label, x1, z, x2, id, i)) ;
                        log.warn(state.toString()) ;
                        dsg.abort() ;
                        dsg.end() ;
                        dsg = null ;
                        return null ;
                    }
                    if (commit)
                        dsg.commit() ;
                    else
                        dsg.abort() ;
                    SysTxnState state = sConn.getTransMgrState() ;
                    log.debug(state.toString()) ;
                    log.debug("writer finish "+id+"/"+i) ;               
                    dsg.end() ;
                    dsg = null ;
                }
                return null ;
            }
            catch (RuntimeException ex)
            {
                ex.printStackTrace(System.err) ;
                if ( dsg != null )
                {
                    dsg.abort() ;
                    dsg.end() ;
                    dsg = null ;
                }
                return null ;
            }
        }
View Full Code Here

    {
        if ( ! LOC.isMem() )
            FileOps.clearDirectory(LOC.getDirectoryPath()) ;
        StoreConnection.reset() ;
        StoreConnection sConn = StoreConnection.make(LOC) ;
        DatasetGraphTxn dsg = sConn.begin(ReadWrite.WRITE) ;
        dsg.add(q1) ;
        dsg.add(q2) ;
        initCount = 2 ;
        dsg.commit() ;
        dsg.end() ;
    }
View Full Code Here

        @Override
        public Object call()
        {
            start() ;
            DatasetGraphTxn dsg = null ;
            try
            {
                int id = gen.incrementAndGet() ;
                for (int i = 0; i < repeats; i++)
                {
                    dsg = sConn.begin(ReadWrite.READ) ;
                    log.debug("reader start " + id + "/" + i) ;

                    // Original T_TransSystem code
//                    int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
//                    pause(maxpause) ;
//                    int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
//                    if (x1 != x2) log.warn(format("READER: %s Change seen: %d/%d : id=%d: i=%d",
//                                                  dsg.getTransaction().getLabel(), x1, x2, id, i)) ;
                   
                    // Add in an abort.
                    long start = System.currentTimeMillis();
                    int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    pause(maxpause) ;

                    String qs1 = StrUtils.strjoinNL("PREFIX afn:     <http://jena.hpl.hp.com/ARQ/function#>",
                        "SELECT * { {FILTER(afn:wait(10))} UNION {?s ?p ?o }}") ;
                    String qs2 = StrUtils.strjoinNL("DESCRIBE ?s { ?s ?p ?o }") ;
                    try {
                        //countWithAbort(qs1, dsg, 5) ;
                        describeWithAbort(qs2, dsg, -1) ;
                    } catch (QueryCancelledException e)
                    {
                        txn("X", dsg);
                    }

                    log.debug("reader finish " + id + "/" + i) ;
                    dsg.end() ;
                    txn("R", dsg) ;
                    dsg = null ;
                }
                return null ;
            } catch (RuntimeException ex)
            {
                System.out.flush() ;
                System.err.println() ;
                ex.printStackTrace(System.err) ;
                if ( dsg != null )
                {
                    dsg.abort() ;
                    dsg.end() ;
                    txn("E", dsg) ;
                    dsg = null ;
                }
                System.exit(2) ;
                return null ;
View Full Code Here

        @Override
        public Object call()
        {
            start() ;

            DatasetGraphTxn dsg = null ;
            try {
                int id = gen.incrementAndGet() ;
                for ( int i = 0 ; i < repeats ; i++ )
                {
                    dsg = sConn.begin(ReadWrite.WRITE) ;
                    log.debug("writer start "+id+"/"+i) ;

                    int x1 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    int z = change(dsg, id, i) ;
                    pause(maxpause) ;
                    int x2 = count("SELECT * { ?s ?p ?o }", dsg) ;
                    if ( x1+z != x2 )
                    {
                        TransactionManager txnMgr = dsg.getTransaction().getTxnMgr() ;
                        SysTxnState state = txnMgr.state() ;
                        String label = dsg.getTransaction().getLabel() ;
                        log.warn(format("WRITER: %s Change seen: %d + %d != %d : id=%d: i=%d", label, x1, z, x2, id, i)) ;
                        log.warn(state.toString()) ;
                        dsg.abort() ;
                        dsg.end() ;
                        dsg = null ;
                        return null ;
                    }
                    if (commit)
                    {
                        dsg.commit() ;
                        txn("C", dsg) ;
                    }
                    else
                    {
                        dsg.abort() ;
                        txn("A", dsg) ;
                    }
                    SysTxnState state = sConn.getTransMgrState() ;
                    log.debug(state.toString()) ;
                    log.debug("writer finish "+id+"/"+i)
                    Lib.sleep(20) ;
                    dsg.end() ;
                    dsg = null ;
                }
                return null ;
            }
            catch (RuntimeException ex)
            {
                txn("E", dsg) ;
                System.err.println() ;
                ex.printStackTrace(System.err) ;
                System.exit(1) ;
                if ( dsg != null )
                {
                    dsg.abort() ;
                    dsg.end() ;
                    dsg = null ;
                }
               
                return null ;
            }
View Full Code Here

    @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 ;
       
View Full Code Here

    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

TOP

Related Classes of com.hp.hpl.jena.tdb.transaction.DatasetGraphTxn

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.