// Copyright 2000 by CiTR Pty Ltd. All rights reserved. import java.io.*; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.NamedNodeMap; import org.ozoneDB.RemoteDatabase; import org.ozoneDB.OzoneRemote; import org.ozoneDB.ExternalTransaction; import org.ozoneDB.xml.util.XPathQuery; import org.ozoneDB.xml.util.XPathQueryImpl; import org.ozoneDB.xml.util.XPathQueryString; import org.ozoneDB.xml.util.XPathQueryStringImpl; import org.ozoneDB.xml.util.XPathInsertString; import org.ozoneDB.xml.util.XPathInsertStringImpl; import org.ozoneDB.xml.util.XPathUpdateString; import org.ozoneDB.xml.util.XPathUpdateStringImpl; import org.ozoneDB.xml.util.OzoneDOMParser; import org.ozoneDB.xml.util.PersistentDOMParser; import org.ozoneDB.xml.util.XercesDOMParser; import org.ozoneDB.xml.util.DOMConverter; import org.ozoneDB.xml.util.DOMConverterImpl; import org.ozoneDB.xml.util.XalanXMLFragWriter; import org.apache.xalan.xpath.XObject; import org.xml.sax.InputSource; /** */ public class DBTool { // Database handle static RemoteDatabase database = new RemoteDatabase(); // Host to contact static String hostname = "localhost"; // Port to use static int port = 3333; // Debugging static boolean debug = true; /** Print the Useage of this sample. */ private static void usage( String prefixError ) { System.out.println( prefixError ); System.out.println( "Useage:" ); System.out.println( " java DBTool [-h host] [-p port] cmd..." ); System.out.println( "Where 'cmd' is one of:" ); System.out.println( " query document-name xpath-query" ); System.out.println( " xquery document-name xpath-query" ); System.out.println( " store document-name..." ); System.out.println( " remove document-name..." ); System.out.println( " insert document-name xpath-query xml-fragment..." ); System.out.println( " xinsert document-name xpath-query xml-fragment..." ); System.out.println( " update document-name xpath-query xml-fragment..." ); System.out.println( " delete document-name xpath-query" ); System.exit( 2 ); } private static String[] sliceFrom( int argp, String args[] ) { int size = args.length - argp; if (size < 1) size = 0; String[] result = new String[size]; for( int idx = 0; argp < args.length; ++argp, ++idx ) result[idx] = args[argp]; return result; } private static String accumulateString( int argp, String args[] ) { String result = ""; for( ; argp < args.length; ++argp ) result = result + args[argp] + " "; return result; } private static void listNodes( NodeList nodes) { for( int idx = 0; idx < nodes.getLength(); ++idx ) listNodes( nodes.item( idx ) ); } private static void listNodes( Node node) { listNodes( node, new StringBuffer( "" ) ); } private static void listNode( Node node, StringBuffer indent, boolean deep) { try { // Open node scope System.out.print( indent.toString() ); System.out.print( "<" + node.getNodeName() ); // Display any attributes this node has NamedNodeMap attrs = node.getAttributes(); if ( attrs != null && attrs.getLength() > 0 ) { for( int idx = 0; idx < attrs.getLength(); ++idx ) { Node attr = attrs.item( idx ); System.out.print( " " + attr.getNodeName() + "=" + attr.getNodeValue() ); } } System.out.println( ">" ); indent.append( " " ); // Display any node value if ( node.getNodeValue() != null ) { System.out.print( indent.toString() ); System.out.println( node.getNodeValue () ); } // Recursively display the children (if asked) if ( deep && node.hasChildNodes() ) { System.out.print( indent.toString() ); System.out.println( "[" + node.getChildNodes().getLength() + " children]" ); Node _child = (Node) node.getFirstChild(); for ( ; _child != null; _child = (Node) _child.getNextSibling() ) { listNodes( _child, indent ); } } indent.setLength( indent.length() - 3 ); // Close node scope System.out.print( indent.toString() ); System.out.println( "" ); } catch (Exception except) { System.out.println( "Unexpected exception: " + except ); } } private static void listNodes( Node node, StringBuffer indent) { listNode( node, indent, true ); } /** * Import nodes from one DOM into another */ private static Node importNodes( Node from, Document doc) { Node newNode = null; switch ( from.getNodeType() ) { case org.w3c.dom.Node.COMMENT_NODE: newNode = (Node) doc.createComment( from.getNodeValue() ); break; case org.w3c.dom.Node.TEXT_NODE: newNode = (Node) doc.createTextNode( from.getNodeValue() ); break; case org.w3c.dom.Node.ELEMENT_NODE: newNode = (Node) doc.createElement( from.getNodeName () ); // Element nodes have attributes NamedNodeMap attrs = from.getAttributes(); if ( attrs != null && attrs.getLength() > 0 ) { Element elt = (Element) newNode; for( int idx = 0; idx < attrs.getLength(); ++idx ) { Node attr = attrs.item( idx ); elt.setAttribute( attr.getNodeName(), attr.getNodeValue() ); } } break; // case ATTRIBUTE_NODE: // case CDATA_SECTION_NODE: // case ENTITY_REFERENCE_NODE: // case ENTITY_NODE: // case PROCESSING_INSTRUCTION_NODE: // case DOCUMENT_NODE: // case DOCUMENT_TYPE_NODE: // case DOCUMENT_FRAGMENT_NODE: // case NOTATION_NODE: default: System.out.println( "Unknown node type (" + from.getNodeName () + "), skipping..." ); return newNode; } for( Node child = (Node) from.getFirstChild(); child != null; child = (Node) child.getNextSibling() ) { Node newChild = importNodes( child, doc ); newNode.appendChild( newChild ); } return newNode; } private static void applyUpdates( Node from, // Source of updates Node to, // Destination of updates Document doc) { // If the node types don't match, then it's all over if ( from.getNodeType() != to.getNodeType() ) return; // Apply any value updates from the target node if ( from.getNodeValue() != null ) to.setNodeValue( from.getNodeValue() ); // If it's an element node, apply any attribute updates if ( to.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE ) { NamedNodeMap attrs = from.getAttributes(); if ( attrs != null && attrs.getLength() > 0 ) { Element elt = (Element) to; for( int idx = 0; idx < attrs.getLength(); ++idx ) { Node attr = attrs.item( idx ); elt.setAttribute( attr.getNodeName(), attr.getNodeValue() ); } } } // Now, here comes the fun bit. We must process the child nodes // in some matching way, since order is not guarenteed. The way // we do this is to match node names. for( Node from_child = (Node) from.getFirstChild(); from_child != null; from_child = (Node) from_child.getNextSibling() ) { // Locate a target child in the 'to' tree for( Node to_child = (Node) to.getFirstChild(); to_child != null; to_child = (Node) to_child.getNextSibling() ) { // Test for match if ( from_child.getNodeType() != to_child.getNodeType() ) continue; if ( ! from_child.getNodeName().equals( to_child.getNodeName() ) ) continue; // Matched, apply the change applyUpdates( from_child, to_child, doc ); } } } /** Store one or more XML documents in the database. */ private static void store( String args[] ) { // Arg format: docName if ( args.length < 1 ) usage( "invalid store" ); // Store all documents for( int argp = 0; argp < args.length; ++argp ) { String docName = args[argp]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } try { // Does the document exist? if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc != null ) { System.err.println( "Document already exists, skipping..." ); continue; } // Construct the parser if (debug) { System.out.println( "### Constructing OzoneDOMParser" ); } PersistentDOMParser parser = (PersistentDOMParser) new OzoneDOMParser(database); if (debug) { System.out.println( "### Constructing XercesDOMParser" ); } XercesDOMParser xercesParser = (XercesDOMParser) new XercesDOMParser(); if (debug) { System.out.println( "### Parsing into memory" ); } Document memDoc = xercesParser.parse(docName); if (debug) { System.out.println( "### Storing into Ozone" ); } pDoc = parser.storeDocument(memDoc, docName); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } } /** Remove one or more XML documents from the database. */ private static void remove( String args[] ) { // Arg format: docName if ( args.length < 1 ) usage( "invalid remove" ); // Store all documents for( int argp = 0; argp < args.length; ++argp ) { String docName = args[argp]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } try { // Does the document exist? if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist, skipping..." ); continue; } // Remove the document if (debug) { System.out.println( "### Removing" ); } database.deleteObject ((OzoneRemote)pDoc); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } } /** Perform a query on an XML document in the database. */ private static void query( String args[] ) { // Arg format: docName xPathQuery if ( args.length < 2 ) usage( "invalid query" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = accumulateString( 1, args ); if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // Get the document Document pDoc; try { if (debug) { System.out.println( "### Checking for existance" ); } pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); return; } // Start Query try { // Do the query if (debug) { System.out.println( "### Creating query" ); } XPathQuery xPQuery = (XPathQuery) database.createObject( XPathQueryImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing query" ); } XObject result = (XObject) xPQuery.execute( xPathQuery, pDoc.getDocumentElement() ); if (result == null) { System.err.println( "Did not match any nodes" ); return; } NodeList resultList = result.nodeset(); if ( resultList.getLength() == 0 ) { System.err.println( "Did not match any nodes" ); return; } // Need to display all of them for( int idx = 0; idx < resultList.getLength (); ++idx ) { if (debug) { System.out.println( "### Query result point idx=" + idx ); } Node resultPoint = resultList.item (idx); // Print the result if (debug) { System.out.println( "### Printing result" ); } listNodes( resultPoint ); } if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform a query on an XML document in the database. */ private static void xquery( String args[] ) { // Arg format: docName xPathQuery if ( args.length < 2 ) usage( "invalid xquery" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = accumulateString( 1, args ); if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // Get the document Document pDoc; try { if (debug) { System.out.println( "### Checking for existance" ); } pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); return; } // Start Query try { // Do the query if (debug) { System.out.println( "### Creating query" ); } XPathQueryString xPQuery = (XPathQueryString) database.createObject( XPathQueryStringImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing query" ); } String result = (String) xPQuery.execute( xPathQuery, pDoc.getDocumentElement() ); if (result == null) { System.err.println( "Did not match any nodes" ); return; } // Print the result if (debug) { System.out.println( "### Printing result" ); } System.out.println( result ); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform an insert on an XML document in the database. */ private static void insert( String args[] ) { // Arg format: docName xPathQuery xmlFrag if ( args.length < 3 ) usage( "invalid insert" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = args[1]; if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // XML Fragment String xmlFrag = accumulateString( 2, args ); if (debug) { System.out.println( "### XML Fragment=\"" + xmlFrag + "\"" ); } // Do the insert try { // Begin Txn ExternalTransaction tx = database.newTransaction(); if (debug) { System.out.println( "### Begin" ); } tx.begin(); // Get the document if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } // Locate the insert point if (debug) { System.out.println( "### Creating query" ); } XPathQuery xPQuery = (XPathQuery) database.createObject( XPathQueryImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing query" ); } XObject result = (XObject) xPQuery.execute( xPathQuery, pDoc.getDocumentElement() ); if (result == null) { System.err.println( "Did not locate point to insert" ); return; } NodeList resultList = result.nodeset(); if (resultList.getLength() == 0) { System.err.println( "Did not locate point to insert" ); return; } // Parse the fragment if (debug) { System.out.println( "### Constructing XercesDOMParser" ); } XercesDOMParser xercesParser = (XercesDOMParser) new XercesDOMParser(); if (debug) { System.out.println( "### Parsing fragment into memory" ); } Document memDoc = xercesParser.parse( new InputSource( new StringReader( xmlFrag ) ) ); Node memNode = memDoc.getDocumentElement(); // Print the fragment if (debug) { System.out.println( "### Parsed fragment (in memory)" ); } listNodes( memNode ); // Need to insert at all of them for( int idx = 0; idx < resultList.getLength(); ++idx ) { if (debug) { System.out.println( "### Insert result point idx=" + idx ); } Node insertPoint = resultList.item(idx); // Import the nodes into this document if (debug) { System.out.println( "### Importing nodes into this document" ); } // DOM 2 has the importNode() function. This is not present in // the DOM implementation of Ozone. In order to get this DOM we've parsed into // the Database, we must get the nodes created under the same document as that // in the database. After we've done that, then we can link the top of the // tree into the desired spot. // Node importedNode = pDoc.importNode( memNode, true ); Node pNode = importNodes( memNode, pDoc ); if (debug) { System.out.println( "### XML Fragment (remote)" ); } listNodes( pNode ); // Add the fragment to the database if (debug) { System.out.println( "### Add imported nodes to to the document" ); } insertPoint.appendChild( pNode ); } if (debug) { System.out.println( "### Commit" ); } tx.commit(); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform an insert on an XML document in the database. */ private static void xinsert( String args[] ) { // Arg format: docName xPathQuery xmlFrag if ( args.length < 3 ) usage( "invalid xinsert" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = args[1]; if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // XML Fragment String xmlFrag = accumulateString( 2, args ); if (debug) { System.out.println( "### XML Fragment=\"" + xmlFrag + "\"" ); } // Do the insert try { // Get the document if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } // Do the insert if (debug) { System.out.println( "### Creating insert" ); } XPathInsertString xPInsert = (XPathInsertString) database.createObject( XPathInsertStringImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing insert" ); } xPInsert.insert( xPathQuery, pDoc.getDocumentElement(), xmlFrag ); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform a delete on an XML document in the database. */ private static void del( String args[] ) { // Arg format: docName xPathQuery if ( args.length < 2 ) usage( "invalid delete" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = accumulateString( 1, args ); if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // Do the delete try { // Begin Txn ExternalTransaction tx = database.newTransaction(); if (debug) { System.out.println( "### Begin" ); } tx.begin(); // Get the document if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } // Locate the delete point if (debug) { System.out.println( "### Creating query" ); } XPathQuery xPQuery = (XPathQuery) database.createObject( XPathQueryImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing query" ); } XObject result = (XObject) xPQuery.execute( xPathQuery, pDoc.getDocumentElement() ); if (result == null) { System.err.println( "Did not locate point to delete" ); return; } NodeList resultList = result.nodeset(); if (resultList.getLength() == 0) { System.err.println( "Did not locate point to delete" ); return; } // Need to delete all of them for( int idx = 0; idx < resultList.getLength(); ++idx ) { if (debug) { System.out.println( "### Delete result point idx=" + idx ); } Node delPoint = resultList.item(idx); // Fragment if (debug) { System.out.println( "### Fragment to delete" ); } listNodes( delPoint ); // Need to unlink this node from it's parent if (debug) { System.out.println( "### Get parent node" ); } Node parent = delPoint.getParentNode(); // Remove the child node if (debug) { System.out.println( "### Removing child node" ); } parent.removeChild( delPoint ); // Ask DB to delete the object //if (debug) { System.out.println( "### Delete the object" ); } //database.deleteObject ((OzoneRemote) delPoint); } // Commit if (debug) { System.out.println( "### Commit" ); } tx.commit(); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform an update on an XML document in the database. */ private static void update( String args[] ) { // Arg format: docName xPathQuery modifications if ( args.length < 3 ) usage( "invalid update" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = args[1]; if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // Update string String xmlFrag = accumulateString( 2, args ); // Do the update try { // Begin Txn ExternalTransaction tx = database.newTransaction(); if (debug) { System.out.println( "### Begin" ); } tx.begin(); // Get the document if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } // Locate the update point if (debug) { System.out.println( "### Creating query" ); } XPathQuery xPQuery = (XPathQuery) database.createObject( XPathQueryImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing query" ); } XObject result = (XObject) xPQuery.execute( xPathQuery, pDoc.getDocumentElement() ); if (result == null) { System.err.println( "Did not locate point to update" ); return; } NodeList resultList = result.nodeset(); if (resultList.getLength() == 0) { System.err.println( "Did not locate point to update" ); return; } // Parse the fragment if (debug) { System.out.println( "### Constructing XercesDOMParser" ); } XercesDOMParser xercesParser = (XercesDOMParser) new XercesDOMParser(); if (debug) { System.out.println( "### Parsing fragment into memory" ); } Document memDoc = xercesParser.parse( new InputSource( new StringReader( xmlFrag ) ) ); Node memNode = memDoc.getDocumentElement(); // Print the fragment if (debug) { System.out.println( "### Parsed fragment (in memory)" ); } listNodes( memNode ); // Need to update all of them for( int idx = 0; idx < resultList.getLength(); ++idx ) { if (debug) { System.out.println( "### Update result point idx=" + idx ); } Node updPoint = resultList.item(idx); // Fragment if (debug) { System.out.println( "### Fragment to update" ); } listNodes( updPoint ); // Now we walk both documents, applying updates from // the in-memory one to the persistent one if (debug) { System.out.println( "### Applying updates" ); } applyUpdates( memNode, updPoint, pDoc ); // Show the updates if (debug) { System.out.println( "### Updated tree" ); } listNodes( updPoint ); } // Commit if (debug) { System.out.println( "### Commit" ); } tx.commit(); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Perform an update on an XML document in the database. */ private static void xupdate( String args[] ) { // Arg format: docName xPathQuery modifications if ( args.length < 3 ) usage( "invalid xupdate" ); // Document name String docName = args[0]; if (debug) { System.out.println( "### Document=\"" + docName + "\"" ); } // Query string String xPathQuery = args[1]; if (debug) { System.out.println( "### Query=\"" + xPathQuery + "\"" ); } // Update string String xmlFrag = accumulateString( 2, args ); // Do the update try { // Get the document if (debug) { System.out.println( "### Checking for existance" ); } Document pDoc = (Document) database.objectForName( docName ); if ( pDoc == null ) { System.err.println( "Document does not exist" ); return; } // Do the update if (debug) { System.out.println( "### Creating update" ); } XPathUpdateString xPUpdate = (XPathUpdateString) database.createObject( XPathUpdateStringImpl.class.getName(), 0, null ); if (debug) { System.out.println( "### Executing update" ); } xPUpdate.update( xPathQuery, pDoc.getDocumentElement(), xmlFrag ); if (debug) { System.out.println( "### Done" ); } } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); } } /** Generic manipulation tool */ public static void main(String args[]) { // Parse '--' arguments int argp = 0; String arg; for( argp = 0; argp < args.length; ++argp ) { arg = args[argp]; if ( arg.length() == 0 ) continue; if ( arg.equals( "--" ) ) break; if ( arg.charAt(0) != '-' ) break; // -d if ( arg.equals( "-d" ) ) { debug = true; continue; } // -h hostname if ( arg.equals( "-h" ) ) { ++argp; if ( argp >= args.length ) usage( "host name not specified" ); hostname = args[argp]; continue; } // -p port if ( arg.equals( "-p" ) ) { ++argp; if ( argp >= args.length ) usage( "port number not specified" ); try { port = Integer.parseInt( args[argp] ); } catch (NumberFormatException e) { usage( "invalid port number - " + args[argp] ); } continue; } // Anything else is wrong usage( "invalid argument - " + arg ); } // Need at least one argument to determine what to do if ( argp >= args.length ) usage( "task missing" ); arg = args[argp++]; if (debug) { System.out.println( "### arg=" + arg ); } // Initialize the database try { // open the connection on localhost at port if (debug) { System.out.println( "### Open DB connection to " + hostname + "[" + port + "]" ); } database.open( hostname, port ); // reload our database classes if we changed them if (debug) { System.out.println( "### Reload DB classes" ); } database.reloadClasses(); } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); System.exit( 1 ); } // Perform a query if ( arg.equalsIgnoreCase( "query" ) ) query( sliceFrom( argp, args ) ); if ( arg.equalsIgnoreCase( "xquery" ) ) xquery( sliceFrom( argp, args ) ); // Store a document if ( arg.equalsIgnoreCase( "store" ) ) store( sliceFrom( argp, args ) ); // Remove a document if ( arg.equalsIgnoreCase( "remove" ) ) remove( sliceFrom( argp, args ) ); // Insert an XML fragment if ( arg.equalsIgnoreCase( "insert" ) ) insert( sliceFrom( argp, args ) ); if ( arg.equalsIgnoreCase( "xinsert" ) ) xinsert( sliceFrom( argp, args ) ); // Delete a fragment if ( arg.equalsIgnoreCase( "delete" ) ) del( sliceFrom( argp, args ) ); // Update a fragment if ( arg.equalsIgnoreCase( "update" ) ) update( sliceFrom( argp, args ) ); if ( arg.equalsIgnoreCase( "xupdate" ) ) xupdate( sliceFrom( argp, args ) ); // Close the DB try { // open the connection on localhost at port if (debug) { System.out.println( "### Closing the DB" ); } database.close(); } catch (Exception except) { System.err.println( "Caught exception:" ); except.printStackTrace(); System.exit( 1 ); } // Done System.exit( 0 ); } }