Package com.mysql.cj.jdbc
Class MysqlDataSource
java.lang.Object
com.mysql.cj.conf.DefaultPropertySet
com.mysql.cj.jdbc.JdbcPropertySetImpl
com.mysql.cj.jdbc.MysqlDataSource
- All Implemented Interfaces:
PropertySet
,JdbcPropertySet
,java.io.Serializable
,java.sql.Wrapper
,javax.naming.Referenceable
,javax.sql.CommonDataSource
,javax.sql.DataSource
- Direct Known Subclasses:
MysqlConnectionPoolDataSource
,MysqlXADataSource
public class MysqlDataSource extends JdbcPropertySetImpl implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, JdbcPropertySet
A JNDI DataSource for a Mysql JDBC connection
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
databaseName
Database Nameprotected java.lang.String
description
protected java.lang.String
encoding
Character Encodingprotected boolean
explicitPort
Was the port explicitly set?protected boolean
explicitUrl
Should we construct the URL, or has it been set explicitly?protected java.lang.String
hostName
Hostnameprotected java.io.PrintWriter
logWriter
Log streamprotected static NonRegisteringDriver
mysqlDriver
The driver to create connections withprotected java.lang.String
password
Passwordprotected int
port
Port numberprotected java.lang.String
profileSQLString
The profileSQL propertyprotected java.lang.String
url
The JDBC URLprotected java.lang.String
user
User name -
Constructor Summary
Constructors Constructor Description MysqlDataSource()
Default no-arg constructor for Serialization -
Method Summary
Modifier and Type Method Description java.util.Properties
exposeAsProperties()
protected boolean
getBooleanRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.java.sql.Connection
getConnection()
java.sql.Connection
getConnection(java.lang.String userID, java.lang.String pass)
protected java.sql.Connection
getConnection(java.util.Properties props)
Creates a connection using the specified properties.java.lang.String
getDatabaseName()
Gets the name of the databasejava.lang.String
getDescription()
protected java.lang.String
getEnumRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.protected int
getIntegerRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.int
getLoginTimeout()
java.io.PrintWriter
getLogWriter()
protected long
getLongRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.protected int
getMemorySizeRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.java.util.logging.Logger
getParentLogger()
java.lang.String
getPassword()
Get the password.int
getPort()
Returns the port numberint
getPortNumber()
Returns the port numberjavax.naming.Reference
getReference()
Required method to support this class as aReferenceable
.java.lang.String
getServerName()
Returns the name of the database serverprotected java.lang.String
getStringRuntimeProperty(java.lang.String name)
Used in properties getters added by instrumentation.java.lang.String
getUrl()
Returns the JDBC URL that will be used to create the database connection.java.lang.String
getURL()
Returns the URL for this connectionjava.lang.String
getUser()
Returns the configured user for this connectionboolean
isWrapperFor(java.lang.Class<?> iface)
protected void
setBooleanRuntimeProperty(java.lang.String name, boolean value)
Used in properties setters added by instrumentation.void
setDatabaseName(java.lang.String dbName)
Sets the database name.void
setDescription(java.lang.String value)
protected void
setEnumRuntimeProperty(java.lang.String name, java.lang.String value)
Used in properties setters added by instrumentation.protected void
setIntegerRuntimeProperty(java.lang.String name, int value)
Used in properties setters added by instrumentation.void
setLoginTimeout(int seconds)
void
setLogWriter(java.io.PrintWriter output)
protected void
setLongRuntimeProperty(java.lang.String name, long value)
Used in properties setters added by instrumentation.protected void
setMemorySizeRuntimeProperty(java.lang.String name, int value)
Used in properties setters added by instrumentation.void
setPassword(java.lang.String pass)
Sets the passwordvoid
setPort(int p)
Sets the database port.void
setPortNumber(int p)
Sets the port numbervoid
setPropertiesViaRef(javax.naming.Reference ref)
Initializes driver properties that come from a JNDI reference (in the case of a javax.sql.DataSource bound into some name service that doesn't handle Java objects directly).void
setServerName(java.lang.String serverName)
Sets the server name.protected void
setStringRuntimeProperty(java.lang.String name, java.lang.String value)
Used in properties setters added by instrumentation.void
setUrl(java.lang.String url)
This method is used by the app server to set the url string specified within the datasource deployment descriptor.void
setURL(java.lang.String url)
Sets the URL for this connectionvoid
setUser(java.lang.String userID)
Sets the user ID.<T> T
unwrap(java.lang.Class<T> iface)
Methods inherited from class com.mysql.cj.jdbc.JdbcPropertySetImpl
exposeAsDriverPropertyInfo, postInitialization
Methods inherited from class com.mysql.cj.conf.DefaultPropertySet
addProperty, getBooleanProperty, getBooleanProperty, getEnumProperty, getEnumProperty, getIntegerProperty, getIntegerProperty, getLongProperty, getLongProperty, getMemorySizeProperty, getMemorySizeProperty, getProperty, getProperty, getStringProperty, getStringProperty, initializeProperties, removeProperty, removeProperty, reset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.mysql.cj.conf.PropertySet
addProperty, getBooleanProperty, getBooleanProperty, getEnumProperty, getEnumProperty, getIntegerProperty, getIntegerProperty, getLongProperty, getLongProperty, getMemorySizeProperty, getMemorySizeProperty, getProperty, getProperty, getStringProperty, getStringProperty, initializeProperties, postInitialization, removeProperty, removeProperty, reset
-
Field Details
-
mysqlDriver
The driver to create connections with -
logWriter
protected transient java.io.PrintWriter logWriterLog stream -
databaseName
protected java.lang.String databaseNameDatabase Name -
encoding
protected java.lang.String encodingCharacter Encoding -
url
protected java.lang.String urlThe JDBC URL -
explicitUrl
protected boolean explicitUrlShould we construct the URL, or has it been set explicitly? -
hostName
protected java.lang.String hostNameHostname -
port
protected int portPort number -
explicitPort
protected boolean explicitPortWas the port explicitly set? -
user
protected java.lang.String userUser name -
password
protected java.lang.String passwordPassword -
profileSQLString
protected java.lang.String profileSQLStringThe profileSQL property -
description
protected java.lang.String description
-
-
Constructor Details
-
MysqlDataSource
public MysqlDataSource()Default no-arg constructor for Serialization
-
-
Method Details
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String userID, java.lang.String pass) throws java.sql.SQLException- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getDescription
public java.lang.String getDescription() -
setDescription
public void setDescription(java.lang.String value) -
setDatabaseName
public void setDatabaseName(java.lang.String dbName)Sets the database name.- Parameters:
dbName
- the name of the database
-
getDatabaseName
public java.lang.String getDatabaseName()Gets the name of the database- Returns:
- the name of the database for this data source
-
setLogWriter
public void setLogWriter(java.io.PrintWriter output) throws java.sql.SQLException- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter()- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout()- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
-
setPassword
public void setPassword(java.lang.String pass)Sets the password- Parameters:
pass
- the password
-
getPassword
public java.lang.String getPassword()Get the password.- Returns:
- password
-
setPort
public void setPort(int p)Sets the database port.- Parameters:
p
- the port
-
getPort
public int getPort()Returns the port number- Returns:
- the port number
-
setPortNumber
public void setPortNumber(int p)Sets the port number- Parameters:
p
- the port
-
getPortNumber
public int getPortNumber()Returns the port number- Returns:
- the port number
-
setPropertiesViaRef
public void setPropertiesViaRef(javax.naming.Reference ref) throws java.sql.SQLExceptionInitializes driver properties that come from a JNDI reference (in the case of a javax.sql.DataSource bound into some name service that doesn't handle Java objects directly).- Parameters:
ref
- The JNDI Reference that holds RefAddrs for all properties- Throws:
java.sql.SQLException
- if error occurs
-
getReference
public javax.naming.Reference getReference() throws javax.naming.NamingExceptionRequired method to support this class as aReferenceable
.- Specified by:
getReference
in interfacejavax.naming.Referenceable
- Returns:
- a Reference to this data source
- Throws:
javax.naming.NamingException
- if a JNDI error occurs
-
setServerName
public void setServerName(java.lang.String serverName)Sets the server name.- Parameters:
serverName
- the server name
-
getServerName
public java.lang.String getServerName()Returns the name of the database server- Returns:
- the name of the database server
-
setURL
public void setURL(java.lang.String url)Sets the URL for this connection- Parameters:
url
- the URL for this connection
-
getURL
public java.lang.String getURL()Returns the URL for this connection- Returns:
- the URL for this connection
-
setUrl
public void setUrl(java.lang.String url)This method is used by the app server to set the url string specified within the datasource deployment descriptor. It is discovered using introspection and matches if property name in descriptor is "url".- Parameters:
url
- url to be used within driver.connect
-
getUrl
public java.lang.String getUrl()Returns the JDBC URL that will be used to create the database connection.- Returns:
- the URL for this connection
-
setUser
public void setUser(java.lang.String userID)Sets the user ID.- Parameters:
userID
- the User ID
-
getUser
public java.lang.String getUser()Returns the configured user for this connection- Returns:
- the user for this connection
-
getConnection
protected java.sql.Connection getConnection(java.util.Properties props) throws java.sql.SQLExceptionCreates a connection using the specified properties.- Parameters:
props
- the properties to connect with- Returns:
- a connection to the database
- Throws:
java.sql.SQLException
- if an error occurs
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
getParentLogger
in interfacejavax.sql.CommonDataSource
- Throws:
java.sql.SQLFeatureNotSupportedException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
getStringRuntimeProperty
protected java.lang.String getStringRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setStringRuntimeProperty
protected void setStringRuntimeProperty(java.lang.String name, java.lang.String value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
getBooleanRuntimeProperty
protected boolean getBooleanRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setBooleanRuntimeProperty
protected void setBooleanRuntimeProperty(java.lang.String name, boolean value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
getIntegerRuntimeProperty
protected int getIntegerRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setIntegerRuntimeProperty
protected void setIntegerRuntimeProperty(java.lang.String name, int value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
getLongRuntimeProperty
protected long getLongRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setLongRuntimeProperty
protected void setLongRuntimeProperty(java.lang.String name, long value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
getMemorySizeRuntimeProperty
protected int getMemorySizeRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setMemorySizeRuntimeProperty
protected void setMemorySizeRuntimeProperty(java.lang.String name, int value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
getEnumRuntimeProperty
protected java.lang.String getEnumRuntimeProperty(java.lang.String name) throws java.sql.SQLExceptionUsed in properties getters added by instrumentation.- Parameters:
name
- property name- Returns:
- property value
- Throws:
java.sql.SQLException
- if error occurs
-
setEnumRuntimeProperty
protected void setEnumRuntimeProperty(java.lang.String name, java.lang.String value) throws java.sql.SQLExceptionUsed in properties setters added by instrumentation.- Parameters:
name
- property namevalue
- value- Throws:
java.sql.SQLException
- if error occurs
-
exposeAsProperties
public java.util.Properties exposeAsProperties()- Specified by:
exposeAsProperties
in interfacePropertySet
- Overrides:
exposeAsProperties
in classDefaultPropertySet
-