Package org.ozoneDB

Examples of org.ozoneDB.ExternalTransaction


            else {
                out.println ("Unknow argument: " + arg);
            }
        }

        ExternalTransaction tx = db.newTransaction();
        tx.begin();
        try {
            admin.beginBackup();

            OutputStream out = System.out;
            if (!filename.equals( "-" )) {
                out = new FileOutputStream( filename );
            }
            if (compress) {
                out = new GZIPOutputStream( out, 4096 );
            }
            else {
                out = new BufferedOutputStream( out, 4096 );
            }

            XMLSerializer serializer = new XMLSerializer( out, new OutputFormat( "xml", "UTF-8", indent ) );
            SAXChunkConsumer consumer = new SAXChunkConsumer( serializer.asContentHandler() );

            byte[] bytes = null;
            while ((bytes = admin.nextBackupChunk()) != null) {
                consumer.processChunk( bytes );
            }
            if (out instanceof GZIPOutputStream) {
                ((GZIPOutputStream)out).finish();
            }
            out.close();
        }
        finally {
            tx.rollback();
        }
    }
View Full Code Here


            }
            else
                return;
        }
       
        ExternalTransaction tx = db.newTransaction();
        tx.begin();
        try {
            long start;
            if (newDoc) {
                start = System.currentTimeMillis();
                container = XMLContainer.newContainer( db, filename );
                System.out.println( "DOM store: new container time: " + (System.currentTimeMillis() - start) + " ms" );
            }
           
            start = System.currentTimeMillis();
            DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
            Document doc = documentBuilder.parse( filename );
            // printNodeTree (doc, new StringBuffer ("    "));
            System.out.println( "DOM store: parse time: " + (System.currentTimeMillis() - start) + " ms" );
           
            start = System.currentTimeMillis();
            if (newDoc)
                container.storeDOM( doc );
            else
                container.storeDOM( null, doc );
            System.out.println( "DOM store: store time: " + (System.currentTimeMillis() - start) + " ms" );
           
            start = System.currentTimeMillis();
            tx.commit();
            System.out.println( "DOM store: commit time: " + (System.currentTimeMillis() - start) + " ms" );
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }
    }
View Full Code Here

        if (container != null) {
            System.out.println( "Document already found in Database." );
            return;
        }
       
        ExternalTransaction tx = db.newTransaction();
        tx.begin();
        try {
            long start = System.currentTimeMillis();
            container = XMLContainer.newContainer( db, filename );
            System.out.println( "SAX store: new container time: " + (System.currentTimeMillis() - start) + " ms" );
           
            start = System.currentTimeMillis();
            SAXParser parser = parserFactory.newSAXParser();
            ParserAdapter adapter = new ParserAdapter( parser.getParser() );
            adapter.setContentHandler( container.storeSAX() );
            adapter.parse( filename );
            System.out.println( "SAX store: parse+store time: " + (System.currentTimeMillis() - start) + " ms" );
           
            start = System.currentTimeMillis();
            tx.commit();
            System.out.println( "SAX store: commit time: " + (System.currentTimeMillis() - start) + " ms" );
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }
    }
View Full Code Here

                    System.out.println( "(NodeList): " + nodeList.getLength() + " Entries" );
                    DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
                    for (int i = 0; i < nodeList.getLength(); i++) {
                        System.out.print( i + 1 + " Entry: " );
                       
                        ExternalTransaction tx = db.newTransaction();
                        tx.begin();

                        // extract the result node from the persistent document first
                        start = System.currentTimeMillis();
                        Document doc = documentBuilder.newDocument();
                        Node extractedNode = container.extractDOM( doc, nodeList.item( i ), null, depth );
                        System.out.println( "[extract time: " + (System.currentTimeMillis() - start) + " ms]" );
                       
                        tx.commit();
                       
                        printNodeTree( extractedNode, new StringBuffer( "        " ) );
                    }
                    break;
                default:
