Class LocalDataSource

java.lang.Object
org.apache.sis.internal.metadata.sql.LocalDataSource
All Implemented Interfaces:
Comparable<LocalDataSource>, Wrapper, CommonDataSource, DataSource

public final class LocalDataSource extends Object implements DataSource, Comparable<LocalDataSource>
A data source for a database stored locally in the $SIS_DATA directory. This class wraps the database-provided DataSource with the addition of a shutdown method. It provides our starting point for initiating the system-wide connection.
Since:
1.1
Version:
1.2
Author:
Martin Desruisseaux (Geomatys)
  • Method Details

    • isSuccessfulShutdown

      public static boolean isSuccessfulShutdown(SQLException e)
      Returns true if the given exception is the one that we expect in successful shutdown of a Derby database. While this method is primarily used for Derby shutdown, the error code tested may be applicable to other systems.
      Note: this method is public for the needs of non-free:sis-embedded-data module.
      Parameters:
      e - the exception thrown by Derby.
      Returns:
      true if the exception indicates a successful shutdown.
    • compareTo

      public int compareTo(LocalDataSource other)
      Compares this data source with the given one for preference order. The preferred data sources are the ones for a database that already exists.
      Specified by:
      compareTo in interface Comparable<LocalDataSource>
      Parameters:
      other - the other data source to compare with this one.
      Returns:
      -1 if this data source is preferred to other, +1 if other is preferred to this, or 0 if no preference.
    • isWrapperFor

      public boolean isWrapperFor(Class<?> type) throws SQLException
      Returns whether unwrap(Class) can be invoked for the given type.
      Specified by:
      isWrapperFor in interface Wrapper
      Parameters:
      type - the interface or implementation type of desired wrapped object.
      Returns:
      whether unwrap(Class) can be invoked for the given type.
      Throws:
      SQLException - if an error occurs while checking wrappers.
    • unwrap

      public <T> T unwrap(Class<T> type) throws SQLException
      Returns an object of the given type to allow access to non-standard methods. The type can be either LocalDataSource or any type supported by the wrapped data source.
      Specified by:
      unwrap in interface Wrapper
      Type Parameters:
      T - compile-time value of type.
      Parameters:
      type - the interface or implementation type of desired wrapped object.
      Returns:
      an object of the given type.
      Throws:
      SQLException - if there is no object of the given type.
    • getConnection

      public Connection getConnection() throws SQLException
      Attempts to establish a connection.
      Specified by:
      getConnection in interface DataSource
      Returns:
      a connection to the locally installed database.
      Throws:
      SQLException - if a database access error occurs.
    • getConnection

      public Connection getConnection(String username, String password) throws SQLException
      Attempts to establish a connection.
      Specified by:
      getConnection in interface DataSource
      Parameters:
      username - the database user.
      password - the user's password.
      Returns:
      a connection to the locally installed database.
      Throws:
      SQLException - if a database access error occurs.
    • getLoginTimeout

      public int getLoginTimeout() throws SQLException
      Returns the maximum time in seconds that this data source will wait while attempting to connect to a database. Initial value is 0, meaning default timeout or no timeout.
      Specified by:
      getLoginTimeout in interface CommonDataSource
      Returns:
      the data source login time limit, or 0 for the default.
      Throws:
      SQLException - if a database access error occurs.
    • setLoginTimeout

      public void setLoginTimeout(int seconds) throws SQLException
      Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
      Specified by:
      setLoginTimeout in interface CommonDataSource
      Parameters:
      seconds - the data source login time limit, or 0 for the default.
      Throws:
      SQLException - if a database access error occurs.
    • getParentLogger

      public Logger getParentLogger() throws SQLFeatureNotSupportedException
      Return the parent of all loggers used by this data source. Can be used for configuring log messages.
      Specified by:
      getParentLogger in interface CommonDataSource
      Returns:
      the parent of all loggers used by this data source.
      Throws:
      SQLFeatureNotSupportedException - if the data source does not use logging.
    • getLogWriter

      public PrintWriter getLogWriter() throws SQLException
      Returns the output stream to which all logging and tracing messages for this data source will be printed. The default writer is null (logging disabled).
      Specified by:
      getLogWriter in interface CommonDataSource
      Returns:
      the log writer, or null if logging is disabled.
      Throws:
      SQLException - if a database access error occurs.
    • setLogWriter

      public void setLogWriter(PrintWriter out) throws SQLException
      Sets the output stream to which all logging and tracing messages for this data source will be printed. This method needs to be invoked for enabling logging.
      Specified by:
      setLogWriter in interface CommonDataSource
      Parameters:
      out - the log writer, or null if logging is disabled.
      Throws:
      SQLException - if a database access error occurs.
    • toString

      public String toString()
      Returns a string representation for debugging purpose.
      Overrides:
      toString in class Object
      Returns:
      an arbitrary string representation.