Class DAO

java.lang.Object
org.deltava.dao.DAO
Direct Known Subclasses:
EliteDAO, GetAcademyCalendar, GetAcademyCertifications, GetAcademyCourses, GetAcademyInactivity, GetAcademyProgress, GetACARSAlternate, GetACARSBandwidth, GetACARSBuilds, GetACARSData, GetACARSDispatchStats, GetACARSErrors, GetACARSLivery, GetACARSOnTime, GetACARSPerformance, GetACARSRoute, GetACARSTakeoffs, GetACARSTaxiTimes, GetACARSTrackInfo, GetAccomplishment, GetAddressValidation, GetAggregateStatistics, GetAircraft, GetAirline, GetAirport, GetAirspace, GetApplicant, GetAssignment, GetAuditLog, GetCachedRoutes, GetChart, GetCharterRequests, GetCoolerChannels, GetCoolerLastRead, GetCoolerLinks, GetCoolerPolls, GetCoolerThreads, GetCountry, GetEMailDelivery, GetEquipmentType, GetEvent, GetEventSignups, GetEventStatistics, GetExam, GetExamProfiles, GetExamQualifications, GetExamQuestions, GetExamStatistics, GetFilterData, GetFIR, GetFlightReportHistory, GetFlightReportLoad, GetFlightReportQueue, GetFlightReportRecognition, GetFlightReportRoutes, GetFlightReports, GetFlightReportStatistics, GetGallery, GetGates, GetHelp, GetHelpTemplate, GetImage, GetIPLocation, GetIssue, GetJobProfiles, GetJobs, GetLibrary, GetLoginData, GetMessageTemplate, GetMetadata, GetNavCycle, GetNavData, GetNews, GetNominations, GetOnlineTrack, GetPartner, GetPerformance, GetPilotBoard, GetPilotEMail, GetProgramStatistics, GetQuestionnaire, GetRawSchedule, GetRawScheduleInfo, GetResources, GetRunwayMapping, GetRunwayUsage, GetSchedule, GetScheduleAirport, GetScheduleEquipment, GetScheduleInfo, GetSELCAL, GetSimBriefPackages, GetStaff, GetStatistics, GetStatusUpdate, GetSystemData, GetSystemInfo, GetSystemLog, GetTableStatus, GetTimeZone, GetTour, GetTransferRequest, GetUserData, GetWarnings, GetWeather, GetXACARS, PilotReadDAO, PilotWriteDAO, SetAcademy, SetAcademyCalendar, SetAcademyCertification, SetACARSArchive, SetACARSBuilds, SetACARSData, SetACARSLog, SetACARSOnTime, SetACARSRoute, SetAccomplishment, SetAddressValidation, SetAggregateStatistics, SetAirportAirline, SetAirspace, SetAssignment, SetAuditLog, SetCachedRoutes, SetChart, SetCoolerChannel, SetCoolerLinks, SetCoolerMessage, SetCoolerNotification, SetDispatchCalendar, SetEMailDelivery, SetEquipmentType, SetEvent, SetExam, SetExamProfile, SetExamQuestion, SetFilterData, SetFlightReport, SetGalleryImage, SetGates, SetHelp, SetInactivity, SetIPLocation, SetIssue, SetJobs, SetLibrary, SetMessageTemplate, SetMetadata, SetNavData, SetNews, SetNomination, SetOceanic, SetOnlineTime, SetOnlineTrack, SetPartner, SetPilotEMail, SetQuestionnaire, SetResource, SetRunwayMapping, SetSchedule, SetScheduleSync, SetSELCAL, SetSignatureImage, SetStaff, SetStatusUpdate, SetSystemData, SetSystemLog, SetTour, SetTransferRequest, SetUserData, SetWeather, SetXACARS

