Esri Geoportal Server
1.0

com.esri.gpt.framework.sql
Class DatabaseReference

java.lang.Object
  extended by com.esri.gpt.framework.sql.DatabaseReference

public final class DatabaseReference
extends Object

Configuration reference for a database.

The reference usually represents a JNDI based connection. It can also represent a direct connection (driver/url/user/pwd), but this is usually limited to a non-production environment.


Constructor Summary
DatabaseReference()
          Default constructor.
 
Method Summary
 void closeConnection(Connection con)
          Closes a JDBC connection.
 String getDirectDriverClassName()
          Gets the driver class name for a direct database reference.
 String getDirectPassword()
          Gets the password for a direct database reference.
 String getDirectUrl()
          Gets the URL for a direct database reference.
 String getDirectUsername()
          Gets the username for a direct database reference.
 boolean getIsJndiBased()
          Gets the JNDI based reference status.
protected  DataSource getJndiDataSource()
          Gets the JNDI based DataSource for the reference.
 String getJndiName()
          Gets the name for a JNDI based database reference.
protected  String getReferenceLabel()
          Gets the label for the database reference.
 String getReferenceName()
          Gets the name for the database reference.
 StringSet getTags()
          Gets the tags associated with the reference.
 Connection openConnection()
          Makes a JDBC connection from based upon the configuration of the database reference.
protected  Connection openDirectConnection()
          Opens a direct JDBC connection based upon the driver, url, username and password.
protected  Connection openJndiConnection()
          Opens a JDBC connection from the JNDI DataSource associated with the JNDI name.
protected  DataSource openJndiDataSource(String jndiName)
          Opens the DataSource associated with the JNDI name.
 void setDirectDriverClassName(String driver)
          Sets the driver class name for a direct database reference.
 void setDirectPassword(String password)
          Sets the password for a direct database reference.
 void setDirectUrl(String url)
          Sets the URL for a direct database reference.
 void setDirectUsername(String username)
          Sets the username for a direct database reference.
 void setIsJndiBased(boolean isJndiBased)
          Sets the JNDI based reference status.
 void setJndiName(String jndiName)
          Sets the name for a JNDI based database reference.
 void setReferenceName(String referenceName)
          Sets the name for the database reference.
protected  void testConnection()
          Tests the connection associated with the database reference.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabaseReference

public DatabaseReference()
Default constructor.

Method Detail

getDirectDriverClassName

public String getDirectDriverClassName()
Gets the driver class name for a direct database reference.

Returns:
the database driver class name

setDirectDriverClassName

public void setDirectDriverClassName(String driver)
Sets the driver class name for a direct database reference.

Parameters:
driver - the database driver class name

getDirectPassword

public String getDirectPassword()
Gets the password for a direct database reference.

Returns:
the password

setDirectPassword

public void setDirectPassword(String password)
Sets the password for a direct database reference.

Parameters:
password - the password

getDirectUrl

public String getDirectUrl()
Gets the URL for a direct database reference.

Returns:
the database url

setDirectUrl

public void setDirectUrl(String url)
Sets the URL for a direct database reference.

Parameters:
url - the database url

getDirectUsername

public String getDirectUsername()
Gets the username for a direct database reference.

Returns:
the username

setDirectUsername

public void setDirectUsername(String username)
Sets the username for a direct database reference.

Parameters:
username - the username

getIsJndiBased

public boolean getIsJndiBased()
Gets the JNDI based reference status.

Returns:
true if this reference is JNDI based

setIsJndiBased

public void setIsJndiBased(boolean isJndiBased)
Sets the JNDI based reference status.

Parameters:
isJndiBased - true if this reference is JNDI based

getJndiDataSource

protected DataSource getJndiDataSource()
                                throws NamingException
Gets the JNDI based DataSource for the reference.

Returns:
the data source
Throws:
NamingException - if a JNDI naming exception occurs

getJndiName

public String getJndiName()
Gets the name for a JNDI based database reference.

Returns:
the JNDI name

setJndiName

public void setJndiName(String jndiName)
Sets the name for a JNDI based database reference.

Parameters:
jndiName - the JNDI name

getReferenceLabel

protected String getReferenceLabel()
Gets the label for the database reference.

Returns:
the reference label

getReferenceName

public String getReferenceName()
Gets the name for the database reference.

Returns:
the name

setReferenceName

public void setReferenceName(String referenceName)
Sets the name for the database reference.

Parameters:
referenceName - the reference name

getTags

public StringSet getTags()
Gets the tags associated with the reference.

Returns:
the associated tags

closeConnection

public void closeConnection(Connection con)
Closes a JDBC connection.
Executes the close() method against the JDBC connection.

Parameters:
con - the connection to close

openConnection

public Connection openConnection()
                          throws ClassNotFoundException,
                                 NamingException,
                                 SQLException
Makes a JDBC connection from based upon the configuration of the database reference.

Returns:
the JDBC connection
Throws:
ClassNotFoundException - if the database driver class was not found
NamingException - if a JNDI naming exception occurs
SQLException - if an SQL exception occurs while establishing the connection

openDirectConnection

protected Connection openDirectConnection()
                                   throws ClassNotFoundException,
                                          SQLException
Opens a direct JDBC connection based upon the driver, url, username and password.

Returns:
the JDBC connection
Throws:
ClassNotFoundException - if the database driver class was not found
SQLException - if an SQL exception occurs while establishing the connection

openJndiConnection

protected Connection openJndiConnection()
                                 throws NamingException,
                                        SQLException
Opens a JDBC connection from the JNDI DataSource associated with the JNDI name.

Returns:
the JDBC connection
Throws:
NamingException - if a JNDI naming exception occurs
SQLException - if an SQL exception occurs while establishing the connection

openJndiDataSource

protected DataSource openJndiDataSource(String jndiName)
                                 throws NamingException
Opens the DataSource associated with the JNDI name.

Parameters:
jndiName - the associated JNDI name
Returns:
the associated data source
Throws:
NamingException - if a JNDI naming exception occurs

testConnection

protected void testConnection()
Tests the connection associated with the database reference.
A connection is opened, then immediately closed.


toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
the string

Esri Geoportal Server
1.0

Copyright 2011 Environmental Systems Research Institute. All rights reserved. Use is subject to license terms.