xtc.driver
Class XTCconnection

java.lang.Object
  extended by xtc.driver.XTCconnection

public class XTCconnection
extends Object


Nested Class Summary
(package private)  class XTCconnection.ResponseThread
           
 
Field Summary
private  XTCconnectionID connectionID
           
private  String currentDirectoryPath
           
private  String host
           
private  int isolationLevel
           
static int ISOLATIONLEVEL_COMMITTED
           
static int ISOLATIONLEVEL_NONE
           
static int ISOLATIONLEVEL_REPEATABLE
           
static int ISOLATIONLEVEL_SERIALIZABLE
           
static int ISOLATIONLEVEL_UNCOMMITTED
           
private  int lockDepth
           
static int LOCKDEPTH_MAX
           
private  int maxQueryTokens
           
private  int port
           
private  XTCconnection.ResponseThread responseThread
           
private  boolean singleStatementCommit
           
private  XTCtransaction transaction
           
private  XTCapiRmi xtcApiRmi
           
private  XTCdomRmi xtcDomRmi
           
private  XTCsaxRmi xtcSaxRmi
           
 
Constructor Summary
XTCconnection(String host, int port, XTCconnectionID connectionID, XTCapiRmi xtcApiRmi)
          Do not invoke this method directly.
 
Method Summary
 void beginWork(String transactionName)
          Starts a new transaction and keeps the transaction context until method commitWork or rollbackWork is invoked.
 void beginWork(String transactionName, boolean logged)
          Starts a new transaction and keeps the transaction context until method commitWork or rollbackWork is invoked.
 void changeDirectory(String newDirectory)
          Changes the current working directory.
 void close()
          Closes the database connection.
 void commitWork()
          Commits the currently running transaction or throws an XTCexception if no transaction is currently running.
 void createDirectory(String directory)
          Creates a directory in the database.
 String createIndexes(String storedDocumentPath, File indexDefinitionFile)
          Creates indexes for the given document.
 void delete(String name)
          Deletes a document.
 void deleteXmlStats(String storedXmlDocument)
           
 void estimateXPath(String storedXmlDocument, String expression)
           
 String executeQuery(String query)
          Executes a clp command.
 Node executeXPath(Document document, String xpathExpression)
          Executes an XPath expression on the given document.
 XTCxqueryResult executeXQuery(Document document, String xquery, boolean materialize, boolean updateable)
          Executes an XQuery expression on the given document.
 XTCxqueryResult executeXQuery(String xquery, boolean materialize, boolean updateable)
          Executes an XQuery expression.
 void getBlob(String storedBlob, String destFilename)
          Loads the storedBlob from the database and writes it into a new file named destFilename.
 String getCurrentDirectory()
          Returns the current working directory.
 Document getDocument(String storedDocument)
          Returns the document for the given document name as a DOM Document node.
 void getDocument(String storedDocument, String destFilename)
          Loads a the storedDocument from the server and writes it into a new File of name destFilename.
private  void getDocumentViaGetSaxNodes(String storedDocument, String destFilename)
           
private  StringBuffer getIndention(int size)
           
 int getIsolationLevel()
          Returns the currently set isolation level.
 int getLockDepth()
          Returns the currently set lock depth.
 int getTransactionID()
          Returns the ID of the currently running transaction in this connection.
 boolean isInTransaction()
          Returns if this connection is currently working within a transaction or not.
 String listDirectory()
          Lists the contents of the current working directory.
 String listIndexes(String storedDocumentPath)
          Returns a String containing a summary of all indexes available for the given document.
