Class MariaDbPoolDataSource
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Wrapper
,CommonDataSource
,ConnectionPoolDataSource
,DataSource
,XADataSource
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.MariaDbPoolDataSource
(String hostname, int port, String database) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
void
close()
Close datasource.Attempts to establish a connection with the data source that thisDataSource
object represents.getConnection
(String username, String password) Attempts to establish a connection with the data source that thisDataSource
object represents.Gets the name of the database.int
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.Retrieves the log writer for thisDataSource
object.int
Max time a connection can be idle.int
Pool maximum connection size.int
Get minimum pool size (pool will grow at creation untile reaching this size).Attempts to establish a physical database connection that can be used as a pooled connection.getPooledConnection
(String user, String password) Attempts to establish a physical database connection that can be used as a pooled connection.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
Returns the port number.Returns the name of the database server.protected UrlParser
For testing purpose only.getUser()
Gets the username.getXAConnection
(String user, String password) void
Initialize pool.private void
boolean
isWrapperFor
(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
(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
(PrintWriter out) Sets the log writer for thisDataSource
object to the givenjava.io.PrintWriter
object.void
setMaxIdleTime
(int maxIdleTime) void
setMaxPoolSize
(int maxPoolSize) void
setMinPoolSize
(int minPoolSize) void
setPassword
(String password) Sets the password.void
setPoolName
(String poolName) void
setPoolValidMinDelay
(Integer poolValidMinDelay) void
setPort
(int port) Sets the database port.void
setPortNumber
(int port) Sets the port number.void
setServerName
(String serverName) Sets the server name.void
setStaticGlobal
(Boolean staticGlobal) void
Sets the connection string URL.void
Sets the username.void
testForceMaxIdleTime
(int maxIdleTime) Permit to create test that doesn't wait for maxIdleTime minimum value of 60 seconds.Get current idle threads.Get pool.<T> T
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.ConnectionPoolDataSource
createPooledConnectionBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
Methods inherited from interface javax.sql.XADataSource
createXAConnectionBuilder
-
Field Details
-
urlParser
-
pool
-
hostname
-
port
-
connectTimeout
-
database
-
url
-
user
-
password
-
poolName
-
maxPoolSize
-
minPoolSize
-
maxIdleTime
-
staticGlobal
-
poolValidMinDelay
-
-
Constructor Details
-
MariaDbPoolDataSource
Constructor.- Parameters:
hostname
- hostname (ipv4, ipv6, dns name)port
- server portdatabase
- database name
-
MariaDbPoolDataSource
-
MariaDbPoolDataSource
public MariaDbPoolDataSource()Default constructor. hostname will be localhost, port 3306.
-
-
Method Details
-
getDatabaseName
Gets the name of the database.- Returns:
- the name of the database for this data source
-
setDatabaseName
Sets the database name.- Parameters:
database
- the name of the database- Throws:
SQLException
- if error in URL
-
checkNotInitialized
- Throws:
SQLException
-
getUser
Gets the username.- Returns:
- the username to use when connecting to the database
-
setUser
Sets the username.- Parameters:
user
- the username- Throws:
SQLException
- if error in URL
-
setPassword
Sets the password.- Parameters:
password
- the password- Throws:
SQLException
- if error in URL
-
getPort
public int getPort()Returns the port number.- Returns:
- the port number
-
setPort
Sets the database port.- Parameters:
port
- the port- Throws:
SQLException
- if error in URL
-
getPortNumber
public int getPortNumber()Returns the port number.- Returns:
- the port number
-
setPortNumber
Sets the port number.- Parameters:
port
- the port- Throws:
SQLException
- if error in URL- See Also:
-
setUrl
Sets the connection string URL.- Parameters:
url
- the connection string- Throws:
SQLException
- if error in URL
-
getServerName
Returns the name of the database server.- Returns:
- the name of the database server
-
setServerName
Sets the server name.- Parameters:
serverName
- the server name- Throws:
SQLException
- if error in URL
-
getConnection
Attempts to establish a connection with the data source that thisDataSource
object represents.- Specified by:
getConnection
in interfaceDataSource
- Returns:
- a connection to the data source
- Throws:
SQLException
- if a database access error occurs
-
getConnection
Attempts to establish a connection with the data source that thisDataSource
object represents.- Specified by:
getConnection
in interfaceDataSource
- Parameters:
username
- the database user on whose behalf the connection is being madepassword
- the user's password- Returns:
- a connection to the data source
- Throws:
SQLException
- if a database access error occurs
-
getPooledConnection
Attempts to establish a physical database connection that can be used as a pooled connection.- Specified by:
getPooledConnection
in interfaceConnectionPoolDataSource
- Returns:
- a
PooledConnection
object that is a physical connection to the database that thisConnectionPoolDataSource
object represents - Throws:
SQLException
- if a database access error occurs if the JDBC driver does not support this method
-
getPooledConnection
Attempts to establish a physical database connection that can be used as a pooled connection.- Specified by:
getPooledConnection
in interfaceConnectionPoolDataSource
- Parameters:
user
- the database user on whose behalf the connection is being madepassword
- the user's password- Returns:
- a
PooledConnection
object that is a physical connection to the database that thisConnectionPoolDataSource
object represents - Throws:
SQLException
- if a database access error occurs
-
getLogWriter
Retrieves the log writer for thisDataSource
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.- Specified by:
getLogWriter
in interfaceCommonDataSource
- Specified by:
getLogWriter
in interfaceConnectionPoolDataSource
- Specified by:
getLogWriter
in interfaceDataSource
- Specified by:
getLogWriter
in interfaceXADataSource
- Returns:
- the log writer for this data source or null if logging is disabled
- See Also:
-
setLogWriter
Sets the log writer for thisDataSource
object to the givenjava.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 aDataSource
object is created the log writer is initially null; in other words, the default is for logging to be disabled.- Specified by:
setLogWriter
in interfaceCommonDataSource
- Specified by:
setLogWriter
in interfaceConnectionPoolDataSource
- Specified by:
setLogWriter
in interfaceDataSource
- Specified by:
setLogWriter
in interfaceXADataSource
- Parameters:
out
- the new log writer; to disable logging, set to null- Since:
- 1.4
- See Also:
-
getLoginTimeout
public int getLoginTimeout()Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When aDataSource
object is created, the login timeout is initially zero.- Specified by:
getLoginTimeout
in interfaceCommonDataSource
- Specified by:
getLoginTimeout
in interfaceConnectionPoolDataSource
- Specified by:
getLoginTimeout
in interfaceDataSource
- Specified by:
getLoginTimeout
in interfaceXADataSource
- Returns:
- the data source login time limit
- Since:
- 1.4
- See Also:
-
setLoginTimeout
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When aDataSource
object is created, the login timeout is initially zero.- Specified by:
setLoginTimeout
in interfaceCommonDataSource
- Specified by:
setLoginTimeout
in interfaceConnectionPoolDataSource
- Specified by:
setLoginTimeout
in interfaceDataSource
- Specified by:
setLoginTimeout
in interfaceXADataSource
- Parameters:
seconds
- the data source login time limit- Throws:
SQLException
- if a database access error occurs.- Since:
- 1.4
- See Also:
-
unwrap
Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy.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 anSQLException
is thrown.- Specified by:
unwrap
in interfaceWrapper
- Parameters:
iface
- A Class defining an interface that the result must implement.- Returns:
- an object that implements the interface. May be a proxy for the actual implementing object.
- Throws:
SQLException
- If no object found that implements the interface- Since:
- 1.6
-
isWrapperFor
Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. Returns false otherwise. If this implements the interface then return true, else if this is a wrapper then return the result of recursively callingisWrapperFor
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 tounwrap
so that callers can use this method to avoid expensiveunwrap
calls that may fail. If this method returns true then callingunwrap
with the same argument should succeed.- Specified by:
isWrapperFor
in interfaceWrapper
- Parameters:
interfaceOrWrapper
- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
SQLException
- if an error occurs while determining whether this is a wrapper for an object with the given interface.- Since:
- 1.6
-
getXAConnection
- Specified by:
getXAConnection
in interfaceXADataSource
- Throws:
SQLException
-
getXAConnection
- Specified by:
getXAConnection
in interfaceXADataSource
- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLogger
in interfaceCommonDataSource
-
getUrlParser
For testing purpose only.- Returns:
- current url parser.
-
getPoolName
-
setPoolName
- Throws:
SQLException
-
getMaxPoolSize
public int getMaxPoolSize()Pool maximum connection size.- Returns:
- current value.
-
setMaxPoolSize
- Throws:
SQLException
-
getMinPoolSize
public int getMinPoolSize()Get minimum pool size (pool will grow at creation untile reaching this size). Null mean use the pool maximum pool size.- Returns:
- current value.
-
setMinPoolSize
- Throws:
SQLException
-
getMaxIdleTime
public int getMaxIdleTime()Max time a connection can be idle.- Returns:
- current value.
-
setMaxIdleTime
- Throws:
SQLException
-
getStaticGlobal
-
setStaticGlobal
-
getPoolValidMinDelay
If connection has been used in less time than poolValidMinDelay, then no connection validation will be done (0=mean validation every time).- Returns:
- current value of poolValidMinDelay
-
setPoolValidMinDelay
-
initializeUrlParser
- Throws:
SQLException
-
close
public void close()Close datasource.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
initialize
Initialize pool.- Throws:
SQLException
- if connection string has error
-
testGetConnectionIdleThreadIds
Get current idle threads. !! For testing purpose only !!- Returns:
- current thread id's
-
testForceMaxIdleTime
Permit to create test that doesn't wait for maxIdleTime minimum value of 60 seconds. !! For testing purpose only !!- Parameters:
maxIdleTime
- forced value of maxIdleTime option.- Throws:
SQLException
- if connection string has error
-
testGetPool
Get pool. !! For testing purpose only !!- Returns:
- pool
-