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
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
FieldsModifier and TypeFieldDescriptionprotected 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
ConstructorsConstructorDescriptionDAO
(Connection c) Creates a Data Access Object with access to a particular connection. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Commits a multi-step transaction to the database.protected static Timestamp
Null-safe conversion of an Instant to a Timestamp.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 aSQLException
if 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 aSQLException
if less than the expected number of rows were updated per batch entry.protected static Instant
expandDate
(Date dt) Converts a date-only JDBC value into a full timestamp.protected static String
formatDBName
(String db) Formats a database name by converting to lowercase.protected static String
Converts a geographic location into a MySQL WKT formatted point.protected int
getNewID()
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.protected PreparedStatement
Initialize the prepared statement with an arbitrary SQL statement.protected PreparedStatement
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.
-
Field Details
-
_queryMax
protected int _queryMaxThe maximum number of rows to return. -
_queryStart
protected int _queryStartThe row number at which to start returning results. -
_queryTimeout
protected int _queryTimeoutThe query timeout, in seconds. -
WGS84_SRID
protected static final int WGS84_SRIDThe SRID used for geolocation queries.- See Also:
-
-
Constructor Details
-
DAO
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
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
Converts a geographic location into a MySQL WKT formatted point.- Parameters:
loc
- the GeoLocation- Returns:
- the WKT point
-
toID
-
toID
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
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 invalidNullPointerException
- if the SQL string is null- See Also:
-
prepareWithoutLimits
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
-
createTimestamp
-
executeIDs
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
Executes an UPDATE transaction on a prepared statement, and throws aSQLException
if less than the expected number of rows were updated.- Parameters:
ps
- a PreparedStatementminUpdateCount
- 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 aSQLException
if less than the expected number of rows were updated per batch entry.- Parameters:
ps
- a PreparedStatementminPerUpdate
- the minimum number of rows to update per batch entryminTotal
- 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
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
-
startTransaction
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
Commits a multi-step transaction to the database. This callsConnection.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 callsConnection.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
-