private  void printNodeList(ArrayList<XTCnode> list)
           
 void putBlob(File localFile, String destBlob)
          Stores a blob contained in the given localFile into the database.
 void putCollection(File localDirectory, String destDirectory, boolean storeElementless)
          Puts a collection residing in the localDirectory into the destDirectory on the server.
 void putDocument(File localFile, String destDocument, boolean storeElementless)
          Puts the local file as destDocument in the database.
 void putServerCollection(File localDirectory, String destDirectory, boolean storeElementless)
          Puts a collection already residing on the server into the database.
 void putServerDocument(String serverFileName, String destDocument, boolean storeElementless)
          Puts the given document already residing on the server machine into the database.
 void removeDirectory(String directory)
          Removes a directory from the database.
 void rename(String oldName, String newName)
          Renames a document in the database.
 void renameDirectory(String oldDirectory, String newDirectory)
          Renames a directory from the database.
 void rollbackWork()
          Aborts the currently running transaction or throws an XTCexception if no transaction is currently running.
 double runXmlStats(String storedXmlDocument)
           
 double runXmlStats(String storedXmlDocument, String histogramType)
           
 void saxParse(Document document, ContentHandler contentHandler)
          Issues a SAX parse on the given document with the given contentHandler.
 void setIsolationLevel(int isolationLevel)
          Sets the new isolation level.
 void setLockDepth(int lockDepth)
          Sets the lock depth.
private  String storeTempFile(File localFile)
           
private  void testHook(String storedDocument)
           
 void viewXmlStats(String storedXmlDocument)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ISOLATIONLEVEL_NONE

public static final int ISOLATIONLEVEL_NONE
See Also:
Constant Field Values

ISOLATIONLEVEL_UNCOMMITTED

public static final int ISOLATIONLEVEL_UNCOMMITTED
See Also:
Constant Field Values

ISOLATIONLEVEL_COMMITTED

public static final int ISOLATIONLEVEL_COMMITTED
See Also:
Constant Field Values

ISOLATIONLEVEL_REPEATABLE

public static final int ISOLATIONLEVEL_REPEATABLE
See Also:
Constant Field Values

ISOLATIONLEVEL_SERIALIZABLE

public static final int ISOLATIONLEVEL_SERIALIZABLE
See Also:
Constant Field Values

LOCKDEPTH_MAX

public static final int LOCKDEPTH_MAX
See Also:
Constant Field Values

isolationLevel

private int isolationLevel

lockDepth

private int lockDepth

host

private String host

port

private int port

connectionID

private XTCconnectionID connectionID

transaction

private XTCtransaction transaction

singleStatementCommit

private boolean singleStatementCommit

currentDirectoryPath

private String currentDirectoryPath

xtcApiRmi

private XTCapiRmi xtcApiRmi

xtcDomRmi

private XTCdomRmi xtcDomRmi

xtcSaxRmi

private XTCsaxRmi xtcSaxRmi

responseThread

private XTCconnection.ResponseThread responseThread

maxQueryTokens

private final int maxQueryTokens
See Also:
Constant Field Values
Constructor Detail

XTCconnection

XTCconnection(String host,
              int port,
              XTCconnectionID connectionID,
              XTCapiRmi xtcApiRmi)
        throws XTCexception
Do not invoke this method directly. This method is called by XTCdriver for creating a new connection object.

Throws:
XTCexception
Method Detail

setIsolationLevel

public void setIsolationLevel(int isolationLevel)
                       throws XTCexception
Sets the new isolation level. Possible values are ISOLATIONLEVEL_NONE, ISOLATIONLEVEL_UNCOMMITTED, ISOLATIONLEVEL_COMMITTED, ISOLATIONLEVEL_REPEATABLE, or ISOLATIONLEVEL_SERIALIZABLE. The new isolation level is used by the next transaction started by this connection.

Parameters:
isolationLevel - The new isolation level for the next transaction.
Throws:
XTCexception

getIsolationLevel

public int getIsolationLevel()
Returns the currently set isolation level.

Returns:
One of the possible isolation levels ISOLATIONLEVEL_NONE, ISOLATIONLEVEL_UNCOMMITTED, ISOLATIONLEVEL_COMMITTED, ISOLATIONLEVEL_REPEATABLE, or ISOLATIONLEVEL_SERIALIZABLE is returned.

setLockDepth

public void setLockDepth(int lockDepth)
                  throws XTCexception
Sets the lock depth. The lock depth defines the level downto which locks are requested. For example, lock depth 1 only requests locks on the document root node and all its children. Lock depth -1 (default value) requests locks on all nodes of the document.

