public class MariaDbPoolDataSource
extends java.lang.Object
implements javax.sql.DataSource, javax.sql.XADataSource, java.io.Closeable, java.lang.AutoCloseable
Modifier and Type | Field and Description |
---|---|
private java.lang.Integer |
connectTimeout |
private java.lang.String |
database |
private java.lang.String |
hostname |
private java.lang.Integer |
maxIdleTime |
private java.lang.Integer |
maxPoolSize |
private java.lang.Integer |
minPoolSize |
private java.lang.String |
password |
private Pool |
pool |
private java.lang.String |
poolName |
private java.lang.Integer |
poolValidMinDelay |
private java.lang.Integer |
port |
private java.lang.Boolean |
staticGlobal |
private java.lang.String |
url |
private UrlParser |
urlParser |
private java.lang.String |
user |
Constructor and Description |
---|
MariaDbPoolDataSource()
Default constructor.
|
MariaDbPoolDataSource(java.lang.String url) |
MariaDbPoolDataSource(java.lang.String hostname,
int port,
java.lang.String database)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkNotInitialized() |
void |
close()
Close datasource.
|
java.sql.Connection |
getConnection()
Attempts to establish a connection with the data source that this
DataSource
object represents. |
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
Attempts to establish a connection with the data source that this
DataSource
object represents. |
java.lang.String |
getDatabaseName()
Gets the name of the database.
|
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 for this
DataSource object. |
int |
getMaxIdleTime()
Max time a connection can be idle.
|
int |
getMaxPoolSize()
Pool maximum connection size.
|
int |
getMinPoolSize()
Get minimum pool size (pool will grow at creation untile reaching this size).
|
java.util.logging.Logger |
getParentLogger() |
java.lang.String |
getPoolName() |
java.lang.Integer |
getPoolValidMinDelay()
If connection has been used in less time than poolValidMinDelay, then no connection validation
will be done (0=mean validation every time).
|
int |
getPort()
Returns the port number.
|
int |
getPortNumber()
Returns the port number.
|
java.lang.String |
getServerName()
Returns the name of the database server.
|
java.lang.Boolean |
getStaticGlobal() |
protected UrlParser |
getUrlParser()
For testing purpose only.
|
java.lang.String |
getUser()
Gets the username.
|
javax.sql.XAConnection |
getXAConnection() |
javax.sql.XAConnection |
getXAConnection(java.lang.String user,
java.lang.String password) |
void |
initialize()
Initialize pool.
|
private void |
initializeUrlParser() |
boolean |
isWrapperFor(java.lang.Class<?> interfaceOrWrapper)
Returns true if this either implements the interface argument or is directly or indirectly a
wrapper for an object that does.
|
void |
setDatabaseName(java.lang.String database)
Sets the database name.
|
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 for this
DataSource object to the given
java.io.PrintWriter object. |
void |
setMaxIdleTime(int maxIdleTime) |
void |
setMaxPoolSize(int maxPoolSize) |
void |
setMinPoolSize(int minPoolSize) |
void |
setPassword(java.lang.String password)
Sets the password.
|
void |
setPoolName(java.lang.String poolName) |
void |
setPoolValidMinDelay(java.lang.Integer poolValidMinDelay) |
void |
setPort(int port)
Sets the database port.
|
void |
setPortNumber(int port)
Sets the port number.
|
void |
setServerName(java.lang.String serverName)
Sets the server name.
|
void |
setStaticGlobal(java.lang.Boolean staticGlobal) |
void |
setUrl(java.lang.String url)
Sets the connection string URL.
|
void |
setUser(java.lang.String user)
Sets the username.
|
void |
testForceMaxIdleTime(int maxIdleTime)
Permit to create test that doesn't wait for maxIdleTime minimum value of 60 seconds.
|
java.util.List<java.lang.Long> |
testGetConnectionIdleThreadIds()
Get current idle threads.
|
Pool |
testGetPool()
Get pool.
|
<T> T |
unwrap(java.lang.Class<T> iface)
Returns an object that implements the given interface to allow access to non-standard methods,
or standard methods not exposed by the proxy.
|
private UrlParser urlParser
private Pool pool
private java.lang.String hostname
private java.lang.Integer port
private java.lang.Integer connectTimeout
private java.lang.String database
private java.lang.String url
private java.lang.String user
private java.lang.String password
private java.lang.String poolName
private java.lang.Integer maxPoolSize
private java.lang.Integer minPoolSize
private java.lang.Integer maxIdleTime
private java.lang.Boolean staticGlobal
private java.lang.Integer poolValidMinDelay
public MariaDbPoolDataSource(java.lang.String hostname, int port, java.lang.String database)
hostname
- hostname (ipv4, ipv6, dns name)port
- server portdatabase
- database namepublic MariaDbPoolDataSource(java.lang.String url)
public MariaDbPoolDataSource()
public java.lang.String getDatabaseName()
public void setDatabaseName(java.lang.String database) throws java.sql.SQLException
database
- the name of the databasejava.sql.SQLException
- if error in URLprivate void checkNotInitialized() throws java.sql.SQLException
java.sql.SQLException
public java.lang.String getUser()
public void setUser(java.lang.String user) throws java.sql.SQLException
user
- the usernamejava.sql.SQLException
- if error in URLpublic void setPassword(java.lang.String password) throws java.sql.SQLException
password
- the passwordjava.sql.SQLException
- if error in URLpublic int getPort()
public void setPort(int port) throws java.sql.SQLException
port
- the portjava.sql.SQLException
- if error in URLpublic int getPortNumber()
public void setPortNumber(int port) throws java.sql.SQLException
port
- the portjava.sql.SQLException
- if error in URLsetPort(int)
public void setUrl(java.lang.String url) throws java.sql.SQLException
url
- the connection stringjava.sql.SQLException
- if error in URLpublic java.lang.String getServerName()
public void setServerName(java.lang.String serverName) throws java.sql.SQLException
serverName
- the server namejava.sql.SQLException
- if error in URLpublic java.sql.Connection getConnection() throws java.sql.SQLException
DataSource
object represents.getConnection
in interface javax.sql.DataSource
java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
DataSource
object represents.getConnection
in interface javax.sql.DataSource
username
- the database user on whose behalf the connection is being madepassword
- the user's passwordjava.sql.SQLException
- if a database access error occurspublic java.io.PrintWriter getLogWriter()
DataSource
object.
The log writer is a character output stream to which all logging and tracing messages for
this data source will be printed. This includes messages printed by the methods of this
object, messages printed by methods of other objects manufactured by this object, and so on.
Messages printed to a data source specific log writer are not printed to the log writer
associated with the java.sql.DriverManager
class.
When a DataSource
object is created, the log writer is initially null; in other words,
the default is for logging to be disabled.
getLogWriter
in interface javax.sql.CommonDataSource
setLogWriter(java.io.PrintWriter)
public void setLogWriter(java.io.PrintWriter out)
DataSource
object to the given
java.io.PrintWriter
object.
The log writer is a character output stream to which all logging and tracing messages for this
data source will be printed. This includes messages printed by the methods of this object,
messages printed by methods of other objects manufactured by this object, and so on. Messages
printed to a data source- specific log writer are not printed to the log writer associated with
the java.sql.DriverManager
class. When a
DataSource
object is created the log writer is initially null; in other words,
the default is for logging to be disabled.
setLogWriter
in interface javax.sql.CommonDataSource
out
- the new log writer; to disable logging, set to nullgetLogWriter()
public int getLoginTimeout()
DataSource
object is
created, the login timeout is initially zero.getLoginTimeout
in interface javax.sql.CommonDataSource
setLoginTimeout(int)
public void setLoginTimeout(int seconds) throws java.sql.SQLException
DataSource
object
is created, the login timeout is initially zero.setLoginTimeout
in interface javax.sql.CommonDataSource
seconds
- the data source login time limitjava.sql.SQLException
- if a database access error occurs.getLoginTimeout()
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
If the receiver implements the interface then the result is the receiver or a proxy for the
receiver. If the receiver is a wrapper and the wrapped object implements the interface then the
result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result
of calling unwrap
recursively on the wrapped object or a proxy for that result. If
the receiver is not a wrapper and does not implement the interface, then an
SQLException
is thrown.
unwrap
in interface java.sql.Wrapper
iface
- A Class defining an interface that the result must implement.java.sql.SQLException
- If no object found that implements the interfacepublic boolean isWrapperFor(java.lang.Class<?> interfaceOrWrapper) throws java.sql.SQLException
isWrapperFor
on the wrapped object. If this does not implement the interface and
is not a wrapper, return false. This method should be implemented as a low-cost operation
compared to unwrap
so that callers can use this method to avoid expensive
unwrap
calls that may fail. If this method returns true then calling
unwrap
with the
same argument should succeed.isWrapperFor
in interface java.sql.Wrapper
interfaceOrWrapper
- a Class defining an interface.java.sql.SQLException
- if an error occurs while determining whether this is a wrapper for an
object with the given interface.public javax.sql.XAConnection getXAConnection() throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
java.sql.SQLException
public javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
getXAConnection
in interface javax.sql.XADataSource
java.sql.SQLException
public java.util.logging.Logger getParentLogger()
getParentLogger
in interface javax.sql.CommonDataSource
protected UrlParser getUrlParser()
public java.lang.String getPoolName()
public void setPoolName(java.lang.String poolName) throws java.sql.SQLException
java.sql.SQLException
public int getMaxPoolSize()
public void setMaxPoolSize(int maxPoolSize) throws java.sql.SQLException
java.sql.SQLException
public int getMinPoolSize()
public void setMinPoolSize(int minPoolSize) throws java.sql.SQLException
java.sql.SQLException
public int getMaxIdleTime()
public void setMaxIdleTime(int maxIdleTime) throws java.sql.SQLException
java.sql.SQLException
public java.lang.Boolean getStaticGlobal()
public void setStaticGlobal(java.lang.Boolean staticGlobal)
public java.lang.Integer getPoolValidMinDelay()
public void setPoolValidMinDelay(java.lang.Integer poolValidMinDelay)
private void initializeUrlParser() throws java.sql.SQLException
java.sql.SQLException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public void initialize() throws java.sql.SQLException
java.sql.SQLException
- if connection string has errorpublic java.util.List<java.lang.Long> testGetConnectionIdleThreadIds()
public void testForceMaxIdleTime(int maxIdleTime) throws java.sql.SQLException
maxIdleTime
- forced value of maxIdleTime option.java.sql.SQLException
- if connection string has errorpublic Pool testGetPool()