com.marklogic.xdmp
Class XDMPDataSource

java.lang.Object
  extended bycom.marklogic.xdmp.XDMPDataSource

public class XDMPDataSource
extends Object

A DataSource for creating connections to a specific XDMP database. This class provides all the methods from javax.sql.DataSource, but doesn't actually implement that interface, since XDMP is fundamentally not a SQL datasource.

An XDMPDataSource object can be bound to a JNDI Context in the standard way. It can then be used by applications to get XDBCConnections without referencing hosts, ports, and other information directly from the code.


Constructor Summary
XDMPDataSource()
          Construct a new XDMPDataSource object.
XDMPDataSource(String host, int port)
          Construct a new XDMPDataSource object.
 
Method Summary
 XDBCConnection getConnection()
          Attempts to establish a connection with the data source that this DataSource object represents.
 XDBCConnection getConnection(String username, String password)
          Attempts to establish a connection with the data source that this DataSource object represents.
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 PrintWriter getLogWriter()
          Retrieves the log writer for this DataSource object.
 void setHost(String host)
          Sets the hostname for connections created from this datasource.
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(PrintWriter out)
          Sets the log writer for this DataSource object to the given java.io.PrintWriter object.
 void setPassword(String password)
          Sets the password for connections created from this datasource.
 void setPort(int port)
          Sets the port number for connections created from this datasource.
 void setUserName(String username)
          Sets the username for connections created from this datasource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XDMPDataSource

public XDMPDataSource()
               throws XDBCException
Construct a new XDMPDataSource object.

Throws:
XDBCException - if the datasource cannot be created.

XDMPDataSource

public XDMPDataSource(String host,
                      int port)
               throws XDBCException
Construct a new XDMPDataSource object.

Parameters:
host - the hostname to use when creating connections.
port - the port number to use when creating connections.
Throws:
XDBCException - if the datasource cannot be created.
Method Detail

getConnection

public XDBCConnection getConnection()
                             throws XDBCException
Attempts to establish a connection with the data source that this DataSource object represents.

Returns:
an XDBCConnection to the datasource.
Throws:
XDBCException - if the connection cannot be made.

getConnection

public XDBCConnection getConnection(String username,
                                    String password)
                             throws XDBCException
Attempts to establish a connection with the data source that this DataSource object represents.

Parameters:
username - a String username for authenticating the connection.
password - a String password for authenticating the connection.
Returns:
an XDBCConnection to the datasource.
Throws:
XDBCException - if the connection cannot be made.

getLoginTimeout

public int getLoginTimeout()
                    throws XDBCException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.

Returns:
the integer number of seconds to wait.
Throws:
XDBCException - if the timeout cannot be determined.

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws XDBCException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.

Parameters:
seconds - the integer number of seconds to wait.
Throws:
XDBCException - if the timeout cannot be set.

getLogWriter

public PrintWriter getLogWriter()
                         throws XDBCException
Retrieves the log writer for this DataSource object.

Returns:
the PrintWriter log output object.
Throws:
XDBCException - if the PrintWriter cannot be retrieved.

setLogWriter

public void setLogWriter(PrintWriter out)
                  throws XDBCException
Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

Parameters:
out - the PrintWriter to use for logging.
Throws:
XDBCException - if the PrintWriter cannot be set.

setUserName

public void setUserName(String username)
Sets the username for connections created from this datasource.

Parameters:
username - the String username for authenticating connections.

setPassword

public void setPassword(String password)
Sets the password for connections created from this datasource.

Parameters:
password - the String password for authenticating connections.

setHost

public void setHost(String host)
Sets the hostname for connections created from this datasource.

Parameters:
host - the String host to connect to.

setPort

public void setPort(int port)
Sets the port number for connections created from this datasource.

Parameters:
port - the integer port number to connect to.