net.xqj.basex
Class BaseXXQDataSource

java.lang.Object
  extended by GenericXQDataSource
      extended by net.xqj.basex.BaseXXQDataSource
All Implemented Interfaces:
XQDataSource

public class BaseXXQDataSource
extends GenericXQDataSource
implements XQDataSource

BaseX XQDataSource Implementation

This implementation internally creates Socket connections with a BaseX Server. Socket connections are persistent and stateful.

By default, BaseX listens for incoming connections on port "1984".


Constructor Summary
BaseXXQDataSource()
          Creates a new instance of a BaseXXQDataSource.
 
Method Summary
 XQConnection getConnection()
          Creates an XQConnection / XQConnection2 instance.
 XQConnection getConnection(Connection con)
          Deprecated.  
 XQConnection getConnection(String username, String passwd)
          Creates a XQConnection / / XQConnection2 instance manually specifying user credentials.
 String getDatabaseName()
          Get the name of the target Database.
 String getPassword()
          Gets the password value of this BaseXXQDataSource
 int getPort()
          Get the target port of the BaseX Server.
 String getProperty(String name)
          Returns the current value of the named property if set, else null.
 String getServerName()
          Gets the BaseX Server's name, which will be a hostname or an IP address.
 String[] getSupportedPropertyNames()
          Returns an array containing the property names supported by this XQDataSource.
 String getUser()
          Gets the user value of this BaseXXQDataSource
 void setDatabaseName(String databaseName)
          Set the BaseX Server's target Database.
 void setPassword(String password)
          Sets the password value of this BaseXXQDataSource
 void setPort(int port)
          Sets the target port of the BaseX Server.
 void setPort(String port)
          Sets the target port of the BaseX Server.
 void setProperty(String name, String value)
          Sets the named property to the specified value.
 void setServerName(String serverName)
          Sets the BaseX Server's name
 void setUser(String user)
          Sets the user value of this BaseXXQDataSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.xml.xquery.XQDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter, setProperties
 

Constructor Detail

BaseXXQDataSource

public BaseXXQDataSource()

Creates a new instance of a BaseXXQDataSource.

Some default properties are given to the XQDataSource

Method Detail

getConnection

public XQConnection getConnection()
                           throws XQException

Creates an XQConnection / XQConnection2 instance. Credentials must have already been defined.

The XQConnection instance returned from this method may be cast into a XQConnection2.

Consider the following code:

XQConnection2 conn = (XQConnection2)BaseXXQDataSourceInstance.getConnection();

Specified by:
getConnection in interface XQDataSource
Returns:
an instance of XQConnection / XQConnection2.
Throws:
XQException - if a datasource access error occurs
See Also:
XQConnection2

getConnection

public XQConnection getConnection(String username,
                                  String passwd)
                           throws XQException

Creates a XQConnection / / XQConnection2 instance manually specifying user credentials.

The XQConnection instance returned from this method may be cast into a XQConnection2.

Consider the following code:

XQConnection2 conn = (XQConnection2)BaseXXQDataSourceInstance.getConnection("user","password");

Specified by:
getConnection in interface XQDataSource
Parameters:
username - the username which will be used when communicating with the BaseX Server.
passwd - the password which will be used when communicating with the BaseX Server.
Returns:
an instance of XQConnection / XQConnection2.
Throws:
XQException - if a datasource access error occurs
See Also:
XQConnection2

setServerName

public void setServerName(String serverName)
Sets the BaseX Server's name

Parameters:
serverName - the BaseX Server's name, this can be a hostname or an IP address.

getServerName

public String getServerName()
Gets the BaseX Server's name, which will be a hostname or an IP address.

Returns:
BaseX Server's hostname or IP address.

setDatabaseName

public void setDatabaseName(String databaseName)
Set the BaseX Server's target Database.

Parameters:
databaseName - the name of the Database which queries run against.

getDatabaseName

public String getDatabaseName()
Get the name of the target Database.

Returns:
the name of the target Database which queries run against.

setUser

public void setUser(String user)
Sets the user value of this BaseXXQDataSource

Parameters:
user - a username which will be sent to an Basex server.

getUser

public String getUser()
Gets the user value of this BaseXXQDataSource

Returns:
The username this BaseXXQDataSource is using to send to an BaseX Server.

setPassword

public void setPassword(String password)
Sets the password value of this BaseXXQDataSource

Parameters:
password - a password which will be sent to an BaseX server.

getPassword

public String getPassword()
Gets the password value of this BaseXXQDataSource

Returns:
The password this BaseXXQDataSource is using to send to an BsaeX Server.

setPort

public void setPort(int port)
Sets the target port of the BaseX Server.

Parameters:
port - the BaseX Server port

setPort

public void setPort(String port)
             throws XQException
Sets the target port of the BaseX Server.

Parameters:
port - the BaseX Server port
Throws:
XQException - if the supplied port is not a valid port.

getPort

public int getPort()
Get the target port of the BaseX Server.

Returns:
the current port defined in this BaseXXQDataSource

getSupportedPropertyNames

public String[] getSupportedPropertyNames()
Description copied from interface: XQDataSource
Returns an array containing the property names supported by this XQDataSource. Implementations that support user name and password must recognize the user name and password properties listed below.

user the user name to use for creating a connection
password the password to use for creating a connection

Any additional properties are implementation-defined.

Specified by:
getSupportedPropertyNames in interface XQDataSource
Returns:
String[] an array of property names supported by this implementation

setProperty

public void setProperty(String name,
                        String value)
                 throws XQException
Description copied from interface: XQDataSource
Sets the named property to the specified value. If a property with the same name was already set, then this method will override the old value for that property with the new value.

If the implementation does not support the given property or if it can determine that the value given for this property is invalid, then an exception is thrown. If an exception is thrown, then no previous value is overwritten.

Specified by:
setProperty in interface XQDataSource
Parameters:
name - the name of the property to set
value - the value of the named property
Throws:
XQException - if (1) the given property is not recognized, (2) the value for the given property is determined to be invalid, or (3) the name parameter is null

getProperty

public String getProperty(String name)
                   throws XQException
Description copied from interface: XQDataSource
Returns the current value of the named property if set, else null. If the implementation does not support the given property then an exception is raised.

Specified by:
getProperty in interface XQDataSource
Parameters:
name - the name of the property whose value is needed
Returns:
String representing the value of the required property if set, else null
Throws:
XQException - if (1) a given property is not supported, or (2) the name parameter is null

getConnection

public XQConnection getConnection(Connection con)
                           throws XQException
Deprecated. 

Calling this method will throw an XQException. BaseX XQConnections can not be built from JDBC Connections.

Specified by:
getConnection in interface XQDataSource
Parameters:
con - an existing JDBC connection
Returns:
a connection to the XML datasource
Throws:
XQException - calling this method will throw an XQException