Parameters:
lockDepth - The new lock depth.
Throws:
XTCexception

getLockDepth

public int getLockDepth()
Returns the currently set lock depth.

Returns:
The currently set lock depth value.

getTransactionID

public int getTransactionID()
Returns the ID of the currently running transaction in this connection.

Returns:
The current transaction ID or -1 if no transaction is running in this connection.

isInTransaction

public boolean isInTransaction()
Returns if this connection is currently working within a transaction or not.

Returns:
True or false - working in a transaction?

beginWork

public void beginWork(String transactionName)
               throws XTCexception
Starts a new transaction and keeps the transaction context until method commitWork or rollbackWork is invoked.

Parameters:
transactionName -
Throws:
XTCexception

beginWork

public void beginWork(String transactionName,
                      boolean logged)
               throws XTCexception
Starts a new transaction and keeps the transaction context until method commitWork or rollbackWork is invoked.

Parameters:
transactionName - A name with which the transaction appears in the server's transaction list.
logged - sets the log-mode of this transaction
Throws:
XTCexception

commitWork

public void commitWork()
                throws XTCexception
Commits the currently running transaction or throws an XTCexception if no transaction is currently running.

Throws:
XTCexception

rollbackWork

public void rollbackWork()
                  throws XTCexception
Aborts the currently running transaction or throws an XTCexception if no transaction is currently running.

Throws:
XTCexception

runXmlStats

public double runXmlStats(String storedXmlDocument,
                          String histogramType)
                   throws XTCexception
Throws:
XTCexception

runXmlStats

public double runXmlStats(String storedXmlDocument)
                   throws XTCexception
Throws:
XTCexception

viewXmlStats

public void viewXmlStats(String storedXmlDocument)
                  throws XTCexception
Throws:
XTCexception

deleteXmlStats

public void deleteXmlStats(String storedXmlDocument)
                    throws XTCexception
Throws:
XTCexception

estimateXPath

public void estimateXPath(String storedXmlDocument,
                          String expression)
                   throws XTCexception
Throws:
XTCexception

executeXPath

public Node executeXPath(Document document,
                         String xpathExpression)
                  throws DOMException
Executes an XPath expression on the given document.

Throws:
DOMException

executeXQuery

public XTCxqueryResult executeXQuery(Document document,
                                     String xquery,
                                     boolean materialize,
                                     boolean updateable)
                              throws DOMException
Executes an XQuery expression on the given document. The given document can be referenced inside the 'doc' function with ".". If the result itself is a document and materialize is true, then the document is materialized in the database and a node referencing this document is returned. If additionally updateable is true, only newly constructed nodes are materialized and existing ones (selected by the query) are stored in referenced mode (updates on the query result affect the source document; does not work in elementless mode).

Parameters:
document -
xquery -
materialize -
updateable -
Returns:
Throws:
DOMException

executeXQuery

public XTCxqueryResult executeXQuery(String xquery,
                                     boolean materialize,
                                     boolean updateable)
                              throws DOMException
Executes an XQuery expression. If the result itself is a document and materialize is true, then the document is materialized in the database and a node referencing this document is returned. If additionally updateable is true, only newly constructed nodes are materialized and existing ones (selected by the query) are stored in referenced mode (updates on the query result affect the source document; does not work in elementless mode).

Parameters:
xquery -
materialize -
updateable -
Returns:
Throws:
DOMException

getDocument

public Document getDocument(String storedDocument)
                     throws XTCexception
Returns the document for the given document name as a DOM Document node.

Parameters:
storedDocument -
Returns:
Throws:
XTCexception

putDocument

public void putDocument(File localFile,
                        String destDocument,
                        boolean storeElementless)
                 throws XTCexception
Puts the local file as destDocument in the database. The file is copied to the server first. If storeElementless is true, then inner elements are virtualized (using a structural summary).

Throws:
XTCexception

listIndexes

public String listIndexes(String storedDocumentPath)
                   throws XTCexception
Returns a String containing a summary of all indexes available for the given document.

