Class MariaDbDataSource
- All Implemented Interfaces:
Wrapper,CommonDataSource,ConnectionPoolDataSource,DataSource,XADataSource
- Direct Known Subclasses:
MySQLDataSource
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.MariaDbDataSource(String url) MariaDbDataSource(String hostname, int port, String database) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAttempts to establish a connection with the data source that thisDataSourceobject represents.getConnection(String username, String password) Attempts to establish a connection with the data source that thisDataSourceobject represents.Gets the name of the database.intGets the maximum time in seconds that this data source can wait while attempting to connect to a database.Retrieves the log writer for thisDataSourceobject.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.intgetPort()Returns the port number.intReturns the port number.Returns the name of the database server.protected UrlParserFor testing purpose only.getUser()Gets the username.Gets the username.getXAConnection(String user, String password) protected voidbooleanisWrapperFor(Class<?> interfaceOrWrapper) Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does.private voidvoidsetDatabaseName(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(PrintWriter out) Sets the log writer for thisDataSourceobject to the givenjava.io.PrintWriterobject.voidsetPassword(String password) Sets the password.voidsetPort(int port) Sets the database port.voidsetPortNumber(int port) Sets the port number.voidsetProperties(String properties) Deprecated.voidsetServerName(String serverName) Sets the server name.voidSets the connection string URL.voidSets the username.voidsetUserName(String userName) Sets the username.<T> TReturns 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, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.ConnectionPoolDataSource
createPooledConnectionBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilderMethods inherited from interface javax.sql.XADataSource
createXAConnectionBuilder
-
Field Details
-
urlParser
-
pool
-
hostname
-
port
-
connectTimeoutInMs
-
database
-
url
-
user
-
password
-
properties
-
-
Constructor Details
-
MariaDbDataSource
Constructor.- Parameters:
hostname- hostname (ipv4, ipv6, dns name)port- server portdatabase- database name
-
MariaDbDataSource
-
MariaDbDataSource
public MariaDbDataSource()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 connection information are erroneous
-
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 connection information are erroneous
-
getUserName
Gets the username.- Returns:
- the username to use when connecting to the database
-
setUserName
Sets the username.- Parameters:
userName- the username- Throws:
SQLException- if connection information are erroneous
-
setPassword
Sets the password.- Parameters:
password- the password- Throws:
SQLException- if connection information are erroneous
-
getPort
public int getPort()Returns the port number.- Returns:
- the port number
-
setPort
Sets the database port.- Parameters:
port- the port- Throws:
SQLException- if connection information are erroneous
-
getPortNumber
public int getPortNumber()Returns the port number.- Returns:
- the port number
-
setPortNumber
Sets the port number.- Parameters:
port- the port- Throws:
SQLException- if connection information are erroneous- See Also:
-
setProperties
Deprecated.- Throws:
SQLException
-
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 connection information are erroneous
-
getConnection
Attempts to establish a connection with the data source that thisDataSourceobject represents.- Specified by:
getConnectionin 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 thisDataSourceobject represents.- Specified by:
getConnectionin 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
-
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 interfaceCommonDataSource- Specified by:
getLogWriterin interfaceConnectionPoolDataSource- Specified by:
getLogWriterin interfaceDataSource- Specified by:
getLogWriterin interfaceXADataSource- Returns:
- the log writer for this data source or null if logging is disabled
- See Also:
-
setLogWriter
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 interfaceCommonDataSource- Specified by:
setLogWriterin interfaceConnectionPoolDataSource- Specified by:
setLogWriterin interfaceDataSource- Specified by:
setLogWriterin interfaceXADataSource- Parameters:
out- the new log writer; to disable logging, set to null- 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 aDataSourceobject is created, the login timeout is initially zero.- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceConnectionPoolDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Specified by:
getLoginTimeoutin interfaceXADataSource- Returns:
- the data source login time limit
- See Also:
-
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 interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceConnectionPoolDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Specified by:
setLoginTimeoutin interfaceXADataSource- Parameters:
seconds- the data source login time limit- 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
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 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 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 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.
-
getPooledConnection
Attempts to establish a physical database connection that can be used as a pooled connection.- Specified by:
getPooledConnectionin interfaceConnectionPoolDataSource- Returns:
- a
PooledConnectionobject that is a physical connection to the database that thisConnectionPoolDataSourceobject 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:
getPooledConnectionin interfaceConnectionPoolDataSource- 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:
SQLException- if a database access error occurs
-
getXAConnection
- Specified by:
getXAConnectionin interfaceXADataSource- Throws:
SQLException
-
getXAConnection
- Specified by:
getXAConnectionin interfaceXADataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource
-
getUrlParser
For testing purpose only.- Returns:
- current url parser.
-
reInitializeIfNeeded
- Throws:
SQLException
-
initialize
- Throws:
SQLException
-