org.geotools.referencing.factory.epsg
Class SimpleDataSource

java.lang.Object
  extended byorg.geotools.referencing.factory.epsg.SimpleDataSource
All Implemented Interfaces:
DataSource, javax.sql.DataSource

public class SimpleDataSource
extends java.lang.Object
implements DataSource

Open a connection to an EPSG database using DriverManager. This implementation is not suitable for uses with Java Naming and Directory (JNDI), but it provides a convenient base class for connections determined from properties files.

The default implementation doesn't make any assumption about where the properties file is located. The properties file location must be supplied at construction time. Because this base class dosn't have a no-argument constructor, it can't be registered in the directory. If such a registration is wanted (for automatic detection by FactoryFinder, then users must provide a subclass with a no-argument constructor.

The properties file to be supplied at construction time shall contains the following:

Property Description Default
The URL to the EPSG database
The schema containing EPSG tables in the database
User used to make database connections
Password used to make database connections
The JDBC driver to load
The EPSG factory to instantiate

Since:
2.2
Version:
$Id: SimpleDataSource.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Field Summary
protected  java.util.Properties properties
          The properties used for etablishing the database connection.
 
Fields inherited from interface org.geotools.referencing.factory.epsg.DataSource
MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY
 
Constructor Summary
SimpleDataSource(java.io.File file)
          Constructs a data source with properties loaded from the specified file.
SimpleDataSource(java.util.Properties properties)
          Constructs a data source with the specified properties.
 
Method Summary
 AbstractAuthorityFactory createFactory(Hints hints)
          Opens a connection and creates an EPSG factory for it.
 java.sql.Connection getConnection()
          Attempts to establish a connection with the data source.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempts to establish a connection with the data source.
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Retrieves the log writer.
 int getPriority()
          Returns the priority for this data source.
 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(java.io.PrintWriter out)
          Sets the log writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected final java.util.Properties properties
The properties used for etablishing the database connection. See the class description for the expected content. This field is never .

Constructor Detail

SimpleDataSource

public SimpleDataSource(java.util.Properties properties)
Constructs a data source with the specified properties. The properties given to this constructor are not cloned.

Parameters:
properties - The properties, or for an empty set.

SimpleDataSource

public SimpleDataSource(java.io.File file)
                 throws java.io.IOException
Constructs a data source with properties loaded from the specified file.

Parameters:
file - The properties file to load.
Throws:
java.io.IOException - if an error occured while loading the properties file.
Method Detail

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Retrieves the log writer. The default implementation delegates to the DriverManager, which returns a system-wide logger.

Specified by:
getLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Sets the log writer. The default implementation delegates to the DriverManager, which have a system-wide effect.

Specified by:
setLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. The default implementation returns zero, which means that the timeout is the default system timeout .

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Throws:
java.sql.SQLException

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. The default implementation does nothing.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getPriority

public int getPriority()
Returns the priority for this data source. The default implementation returns NORMAL_PRIORITY.

Specified by:
getPriority in interface DataSource

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempts to establish a connection with the data source.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
A connection to the data source.
Throws:
java.sql.SQLException - if a database access error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempts to establish a connection with the data source.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username - The database user on whose behalf the connection is being made.
password - The user's password.
Returns:
A connection to the data source.
Throws:
java.sql.SQLException - if a database access error occurs.

createFactory

public AbstractAuthorityFactory createFactory(Hints hints)
                                       throws java.sql.SQLException
Opens a connection and creates an EPSG factory for it. The default implementation attempts to create an instance of the class specified by the key. This class shall have a constructor expecting the following arguments in that order: Hints, Connection.

Specified by:
createFactory in interface DataSource
Parameters:
hints - A map of hints, including the low-level factories to use for CRS creation. This argument should be given unchanged to constructor.
Returns:
The EPSG factory using SQL queries appropriate for this data source.
Throws:
java.sql.SQLException - if connection to the database failed.


Copyright © GeoTools. All Rights Reserved.