Package org.ozoneDB

Examples of org.ozoneDB.ExternalTransaction


    *
    * @param content The new content value
    */
    public void setContent( Object value ) throws XMLDBException {
        if (value instanceof String) {  
            ExternalTransaction tx = database.newTransaction();           
            // we assume it's a valid XML doc and parse it
            try {               
                StringReader in = new StringReader((String)value);
                InputSource source = new InputSource(in);
                SAXParser parser = parserFactory.newSAXParser();
                ParserAdapter adapter = new ParserAdapter( parser.getParser() );
                tx.begin();
                adapter.setContentHandler( container.storeSAX() );
                adapter.parse( source );
                tx.commit();
            }
            catch (SAXException e) {
                try {
                    if (tx.getStatus() == tx.STATUS_ACTIVE)
                        tx.rollback();
                    throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e.getMessage())
                }
                catch (Exception rollbackException) {
                    throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.toString())
                }
            }
            catch (Exception e) {
                try {
                    if (tx.getStatus() == tx.STATUS_ACTIVE)
                        tx.rollback();
                    throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage())
                }
                catch (Exception rollbackException) {
                    throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.toString())
                }
View Full Code Here


    * Returns the content of the <code>Resource</code> as a DOM Node.
    *
    * @return The XML content as a DOM <code>Node</code>
    */
    public Node getContentAsDOM() throws XMLDBException {
        ExternalTransaction tx = database.newTransaction();       
        try {           
            tx.begin();
            DocumentBuilderFactory builderFactory = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();           
            DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
            Document doc = container.extractDOM(documentBuilder.newDocument());           
            tx.commit();
            return doc;
        }
        catch (Exception e) {
            try {
                if (tx.getStatus() == tx.STATUS_ACTIVE)
                    tx.rollback();
                throw new XMLDBException( ErrorCodes.VENDOR_ERROR, e.getMessage());
            }
            catch (Exception rollbackException) {
                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.toString())
            }           
View Full Code Here

    * source.
    *
    * @param content The new content value
    */
    public void setContentAsDOM( Node content ) throws XMLDBException {  
        ExternalTransaction tx = database.newTransaction();            
        try {           
            if (content == null) {
                System.out.println("XMLResourceImpl.setContentAsDOM() - Content is null");
                throw new XMLDBException(ErrorCodes.INVALID_RESOURCE);
            }
            if (content instanceof Document) {
                Document doc = (Document)content; 
                tx.begin();      
                container.storeDOM(doc);               
                tx.commit();
            }
            else {
                System.out.println("Cannot store Nodes right now, must be a Document");
            }                           
        }
        catch (Exception e) {
            e.printStackTrace();           
            try {
                System.out.println("XMLResourceImpl.setContentAsDOM() - Transaction status is " + tx.getStatus());
                if (tx.getStatus() == tx.STATUS_ACTIVE)
                    tx.rollback();
                throw new XMLDBException( ErrorCodes.VENDOR_ERROR, e.getMessage());
            }
            catch (Exception rollbackException) {
                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.getMessage())
            }           
View Full Code Here

    *
    * @param handler the SAX <code>ContentHandler</code> to use to handle the
    *  <code>Resource</code> content.   
    */
    public void getContentAsSAX( ContentHandler handler ) throws XMLDBException {
        ExternalTransaction tx = database.newTransaction();       
        try {
            tx.begin();
            container.extractSAX(handler);
            tx.commit();
        }
        catch (Exception e) {
            try {
                if (tx.getStatus() == tx.STATUS_ACTIVE)
                    tx.rollback();           
                throw new XMLDBException( ErrorCodes.VENDOR_ERROR, e.getMessage());
            }
            catch (Exception rollbackException) {
                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.toString())
            }           
View Full Code Here

    *
    * @return a SAX <code>ContentHandler</code> that can be used to add content
    *  into the <code>Resource</code>.
    */
    public ContentHandler setContentAsSAX() throws XMLDBException {
        ExternalTransaction tx = database.newTransaction();               
        try
            tx.begin();
            ContentHandler handler = container.storeSAX();
            tx.commit();
            return handler;
        }
        catch (Exception e) {
            try {
                if (tx.getStatus() == tx.STATUS_ACTIVE)
                    tx.rollback();
                throw new XMLDBException( ErrorCodes.VENDOR_ERROR, e.getMessage());
            }
            catch (Exception rollbackException) {
                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, rollbackException.toString())
            }           
View Full Code Here

     *  Example: String content = toString( "xml", "UTF-8", true );
     *
     */ 
    private String toString(String type, String encoding, boolean indenting) throws Exception {       
        int depth = -1;
        ExternalTransaction tx = database.newTransaction();
        tx.begin();
        try {
            StringWriter writer = new StringWriter();
            XMLSerializer serializer = new XMLSerializer( writer, new OutputFormat(type, encoding, indenting) );
            ContentHandler handler = serializer.asContentHandler();
            container.extractSAX( handler, null, depth );
            writer.flush();
            tx.commit();
            return writer.toString();
        }
        catch (Exception e) {
            if (tx.getStatus() == tx.STATUS_ACTIVE)
                tx.rollback();
            throw e;
        }
    } 
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.