Class MysqlDataAccess

java.lang.Object
com.jk.data.dataaccess.core.JKDataAccessImpl
com.jk.data.vendors.mysql.MysqlDataAccess
All Implemented Interfaces:
JKDataAccessService

public class MysqlDataAccess extends JKDataAccessImpl
This class provides data access functionality specific to MySQL databases.

It extends the JKDataAccessImpl class.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • MysqlDataAccess

      public MysqlDataAccess(JKDataSource dataSource)
      This method constructs a new MysqlDataAccess with the provided data source.
      Parameters:
      dataSource - Specifies the data source.
  • Method Details

    • blobToByteArray

      public static byte[] blobToByteArray(Blob blob) throws IOException, SQLException
      This method converts a Blob object to a byte array.
      Parameters:
      blob - Specifies the Blob object to convert.
      Returns:
      the byte array representation of the `Blob` data.
      Throws:
      IOException - if an I/O exception has occurred.
      SQLException - if a SQL error occurs while accessing the Blob.
    • getRowsCount

      public int getRowsCount(String query, Object... params)
      This method retrieves the number of rows returned by a specified SQL query with optional parameters.
      Specified by:
      getRowsCount in interface JKDataAccessService
      Overrides:
      getRowsCount in class JKDataAccessImpl
      Parameters:
      query - Specifies the SQL query for which row count is to be determined.
      params - Specifies the optional parameters to be used in the SQL query.
      Returns:
      the number of rows returned by the specified SQL query.
    • getSystemDate

      public Timestamp getSystemDate()
      This method retrieves the current system date and time from the database.
      Specified by:
      getSystemDate in interface JKDataAccessService
      Overrides:
      getSystemDate in class JKDataAccessImpl
      Returns:
      a Date object representing the current system date and time
    • isDuplicateKey

      protected boolean isDuplicateKey(SQLException e) throws SQLException
      This method checks if the provided SQLException indicates a duplicate key violation.
      Parameters:
      e - Specifies the exception to check.
      Returns:
      true, if the exception indicates a duplicate key violation, false otherwise.
      Throws:
      SQLException - if the exception is not a duplicate key violation.
    • isDuplicateKey

      protected boolean isDuplicateKey(SQLException e, boolean throwException) throws SQLException
      This method checks if the provided SQLException indicates a duplicate key violation.
      Parameters:
      e - Specifies the exception to check.
      throwException - Indicates whether to throw the exception if it's not a duplicate key violation (true) or not (false).
      Returns:
      true, if the exception indicates a duplicate key violation, false otherwise.
      Throws:
      SQLException - if the exception is not a duplicate key violation and throwException is true.
    • describeTable

      public Map<String,String> describeTable(String name)
      This method retrieves data about a database table and returns it as a map of column names to their corresponding data types.
      Specified by:
      describeTable in interface JKDataAccessService
      Overrides:
      describeTable in class JKDataAccessImpl
      Parameters:
      name - Specifies the name of the table to describe.
      Returns:
      the map containing column names as keys and their corresponding data types as values.