View Full Code Here

        if (container == null) {
            System.out.println( "No such document." );
            return;
        }
       
        ExternalTransaction tx = db.newTransaction();
        tx.begin();
        try {
            PrintWriter writer = new PrintWriter( System.out, false );
            if (targetFile != null) {
                writer = new PrintWriter( new FileOutputStream( targetFile ), false );
            }
            XMLSerializer serializer = new XMLSerializer( writer, new OutputFormat( "xml", "UTF-8", true ) );

            long start = System.currentTimeMillis();
            container.extractSAX( serializer.asContentHandler(), null, depth );
            System.out.println( "Dump: extract/serialize time: " + (System.currentTimeMillis() - start) + " ms" );
           
            writer.close();
            tx.commit();
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }
    }
View Full Code Here

       
        DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
        Document doc = documentBuilder.newDocument();
        Node resultNode = null;
       
        ExternalTransaction tx = db.newTransaction();
        tx.begin();
        try {
            long start = System.currentTimeMillis();

            resultNode = container.extractDOM( doc, (Node)null /*container.getPDocument().getFirstChild()*/, null, depth );
            System.out.println( "Print: with depth: " + depth );

            System.out.println( "Print: extract DOM time: " + (System.currentTimeMillis() - start) + " ms" );
            tx.commit();
        }
        catch (Exception e) {
            tx.rollback();
            throw e;
        }
       
        if (printResult) {
            System.out.println( "Print: result: " );
View Full Code Here

        XMLContainer container = XMLContainer.forName( db, id );
        if (container == null) {
            container = XMLContainer.newContainer( db, id );
        }
       
        ExternalTransaction tx = db.newTransaction();
        try {
            long start = System.currentTimeMillis();
    
            tx.begin();
            start = System.currentTimeMillis();                   
            container.storeDOM( null, doc );
            System.out.println( "DOM store: store time: " + (System.currentTimeMillis() - start) + " ms" );
           
            start = System.currentTimeMillis();
            tx.commit();
            System.out.println( "DOM store: commit time: " + (System.currentTimeMillis() - start) + " ms" );
        } catch (Exception e) {
            tx.rollback();
            throw e;
        }
    }
View Full Code Here

        removeDocument();
    }

    public void testDOMUpdate() {
        insertDocument();
        ExternalTransaction tx = db.newTransaction();
        try {
            XMLContainer container = XMLContainer.forName(db, xmlTestDataFileName);
            assertNotNull(container);
            tx.begin();
            container.storeDOM(null, getTestDocument());
            tx.commit();
            removeDocument();
        } catch (Exception e) {
            try {
                tx.rollback();
            } catch (Exception e1) {
                // leave it for finally
            } finally {
                fail(e.getMessage());
            }
View Full Code Here

            return null;
        }
    }

    private void insertDocument() {
        ExternalTransaction tx = db.newTransaction();
        try {
            tx.begin();
            XMLContainer container = XMLContainer.newContainer(db, xmlTestDataFileName);
            container.storeDOM(getTestDocument());
            tx.commit();
        } catch (Exception e) {
            try {
                tx.rollback();
            } catch (Exception e1) {
                // leave it for finally
            } finally {
                fail(e.getMessage());
            }
View Full Code Here

                fail(e.getMessage());
            }
        }
    }
    private void removeDocument() {
        ExternalTransaction tx = db.newTransaction();
        try {
            tx.begin();
            XMLContainer container = XMLContainer.forName(db, xmlTestDataFileName);
            if (container == null) {
                fail("XML2ObjTest.removeDocument() - No such document " + xmlTestDataFileName);
            }
            container.delete();
            tx.commit();
            assertNull(XMLContainer.forName(db, xmlTestDataFileName));
        } catch (Exception e) {
            try {
                tx.rollback();
            } catch (Exception e1) {
                // leave it for finally
            } finally {
                fail(e.getMessage());
            }
View Full Code Here

TOP

Related Classes of org.ozoneDB.ExternalTransaction

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.