Class MariaDbDataSource
- java.lang.Object
-
- org.mariadb.jdbc.MariaDbDataSource
-
- All Implemented Interfaces:
java.sql.Wrapper,javax.sql.CommonDataSource,javax.sql.ConnectionPoolDataSource,javax.sql.DataSource,javax.sql.XADataSource
- Direct Known Subclasses:
MySQLDataSource
public class MariaDbDataSource extends java.lang.Object implements javax.sql.DataSource, javax.sql.ConnectionPoolDataSource, javax.sql.XADataSource
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.IntegerconnectTimeoutInMsprivate java.lang.Stringdatabaseprivate java.lang.Stringhostnameprivate java.lang.Stringpasswordprivate java.lang.Integerportprivate java.lang.Stringpropertiesprivate java.lang.Stringurlprivate UrlParserurlParserprivate java.lang.Stringuser
-
Constructor Summary
Constructors Constructor Description MariaDbDataSource()Default constructor.MariaDbDataSource(java.lang.String url)MariaDbDataSource(java.lang.String hostname, int port, java.lang.String database)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.sql.ConnectiongetConnection()Attempts to establish a connection with the data source that thisDataSourceobject represents.java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)Attempts to establish a connection with the data source that thisDataSourceobject represents.java.lang.StringgetDatabaseName()Gets the name of the database.intgetLoginTimeout()Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.java.io.PrintWritergetLogWriter()Retrieves the log writer for thisDataSourceobject.java.util.logging.LoggergetParentLogger()javax.sql.PooledConnectiongetPooledConnection()Attempts to establish a physical database connection that can be used as a pooled connection.javax.sql.PooledConnectiongetPooledConnection(java.lang.String user, java.lang.String password)Attempts to establish a physical database connection that can be used as a pooled connection.intgetPort()Returns the port number.intgetPortNumber()Returns the port number.java.lang.StringgetServerName()Returns the name of the database server.protected UrlParsergetUrlParser()For testing purpose only.java.lang.StringgetUser()Gets the username.java.lang.StringgetUserName()Gets the username.javax.sql.XAConnectiongetXAConnection()javax.sql.XAConnectiongetXAConnection(java.lang.String user, java.lang.String password)protected voidinitialize()booleanisWrapperFor(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 voidreInitializeIfNeeded()voidsetDatabaseName(java.lang.String database)Sets the database name.voidsetLoginTimeout(int seconds)Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.voidsetLogWriter(java.io.PrintWriter out)Sets the log writer for thisDataSourceobject to the givenjava.io.PrintWriterobject.voidsetPassword(java.lang.String password)Sets the password.voidsetPort(int port)Sets the database port.voidsetPortNumber(int port)Sets the port number.voidsetProperties(java.lang.String properties)Deprecated.voidsetServerName(java.lang.String serverName)Sets the server name.voidsetUrl(java.lang.String url)Sets the connection string URL.voidsetUser(java.lang.String user)Sets the username.voidsetUserName(java.lang.String userName)Sets the username.<T> Tunwrap(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.
-
-
-
Field Detail
-
urlParser
private UrlParser urlParser
-
hostname
private java.lang.String hostname
-
port
private java.lang.Integer port
-
connectTimeoutInMs
private java.lang.Integer connectTimeoutInMs
-
database
private java.lang.String database
-
url
private java.lang.String url
-
user
private java.lang.String user
-
password
private java.lang.String password
-
properties
private java.lang.String properties
-
-
Constructor Detail
-
MariaDbDataSource
public MariaDbDataSource(java.lang.String hostname, int port, java.lang.String database)Constructor.- Parameters:
hostname- hostname (ipv4, ipv6, dns name)port- server portdatabase- database name
-
MariaDbDataSource
public MariaDbDataSource(java.lang.String url)
-
MariaDbDataSource
public MariaDbDataSource()
Default constructor. hostname will be localhost, port 3306.
-
-
Method Detail
-
getDatabaseName
public java.lang.String getDatabaseName()
Gets the name of the database.- Returns:
- the name of the database for this data source
-
setDatabaseName
public void setDatabaseName(java.lang.String database) throws java.sql.SQLExceptionSets the database name.- Parameters:
database- the name of the database- Throws:
java.sql.SQLException- if connection information are erroneous
-
getUser
public java.lang.String getUser()
Gets the username.- Returns:
- the username to use when connecting to the database
-
setUser
public void setUser(java.lang.String user) throws java.sql.SQLExceptionSets the username.- Parameters:
user- the username- Throws:
java.sql.SQLException- if connection information are erroneous
-
getUserName
public java.lang.String getUserName()
Gets the username.- Returns:
- the username to use when connecting to the database
-
setUserName
public void setUserName(java.lang.String userName) throws java.sql.SQLExceptionSets the username.- Parameters:
userName- the username- Throws:
java.sql.SQLException- if connection information are erroneous
-
setPassword
public void setPassword(java.lang.String password) throws java.sql.SQLExceptionSets the password.- Parameters:
password- the password- Throws:
java.sql.SQLException- if connection information are erroneous
-
getPort
public int getPort()
Returns the port number.- Returns:
- the port number
-
setPort
public void setPort(int port) throws java.sql.SQLExceptionSets the database port.- Parameters:
port- the port- Throws:
java.sql.SQLException- if connection information are erroneous
-
getPortNumber
public int getPortNumber()
Returns the port number.- Returns:
- the port number
-
setPortNumber
public void setPortNumber(int port) throws java.sql.SQLExceptionSets the port number.- Parameters:
port- the port- Throws:
java.sql.SQLException- if connection information are erroneous- See Also:
setPort(int)
-
setProperties
@Deprecated public void setProperties(java.lang.String properties) throws java.sql.SQLExceptionDeprecated.- Throws:
java.sql.SQLException
-
setUrl
public void setUrl(java.lang.String url) throws java.sql.SQLExceptionSets the connection string URL.- Parameters:
url- the connection string- Throws:
java.sql.SQLException- if error in URL
-
getServerName
public java.lang.String getServerName()
Returns the name of the database server.- Returns:
- the name of the database server
-
setServerName
public void setServerName(java.lang.String serverName) throws java.sql.SQLExceptionSets the server name.- Parameters:
serverName- the server name- Throws:
java.sql.SQLException- if connection information are erroneous
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionAttempts to establish a connection with the data source that thisDataSourceobject represents.- Specified by:
getConnectionin interfacejavax.sql.DataSource- Returns:
- a connection to the data source
- Throws:
java.sql.SQLException- if a database access error occurs
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLExceptionAttempts to establish a connection with the data source that thisDataSourceobject represents.- Specified by:
getConnectionin interfacejavax.sql.DataSource- 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:
java.sql.SQLException- if a database access error occurs
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Retrieves the log writer for thisDataSourceobject.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.DriverManagerclass. When aDataSourceobject is created, the log writer is initially null; in other words, the default is for logging to be disabled.- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.ConnectionPoolDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource- Specified by:
getLogWriterin interfacejavax.sql.XADataSource- Returns:
- the log writer for this data source or null if logging is disabled
- See Also:
setLogWriter(java.io.PrintWriter)
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out)
Sets the log writer for thisDataSourceobject to the givenjava.io.PrintWriterobject.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.DriverManagerclass. When aDataSourceobject is created the log writer is initially null; in other words, the default is for logging to be disabled.- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.ConnectionPoolDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- Specified by:
setLogWriterin interfacejavax.sql.XADataSource- Parameters:
out- the new log writer; to disable logging, set to null- See Also:
getLogWriter()
-
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 aDataSourceobject is created, the login timeout is initially zero.- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.ConnectionPoolDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.XADataSource- Returns:
- the data source login time limit
- See Also:
setLoginTimeout(int)
-
setLoginTimeout
public void setLoginTimeout(int seconds)
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 aDataSourceobject is created, the login timeout is initially zero.- Specified by:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.ConnectionPoolDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.XADataSource- Parameters:
seconds- the data source login time limit- See Also:
getLoginTimeout()
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionReturns 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
unwraprecursively on the wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface, then anSQLExceptionis thrown.- Specified by:
unwrapin interfacejava.sql.Wrapper- 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:
java.sql.SQLException- If no object found that implements the interface- Since:
- 1.6
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> interfaceOrWrapper) throws java.sql.SQLExceptionReturns 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 callingisWrapperForon 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 tounwrapso that callers can use this method to avoid expensiveunwrapcalls that may fail. If this method returns true then callingunwrapwith the same argument should succeed.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
interfaceOrWrapper- a Class defining an interface.- Returns:
- true if this implements the interface or directly or indirectly wraps an object that does.
- Throws:
java.sql.SQLException- if an error occurs while determining whether this is a wrapper for an object with the given interface.
-
getPooledConnection
public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLExceptionAttempts to establish a physical database connection that can be used as a pooled connection.- Specified by:
getPooledConnectionin interfacejavax.sql.ConnectionPoolDataSource- Returns:
- a
PooledConnectionobject that is a physical connection to the database that thisConnectionPoolDataSourceobject represents - Throws:
java.sql.SQLException- if a database access error occurs
-
getPooledConnection
public javax.sql.PooledConnection getPooledConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLExceptionAttempts to establish a physical database connection that can be used as a pooled connection.- Specified by:
getPooledConnectionin interfacejavax.sql.ConnectionPoolDataSource- Parameters:
user- the database user on whose behalf the connection is being madepassword- the user's password- Returns:
- a
PooledConnectionobject that is a physical connection to the database that thisConnectionPoolDataSourceobject represents - Throws:
java.sql.SQLException- if a database access error occurs
-
getXAConnection
public javax.sql.XAConnection getXAConnection() throws java.sql.SQLException- Specified by:
getXAConnectionin interfacejavax.sql.XADataSource- Throws:
java.sql.SQLException
-
getXAConnection
public javax.sql.XAConnection getXAConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException- Specified by:
getXAConnectionin interfacejavax.sql.XADataSource- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger()
- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource
-
getUrlParser
protected UrlParser getUrlParser()
For testing purpose only.- Returns:
- current url parser.
-
reInitializeIfNeeded
private void reInitializeIfNeeded() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
initialize
protected void initialize() throws java.sql.SQLException- Throws:
java.sql.SQLException
-
-