Class MysqlDataSource

java.lang.Object
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 Details

    • mysqlDriver

      protected static final NonRegisteringDriver mysqlDriver
      The driver to create connections with
    • logWriter

      protected transient java.io.PrintWriter logWriter
      Log stream
    • databaseName

      protected java.lang.String databaseName
      Database Name
    • encoding

      protected java.lang.String encoding
      Character Encoding
    • url

      protected java.lang.String url
      The JDBC URL
    • explicitUrl

      protected boolean explicitUrl
      Should we construct the URL, or has it been set explicitly?
    • hostName

      protected java.lang.String hostName
      Hostname
    • port

      protected int port
      Port number
    • explicitPort

      protected boolean explicitPort
      Was the port explicitly set?
    • user

      protected java.lang.String user
      User name
    • password

      protected java.lang.String password
      Password
    • profileSQLString

      protected java.lang.String profileSQLString
      The 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 interface javax.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 interface javax.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 interface javax.sql.CommonDataSource
      Specified by:
      setLogWriter in interface javax.sql.DataSource
      Throws:
      java.sql.SQLException
    • getLogWriter

      public java.io.PrintWriter getLogWriter()
      Specified by:
      getLogWriter in interface javax.sql.CommonDataSource
      Specified by:
      getLogWriter in interface javax.sql.DataSource
    • setLoginTimeout

      public void setLoginTimeout​(int seconds) throws java.sql.SQLException
      Specified by:
      setLoginTimeout in interface javax.sql.CommonDataSource
      Specified by:
      setLoginTimeout in interface javax.sql.DataSource
      Throws:
      java.sql.SQLException
    • getLoginTimeout

      public int getLoginTimeout()
      Specified by:
      getLoginTimeout in interface javax.sql.CommonDataSource
      Specified by:
      getLoginTimeout in interface javax.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.SQLException
      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).
      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.NamingException
      Required method to support this class as a Referenceable.
      Specified by:
      getReference in interface javax.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.SQLException
      Creates 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 interface javax.sql.CommonDataSource
      Throws:
      java.sql.SQLFeatureNotSupportedException
    • unwrap

      public <T> T unwrap​(java.lang.Class<T> iface) throws java.sql.SQLException
      Specified by:
      unwrap in interface java.sql.Wrapper
      Throws:
      java.sql.SQLException
    • isWrapperFor

      public boolean isWrapperFor​(java.lang.Class<?> iface) throws java.sql.SQLException
      Specified by:
      isWrapperFor in interface java.sql.Wrapper
      Throws:
      java.sql.SQLException
    • getStringRuntimeProperty

      protected java.lang.String getStringRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • getBooleanRuntimeProperty

      protected boolean getBooleanRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • getIntegerRuntimeProperty

      protected int getIntegerRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • getLongRuntimeProperty

      protected long getLongRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • getMemorySizeRuntimeProperty

      protected int getMemorySizeRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • getEnumRuntimeProperty

      protected java.lang.String getEnumRuntimeProperty​(java.lang.String name) throws java.sql.SQLException
      Used 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.SQLException
      Used in properties setters added by instrumentation.
      Parameters:
      name - property name
      value - value
      Throws:
      java.sql.SQLException - if error occurs
    • exposeAsProperties

      public java.util.Properties exposeAsProperties()
      Specified by:
      exposeAsProperties in interface PropertySet
      Overrides:
      exposeAsProperties in class DefaultPropertySet