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 Summary
Modifier and TypeMethodDescriptionintcompareTo(LocalDataSource other) Compares this data source with the given one for preference order.Attempts to establish a connection.getConnection(String username, String password) Attempts to establish a connection.intReturns the maximum time in seconds that this data source will wait while attempting to connect to a database.Returns the output stream to which all logging and tracing messages for this data source will be printed.Return the parent of all loggers used by this data source.static booleanReturnstrueif the given exception is the one that we expect in successful shutdown of a Derby database.booleanisWrapperFor(Class<?> type) Returns whetherunwrap(Class)can be invoked for the given type.voidsetLoginTimeout(int seconds) Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.voidsetLogWriter(PrintWriter out) Sets the output stream to which all logging and tracing messages for this data source will be printed.toString()Returns a string representation for debugging purpose.<T> TReturns an object of the given type to allow access to non-standard methods.
-
Method Details
-
isSuccessfulShutdown
Returnstrueif 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 ofnon-free:sis-embedded-datamodule.- Parameters:
e- the exception thrown by Derby.- Returns:
trueif the exception indicates a successful shutdown.
-
compareTo
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:
compareToin interfaceComparable<LocalDataSource>- Parameters:
other- the other data source to compare with this one.- Returns:
- -1 if this data source is preferred to
other, +1 ifotheris preferred tothis, or 0 if no preference.
-
isWrapperFor
Returns whetherunwrap(Class)can be invoked for the given type.- Specified by:
isWrapperForin interfaceWrapper- 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
Returns an object of the given type to allow access to non-standard methods. The type can be eitherLocalDataSourceor any type supported by the wrapped data source.- Specified by:
unwrapin interfaceWrapper- Type Parameters:
T- compile-time value oftype.- 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
Attempts to establish a connection.- Specified by:
getConnectionin interfaceDataSource- Returns:
- a connection to the locally installed database.
- Throws:
SQLException- if a database access error occurs.
-
getConnection
Attempts to establish a connection.- Specified by:
getConnectionin interfaceDataSource- 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
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:
getLoginTimeoutin interfaceCommonDataSource- Returns:
- the data source login time limit, or 0 for the default.
- Throws:
SQLException- if a database access error occurs.
-
setLoginTimeout
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Parameters:
seconds- the data source login time limit, or 0 for the default.- Throws:
SQLException- if a database access error occurs.
-
getParentLogger
Return the parent of all loggers used by this data source. Can be used for configuring log messages.- Specified by:
getParentLoggerin interfaceCommonDataSource- Returns:
- the parent of all loggers used by this data source.
- Throws:
SQLFeatureNotSupportedException- if the data source does not use logging.
-
getLogWriter
Returns the output stream to which all logging and tracing messages for this data source will be printed. The default writer isnull(logging disabled).- Specified by:
getLogWriterin interfaceCommonDataSource- Returns:
- the log writer, or null if logging is disabled.
- Throws:
SQLException- if a database access error occurs.
-
setLogWriter
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:
setLogWriterin interfaceCommonDataSource- Parameters:
out- the log writer, or null if logging is disabled.- Throws:
SQLException- if a database access error occurs.
-
toString
Returns a string representation for debugging purpose.
-