Parameters:
storedDocumentPath -
Returns:
Throws:
XTCexception

createIndexes

public String createIndexes(String storedDocumentPath,
                            File indexDefinitionFile)
                     throws XTCexception
Creates indexes for the given document. The indexes have to be defined in an indexDefinitionFile.

Parameters:
storedDocumentPath -
indexDefinitionFile -
Returns:
Throws:
XTCexception

putServerDocument

public void putServerDocument(String serverFileName,
                              String destDocument,
                              boolean storeElementless)
                       throws XTCexception
Puts the given document already residing on the server machine into the database.

Throws:
XTCexception

putCollection

public void putCollection(File localDirectory,
                          String destDirectory,
                          boolean storeElementless)
                   throws XTCexception
Puts a collection residing in the localDirectory into the destDirectory on the server.

Parameters:
localDirectory -
destDirectory -
storeElementless -
Throws:
XTCexception

putServerCollection

public void putServerCollection(File localDirectory,
                                String destDirectory,
                                boolean storeElementless)
                         throws XTCexception
Puts a collection already residing on the server into the database.

Parameters:
localDirectory -
destDirectory -
storeElementless -
Throws:
XTCexception

putBlob

public void putBlob(File localFile,
                    String destBlob)
             throws XTCexception
Stores a blob contained in the given localFile into the database.

Parameters:
localFile -
destBlob -
Throws:
XTCexception

getDocument

public void getDocument(String storedDocument,
                        String destFilename)
                 throws XTCexception
Loads a the storedDocument from the server and writes it into a new File of name destFilename.

Parameters:
storedDocument -
destFilename -
Throws:
XTCexception

testHook

private void testHook(String storedDocument)
               throws XTCexception
Throws:
XTCexception

getDocumentViaGetSaxNodes

private void getDocumentViaGetSaxNodes(String storedDocument,
                                       String destFilename)
                                throws XTCexception
Throws:
XTCexception

printNodeList

private void printNodeList(ArrayList<XTCnode> list)

getIndention

private StringBuffer getIndention(int size)

getBlob

public void getBlob(String storedBlob,
                    String destFilename)
             throws XTCexception
Loads the storedBlob from the database and writes it into a new file named destFilename.

Parameters:
storedBlob -
destFilename -
Throws:
XTCexception

rename

public void rename(String oldName,
                   String newName)
            throws XTCexception
Renames a document in the database.

Parameters:
oldName -
newName -
Throws:
XTCexception

delete

public void delete(String name)
            throws XTCexception
Deletes a document. Deletion from collections is not implemented yet.

Parameters:
name -
Throws:
XTCexception

createDirectory

public void createDirectory(String directory)
                     throws XTCexception
Creates a directory in the database.

Parameters:
directory -
Throws:
XTCexception

removeDirectory

public void removeDirectory(String directory)
                     throws XTCexception
Removes a directory from the database.

Parameters:
directory -
Throws:
XTCexception

renameDirectory

public void renameDirectory(String oldDirectory,
                            String newDirectory)
                     throws XTCexception
Renames a directory from the database.

Parameters:
oldDirectory -
newDirectory -
Throws:
XTCexception

changeDirectory

public void changeDirectory(String newDirectory)
                     throws XTCexception
Changes the current working directory.

Parameters:
newDirectory -
Throws:
XTCexception

getCurrentDirectory

public String getCurrentDirectory()
Returns the current working directory.

Returns:

listDirectory

public String listDirectory()
                     throws XTCexception
Lists the contents of the current working directory.

Returns:
Throws:
XTCexception

close

public void close()
Closes the database connection.


storeTempFile

private String storeTempFile(File localFile)
                      throws XTCexception
Throws:
XTCexception

executeQuery

public String executeQuery(String query)
                    throws XTCexception
Executes a clp command.

Parameters:
query -
Returns:
Throws:
XTCexception

saxParse

public void saxParse(Document document,
                     ContentHandler contentHandler)
              throws XTCexception
Issues a SAX parse on the given document with the given contentHandler.

Parameters:
document -
contentHandler -
Throws:
XTCexception