public abstract class DAO extends Object
A JDBC Data Access Object. DAOs are used to read and write persistent data to JDBC data sources.
Since:
1.0
Version:
11.3
Author:
Luke
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The maximum number of rows to return.
    protected int
    The row number at which to start returning results.
    protected int
    The query timeout, in seconds.
    protected static final int
    The SRID used for geolocation queries.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a Data Access Object with access to a particular connection.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Commits a multi-step transaction to the database.
    protected static Timestamp
    Null-safe conversion of an Instant to a Timestamp.
    protected static List<Integer>
    Helper method to extract database ID data from the result set.
    protected static int
    executeUpdate(PreparedStatement ps, int minUpdateCount)
    Executes an UPDATE transaction on a prepared statement, and throws a SQLExceptionif less than the expected number of rows were updated.
    protected static int
    executeUpdate(PreparedStatement ps, int minPerUpdate, int minTotal)
    Executes an batched UPDATE transaction on a prepared statement, and throws a SQLExceptionif less than the expected number of rows were updated per batch entry.
    protected static Instant
    Converts a date-only JDBC value into a full timestamp.
    protected static String
    Formats a database name by converting to lowercase.
    protected static String
    Converts a geographic location into a MySQL WKT formatted point.
    protected int
    Returns the AUTO_INC column value generated by the previous JDBC transaction.
    static final long
    Returns the total number of queries executed since the JVM was started.
    Initialize the prepared statement with an arbitrary SQL statement.
    Initialize the prepared statement with an abitrary SQL statement, without applying the DAO's query result limitations.
    protected void
    Rolls back a multi-step transaction before it is completed.
    final void
    setQueryMax(int maxRows)
    Sets the maximum number of rows in the returned result set.
    final void
    setQueryStart(int rowStart)
    Sets the first row of the results to return.
    void
    setQueryTimeout(int timeout)
    Sets the timeout for any SQL operations.
    protected void
    Marks the start of a multi-step database transaction.
    protected static Integer
    Converts a Database bean or an Integer into an Integer.
    protected static Collection<Integer>
    toID(Collection<?> ids)
    Converts a collection of Objects into Integer IDs.
    protected static Instant
    Null-safe conversion of a Timestamp to an Instant.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _queryMax

      protected int _queryMax
      The maximum number of rows to return.
    • _queryStart

      protected int _queryStart
      The row number at which to start returning results.
    • _queryTimeout

      protected int _queryTimeout
      The query timeout, in seconds.
    • WGS84_SRID

      protected static final int WGS84_SRID
      The SRID used for geolocation queries.
      See Also:
  • Constructor Details

    • DAO

      public DAO(Connection c)
      Creates a Data Access Object with access to a particular connection. If the autoCommit property for the JDBC connection is false, we assume that manual commits are being used and any internal transaction management is automatically disabled.
      Parameters:
      c - the JDBC connection to use
  • Method Details

    • expandDate

      protected static Instant expandDate(Date dt)
      Converts a date-only JDBC value into a full timestamp. Since the server may be several hours ahead or behind most web users, a default time of 12 noon is applied (instead of the default midnight value) to prevent spurious date adjustments.
      Parameters:
      dt - a JDBC Date
      Returns:
      a Java date/time
    • formatLocation

      protected static String formatLocation(GeoLocation loc)
      Converts a geographic location into a MySQL WKT formatted point.
      Parameters:
      loc - the GeoLocation
      Returns:
      the WKT point
    • toID

      protected static Integer toID(Object o)
      Converts a Database bean or an Integer into an Integer.
      Parameters:
      o - the Object
      Returns:
      an Integer
    • toID

      protected static Collection<Integer> toID(Collection<?> ids)
      Converts a collection of Objects into Integer IDs.
      Parameters:
      ids - a Collection of Objects
      Returns:
      an array of Integers
    • setQueryTimeout

      public void setQueryTimeout(int timeout)
      Sets the timeout for any SQL operations.
      Parameters:
      timeout - the timeout, in seconds
    • setQueryStart

      public final void setQueryStart(int rowStart)
      Sets the first row of the results to return. mySQL uses 0 as its first row.
      Parameters:
      rowStart - the first row number of the unfiltered resultset to return
    • setQueryMax

      public final void setQueryMax(int maxRows)
      Sets the maximum number of rows in the returned result set.
      Parameters:
      maxRows - the maximum number of rows to return
    • prepare

      protected PreparedStatement prepare(String sql) throws SQLException
      Initialize the prepared statement with an arbitrary SQL statement. This statement appends LIMIT start,max to the SQL before preparing the statement if this is a SELECT statement.
      Parameters:
      sql - the SQL statement to initialize the prepared statement with
      Returns:
      the PreparedStatement
      Throws:
      SQLException - if the prepared statement is invalid
      NullPointerException - if the SQL string is null
      See Also:
    • prepareWithoutLimits

      protected PreparedStatement prepareWithoutLimits(String sql) throws SQLException
      Initialize the prepared statement with an abitrary SQL statement, without applying the DAO's query result limitations. This is useful where a DAO might make multiple queries on the database and only needs to limit a subset of these queries
      Parameters:
      sql - the SQL statement to initialize the prepared statement with
      Returns:
      the PreparedStatement
      Throws:
      SQLException - if the prepared statement is invalid
      See Also:
    • toInstant

      protected static Instant toInstant(Timestamp dt)
      Null-safe conversion of a Timestamp to an Instant.
      Parameters:
      dt - the Timestamp
      Returns:
      an Instant, or null
    • createTimestamp

      protected static Timestamp createTimestamp(Instant i)
      Null-safe conversion of an Instant to a Timestamp.
      Parameters:
      i - the Instant
      Returns:
      a Timestamp, or null
    • executeIDs

      protected static List<Integer> executeIDs(PreparedStatement ps) throws SQLException
      Helper method to extract database ID data from the result set.
      Parameters:
      ps - a PreparedStatement
      Returns:
      a List of database IDs
      Throws:
      SQLException - if an error occurs
    • executeUpdate

      protected static int executeUpdate(PreparedStatement ps, int minUpdateCount) throws SQLException
      Executes an UPDATE transaction on a prepared statement, and throws a SQLExceptionif less than the expected number of rows were updated.
      Parameters:
      ps - a PreparedStatement
      minUpdateCount - the minimum number of rows to update
      Returns:
      the actual number of rows updated
      Throws:
      SQLException - if the update fails due to a JDBC error, or if less than the expected number of rows were updated
    • executeUpdate

      protected static int executeUpdate(PreparedStatement ps, int minPerUpdate, int minTotal) throws SQLException
      Executes an batched UPDATE transaction on a prepared statement, and throws a SQLExceptionif less than the expected number of rows were updated per batch entry.
      Parameters:
      ps - a PreparedStatement
      minPerUpdate - the minimum number of rows to update per batch entry
      minTotal - the minimum number of rows to update across the entry batch
      Returns:
      the actual number of rows updated
      Throws:
      SQLException - if the update fails due to a JDBC error, or if less than the expected number of rows were updated
    • getNewID

      protected int getNewID() throws SQLException
      Returns the AUTO_INC column value generated by the previous JDBC transaction. This is useful when inserting a new record into a table where the primary key is a MEDIUMINT AUTO_INCREMENT column and we want to get the new database ID of the inserted object.
      Returns:
      the database ID, or 0 if LAST_INSERT_ID() returns null
      Throws:
      SQLException - if a JDBC error occurs
    • formatDBName

      protected static String formatDBName(String db)
      Formats a database name by converting to lowercase. This method will also return the database name component of a table name expressed in DB.TABLE format.
      Parameters:
      db - the database/table name
      Returns:
      the converted database name
    • startTransaction

      protected void startTransaction() throws SQLException
      Marks the start of a multi-step database transaction. This turns off the autoCommit property of the JDBC connection, if it is already set.
      Throws:
      SQLException - if a JDBC error occurs.
      See Also:
    • commitTransaction

      protected void commitTransaction() throws SQLException
      Commits a multi-step transaction to the database. This calls Connection.commit()on the JDBC connection, and then restores the old autoCommit property for the Connection.
      Throws:
      SQLException - if a JDBC error occurs
      See Also:
    • rollbackTransaction

      protected void rollbackTransaction()
      Rolls back a multi-step transaction before it is completed. This calls Connection.rollback()on the JDBC connection, and then resotres the old autoCommit property for the Connection. Since this is designed to be called in catch blocks, it eats exceptions.
      See Also:
    • getQueryCount

      public static final long getQueryCount()
      Returns the total number of queries executed since the JVM was started.
      Returns:
      the number of queries