public class MariaDbDataSource
extends java.lang.Object
implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource
Modifier and Type | Field and Description |
---|---|
private java.lang.Integer |
connectTimeoutInMs |
private java.lang.String |
database |
private java.lang.String |
hostname |
private java.lang.String |
password |
private Pool |
pool |
private java.lang.Integer |
port |
private java.lang.String |
properties |
private java.lang.String |
url |
private UrlParser |
urlParser |
private java.lang.String |
user |
Constructor and Description |
---|
MariaDbDataSource()
Default constructor.
|
MariaDbDataSource(java.lang.String url) |
MariaDbDataSource(java.lang.String hostname,
int port,
java.lang.String database)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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. |
java.util.logging.Logger |
getParentLogger() |
javax.sql.PooledConnection |
getPooledConnection()
Attempts to establish a physical database connection that can be used as a pooled connection.
|
javax.sql.PooledConnection |
getPooledConnection(java.lang.String user,
java.lang.String password)
Attempts to establish a physical database connection that can be used as a pooled connection.
|
int |
getPort()
Returns the port number.
|
int |
getPortNumber()
Returns the port number.
|
java.lang.String |
getServerName()
Returns the name of the database server.
|
protected UrlParser |
getUrlParser()
For testing purpose only.
|
java.lang.String |
getUser()
Gets the username.
|
java.lang.String |
getUserName()
Gets the username.
|
javax.sql.XAConnection |
getXAConnection() |
javax.sql.XAConnection |
getXAConnection(java.lang.String user,
java.lang.String password) |
protected void |
initialize() |
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.
|
private void |
reInitializeIfNeeded() |
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 |
setPassword(java.lang.String password)
Sets the password.
|
void |
setPort(int port)
Sets the database port.
|
void |
setPortNumber(int port)
Sets the port number.
|
void |
setProperties(java.lang.String properties)
Deprecated.
|
void |
setServerName(java.lang.String serverName)
Sets the server name.
|
void |
setUrl(java.lang.String url)
Sets the connection string URL.
|
void |
setUser(java.lang.String user)
Sets the username.
|
void |
setUserName(java.lang.String userName)
Sets the username.
|
<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 connectTimeoutInMs
private java.lang.String database
private java.lang.String url
private java.lang.String user
private java.lang.String password
private java.lang.String properties
public MariaDbDataSource(java.lang.String hostname, int port, java.lang.String database)
hostname
- hostname (ipv4, ipv6, dns name)port
- server portdatabase
- database namepublic MariaDbDataSource(java.lang.String url)
public MariaDbDataSource()
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 connection information are erroneouspublic java.lang.String getUser()
public void setUser(java.lang.String user) throws java.sql.SQLException
user
- the usernamejava.sql.SQLException
- if connection information are erroneouspublic java.lang.String getUserName()
public void setUserName(java.lang.String userName) throws java.sql.SQLException
userName
- the usernamejava.sql.SQLException
- if connection information are erroneouspublic void setPassword(java.lang.String password) throws java.sql.SQLException
password
- the passwordjava.sql.SQLException
- if connection information are erroneouspublic int getPort()
public void setPort(int port) throws java.sql.SQLException
port
- the portjava.sql.SQLException
- if connection information are erroneouspublic int getPortNumber()
public void setPortNumber(int port) throws java.sql.SQLException
port
- the portjava.sql.SQLException
- if connection information are erroneoussetPort(int)
@Deprecated public void setProperties(java.lang.String properties) throws java.sql.SQLException
java.sql.SQLException
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 connection information are erroneouspublic 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)
DataSource
object
is created, the login timeout is initially zero.setLoginTimeout
in interface javax.sql.CommonDataSource
seconds
- the data source login time limitgetLoginTimeout()
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.PooledConnection getPooledConnection() throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
PooledConnection
object that is a physical connection to the database
that this ConnectionPoolDataSource
object representsjava.sql.SQLException
- if a database access error occurs if the JDBC driver does not support this
methodpublic javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
user
- the database user on whose behalf the connection is being madepassword
- the user's passwordPooledConnection
object that is a physical connection to the database
that this
ConnectionPoolDataSource
object representsjava.sql.SQLException
- if a database access error occurspublic 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()
private void reInitializeIfNeeded() throws java.sql.SQLException
java.sql.SQLException
protected void initialize() throws java.sql.SQLException
java.sql.SQLException