Class QueryDetails
- java.lang.Object
-
- nz.co.gregs.dbvolution.internal.query.QueryDetails
-
- All Implemented Interfaces:
java.io.Serializable,DBQueryable
- Direct Known Subclasses:
RecursiveQueryDetails
public class QueryDetails extends java.lang.Object implements DBQueryable, java.io.Serializable
Support DBvolution at Patreon
- Author:
- gregorygraham
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description QueryDetails()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToSortOrder(SortProvider[] sortColumns)voidblankResults()voidclear()voidclearResults()voidclearSortOrder()protected voidfillResultSetFromSQL(DBDatabase db, QueryDetails details, DBDefinition defn, java.lang.String sqlString)protected voidfillResultSetInternal(DBDatabase db, QueryDetails details, QueryOptions options)java.util.List<BooleanExpression>getAllConditions(DBDatabase database)Get all conditions involved in this query.java.util.List<DBRow>getAllQueryTables()Support DBvolution at Patreonjava.util.List<DBQueryRow>getAllRows()voidgetAllRowsForPage(DBDatabase database, QueryDetails details)java.lang.StringgetANSIJoinClause(DBDefinition defn, QueryState queryState, DBRow newTable, QueryOptions options)java.util.List<DBRow>getAssumedQueryTables()Support DBvolution at Patreonjava.util.List<BooleanExpression>getConditions()Support DBvolution at Patreonjava.lang.LonggetCount()java.util.List<DBQueryRow>getCurrentPage()java.util.Map<java.lang.Object,DBExpression>getDBReportGroupByColumns()Support DBvolution at Patreonjava.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,DBRow>>getExistingInstances()Support DBvolution at Patreonjava.util.Map<java.lang.Object,QueryableDatatype<?>>getExpressionColumns()Support DBvolution at Patreonjava.util.List<DBRow>getExtraExamples()Support DBvolution at PatreonBooleanExpression[]getHavingColumns()Support DBvolution at Patreonjava.lang.StringgetLabel()java.util.List<DBRow>getOptionalQueryTables()Support DBvolution at PatreonQueryOptionsgetOptions()Support DBvolution at Patreonprotected DBRowgetOrSetExistingInstanceForRow(DBDefinition defn, DBRow newInstance, java.util.Map<java.lang.String,DBRow> existingInstancesOfThisTableRow)Retrieves or sets the existing instance of the DBRow provided.java.lang.StringgetRawSQLClause()<R extends DBRow>
java.util.List<R>getRelatedInstancesFromQuery(DBRow row, R example)Finds all instances ofexamplethat share aDBQueryRowwith this instance.java.util.List<DBRow>getRequiredQueryTables()Support DBvolution at Patreonjava.util.List<DBQueryRow>getResults()protected java.sql.ResultSetgetResultSetForSQL(DBStatement statement, java.lang.String sql)Executes the query using the statement provided and returns the ResultSetjava.lang.IntegergetResultsPageIndex()java.lang.StringgetResultSQL()java.lang.IntegergetResultsRowLimit()java.lang.StringgetSelectSQLClause()Get the SELECT clause used during the query.java.lang.StringgetSQLForQuery(DBDatabase database, QueryState queryState, QueryType queryType, QueryOptions options)java.lang.LonggetTimeoutInMilliseconds()booleanisGroupedQuery()Return the requirement for a GROUP BY clause.booleanneedsResults(QueryOptions options)DBQueryablequery(DBDatabase db)Performs the DB query and returns a list of all actions performed in the process.protected voidsetCurrentPage(java.util.List<DBQueryRow> results)protected java.util.Map<java.lang.String,DBRow>setExistingInstancesForTable(java.util.Map<java.lang.String,DBRow> existingInstancesOfThisTableRow, DBRow newInstance)Creates the list of already created rows for the DBRow class supplied.protected voidsetFieldsFromColumns(DBDefinition defn, DBRow oldInstance, DBRow newInstance, java.sql.ResultSet resultSet)Based on the template provided by oldInstance, fill all the fields of newInstance with data from the current row of the ResultSet.voidsetGroupByRequiredByAggregator(boolean b)Set the requirement for a GROUP BY clause.voidsetHavingColumns(BooleanExpression... havingColumns)voidsetLabel(java.lang.String newLabel)voidsetOptions(QueryOptions tempOptions)voidsetQueryRowFromResultSet(DBDefinition defn, java.sql.ResultSet resultSet, QueryDetails details, DBQueryRow queryRow, boolean isGroupedQuery)voidsetQueryType(QueryType queryType)voidsetRawSQLClause(java.lang.String rawSQLClause)voidsetResults(java.util.List<DBQueryRow> results)voidsetResultsPageIndex(java.lang.Integer resultsPageIndex)voidsetResultSQL(java.lang.String resultSQL)voidsetResultsRowLimit(java.lang.Integer resultsRowLimit)voidsetSelectSQLClause(java.lang.String selectClause)Define the SELECT clause used during the query.voidsetSortOrder(ColumnProvider[] sortColumns)voidsetSortOrder(SortProvider[] sortColumns)voidsetTimeoutInMilliseconds(java.lang.Integer milliseconds)voidsetTimeoutInMilliseconds(java.lang.Long milliseconds)voidsetTimeoutToDefault()voidsetTimeoutToForever()java.lang.StringtoSQLString(DBDatabase db)booleanwillCreateBlankQuery(DBDatabase db)
-
-
-
Method Detail
-
getAllQueryTables
public java.util.List<DBRow> getAllQueryTables()
Support DBvolution at Patreon
- Returns:
- the allQueryTables
-
getRequiredQueryTables
public java.util.List<DBRow> getRequiredQueryTables()
Support DBvolution at Patreon
- Returns:
- the requiredQueryTables
-
getOptionalQueryTables
public java.util.List<DBRow> getOptionalQueryTables()
Support DBvolution at Patreon
- Returns:
- the optionalQueryTables
-
getAssumedQueryTables
public java.util.List<DBRow> getAssumedQueryTables()
Support DBvolution at Patreon
- Returns:
- the assumedQueryTables
-
getOptions
public QueryOptions getOptions()
Support DBvolution at Patreon
- Returns:
- the options
-
getExtraExamples
public java.util.List<DBRow> getExtraExamples()
Support DBvolution at Patreon
- Returns:
- the extraExamples
-
getAllConditions
public java.util.List<BooleanExpression> getAllConditions(DBDatabase database)
Get all conditions involved in this query.Support DBvolution at Patreon
- Parameters:
database- the database- Returns:
- all conditions in the query
-
getConditions
public java.util.List<BooleanExpression> getConditions()
Support DBvolution at Patreon
- Returns:
- the conditions
-
getExpressionColumns
public java.util.Map<java.lang.Object,QueryableDatatype<?>> getExpressionColumns()
Support DBvolution at Patreon
- Returns:
- the expressionColumns
-
getDBReportGroupByColumns
public java.util.Map<java.lang.Object,DBExpression> getDBReportGroupByColumns()
Support DBvolution at Patreon
- Returns:
- the dbReportGroupByColumns
-
getExistingInstances
public java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.String,DBRow>> getExistingInstances()
Support DBvolution at Patreon
- Returns:
- the existingInstances
-
setGroupByRequiredByAggregator
public void setGroupByRequiredByAggregator(boolean b)
Set the requirement for a GROUP BY clause.- Parameters:
b- the setting required
-
isGroupedQuery
public boolean isGroupedQuery()
Return the requirement for a GROUP BY clause.Support DBvolution at Patreon
- Returns:
- TRUE if the GROUP BY clause is required, otherwise FALSE.
-
setSelectSQLClause
public void setSelectSQLClause(java.lang.String selectClause)
Define the SELECT clause used during the query.- Parameters:
selectClause- the select clause to set
-
getSelectSQLClause
public java.lang.String getSelectSQLClause()
Get the SELECT clause used during the query.Support DBvolution at Patreon
- Returns:
- the SELECT clause defined earlier
-
getHavingColumns
public BooleanExpression[] getHavingColumns()
Support DBvolution at Patreon
- Returns:
- the havingColumns
-
setHavingColumns
public void setHavingColumns(BooleanExpression... havingColumns)
- Parameters:
havingColumns- the havingColumns to set
-
setQueryType
public void setQueryType(QueryType queryType)
-
setOptions
public void setOptions(QueryOptions tempOptions)
-
getRawSQLClause
public java.lang.String getRawSQLClause()
- Returns:
- the rawSQLClause
-
setRawSQLClause
public void setRawSQLClause(java.lang.String rawSQLClause)
- Parameters:
rawSQLClause- the rawSQLClause to set
-
getResults
public java.util.List<DBQueryRow> getResults()
- Returns:
- the results
-
setResults
public void setResults(java.util.List<DBQueryRow> results)
- Parameters:
results- the results to set
-
getResultSQL
public java.lang.String getResultSQL()
- Returns:
- the resultSQL
-
setResultSQL
public void setResultSQL(java.lang.String resultSQL)
- Parameters:
resultSQL- the resultSQL to set
-
getResultsPageIndex
public java.lang.Integer getResultsPageIndex()
- Returns:
- the resultsPageIndex
-
setResultsPageIndex
public void setResultsPageIndex(java.lang.Integer resultsPageIndex)
- Parameters:
resultsPageIndex- the resultsPageIndex to set
-
getResultsRowLimit
public java.lang.Integer getResultsRowLimit()
- Returns:
- the resultsRowLimit
-
setResultsRowLimit
public void setResultsRowLimit(java.lang.Integer resultsRowLimit)
- Parameters:
resultsRowLimit- the resultsRowLimit to set
-
clearResults
public void clearResults()
-
getCount
public java.lang.Long getCount()
-
getSQLForQuery
public java.lang.String getSQLForQuery(DBDatabase database, QueryState queryState, QueryType queryType, QueryOptions options)
-
getANSIJoinClause
public java.lang.String getANSIJoinClause(DBDefinition defn, QueryState queryState, DBRow newTable, QueryOptions options)
-
setSortOrder
public void setSortOrder(SortProvider[] sortColumns)
-
setSortOrder
public void setSortOrder(ColumnProvider[] sortColumns)
-
blankResults
public void blankResults()
-
addToSortOrder
public void addToSortOrder(SortProvider[] sortColumns)
-
clearSortOrder
public void clearSortOrder()
-
needsResults
public boolean needsResults(QueryOptions options)
-
getAllRows
public java.util.List<DBQueryRow> getAllRows() throws java.sql.SQLException, java.sql.SQLTimeoutException, AccidentalBlankQueryException, AccidentalCartesianJoinException
- Specified by:
getAllRowsin interfaceDBQueryable- Throws:
java.sql.SQLExceptionjava.sql.SQLTimeoutExceptionAccidentalBlankQueryExceptionAccidentalCartesianJoinException
-
query
public DBQueryable query(DBDatabase db) throws java.sql.SQLException, AccidentalBlankQueryException
Description copied from interface:DBQueryablePerforms the DB query and returns a list of all actions performed in the process.The supplied row will be changed by the action in an appropriate way, however the Action will contain an unchanged and unchangeable copy of the row for internal use.
- Specified by:
queryin interfaceDBQueryable- Parameters:
db- the target database.Support DBvolution at Patreon
- Returns:
- The complete list of all actions performed to complete this action on the database
- Throws:
java.sql.SQLException- Database operations may throw SQLExceptionsAccidentalBlankQueryException
-
getAllRowsForPage
public void getAllRowsForPage(DBDatabase database, QueryDetails details) throws java.sql.SQLException, AccidentalBlankQueryException
- Throws:
java.sql.SQLExceptionAccidentalBlankQueryException
-
fillResultSetInternal
protected void fillResultSetInternal(DBDatabase db, QueryDetails details, QueryOptions options) throws java.sql.SQLException, AccidentalBlankQueryException
- Throws:
java.sql.SQLExceptionAccidentalBlankQueryException
-
fillResultSetFromSQL
protected void fillResultSetFromSQL(DBDatabase db, QueryDetails details, DBDefinition defn, java.lang.String sqlString) throws java.sql.SQLException, AccidentalCartesianJoinException, AccidentalBlankQueryException
- Throws:
java.sql.SQLExceptionAccidentalCartesianJoinExceptionAccidentalBlankQueryException
-
getRelatedInstancesFromQuery
public <R extends DBRow> java.util.List<R> getRelatedInstancesFromQuery(DBRow row, R example) throws java.sql.SQLException, AccidentalCartesianJoinException, AccidentalBlankQueryException
Finds all instances ofexamplethat share aDBQueryRowwith this instance.- Type Parameters:
R- DBRow- Parameters:
row- the instance that the examples connect to.example- exampleSupport DBvolution at Patreon
- Returns:
- all instances of
examplethat are connected to this instance in thequery1 Database exceptions may be thrown - Throws:
java.sql.SQLException- java.sql.SQLExceptionAccidentalCartesianJoinExceptionAccidentalBlankQueryException
-
willCreateBlankQuery
public boolean willCreateBlankQuery(DBDatabase db)
-
getResultSetForSQL
protected java.sql.ResultSet getResultSetForSQL(DBStatement statement, java.lang.String sql) throws java.sql.SQLException, java.sql.SQLTimeoutException
Executes the query using the statement provided and returns the ResultSet- Parameters:
statement- dbStatementsql- sqlSupport DBvolution at Patreon
- Returns:
- the ResultSet returned from the actual database. Database exceptions may be thrown
- Throws:
java.sql.SQLException- java.sql.SQLExceptionjava.sql.SQLTimeoutException- time out exception
-
setQueryRowFromResultSet
public void setQueryRowFromResultSet(DBDefinition defn, java.sql.ResultSet resultSet, QueryDetails details, DBQueryRow queryRow, boolean isGroupedQuery) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setFieldsFromColumns
protected void setFieldsFromColumns(DBDefinition defn, DBRow oldInstance, DBRow newInstance, java.sql.ResultSet resultSet) throws java.sql.SQLException
Based on the template provided by oldInstance, fill all the fields of newInstance with data from the current row of the ResultSet.OldInstance is used to find the selected properties, newInstance is the result, and restultSet contains the retrieved data. Database exceptions may be thrown
- Parameters:
defn- the database definitionoldInstance- oldInstancenewInstance- newInstanceresultSet- resultSet- Throws:
java.sql.SQLException- java.sql.SQLException
-
setExistingInstancesForTable
protected java.util.Map<java.lang.String,DBRow> setExistingInstancesForTable(java.util.Map<java.lang.String,DBRow> existingInstancesOfThisTableRow, DBRow newInstance)
Creates the list of already created rows for the DBRow class supplied.- Parameters:
existingInstancesOfThisTableRow- existingInstancesOfThisTableRownewInstance- newInstanceSupport DBvolution at Patreon
- Returns:
- a list of existing rows.
-
getOrSetExistingInstanceForRow
protected DBRow getOrSetExistingInstanceForRow(DBDefinition defn, DBRow newInstance, java.util.Map<java.lang.String,DBRow> existingInstancesOfThisTableRow)
Retrieves or sets the existing instance of the DBRow provided.Queries maintain a list of existing rows to avoid duplicating identical rows. This method checks to see if the supplied row already exists and returns the existing version.
If the row is new then this method stores it, and returns it as the existing instance.
- Parameters:
defn- the database definitionnewInstance- newInstanceexistingInstancesOfThisTableRow- existingInstancesOfThisTableRowSupport DBvolution at Patreon
- Returns:
- the exisinting instance of the provided row, or the row itself if none exists.
-
setCurrentPage
protected void setCurrentPage(java.util.List<DBQueryRow> results)
-
getCurrentPage
public java.util.List<DBQueryRow> getCurrentPage()
-
clear
public void clear()
-
setTimeoutInMilliseconds
public void setTimeoutInMilliseconds(java.lang.Long milliseconds)
-
setTimeoutInMilliseconds
public void setTimeoutInMilliseconds(java.lang.Integer milliseconds)
-
setTimeoutToDefault
public void setTimeoutToDefault()
-
setTimeoutToForever
public void setTimeoutToForever()
-
getTimeoutInMilliseconds
public java.lang.Long getTimeoutInMilliseconds()
- Returns:
- the timeoutInMilliseconds
-
toSQLString
public java.lang.String toSQLString(DBDatabase db)
- Specified by:
toSQLStringin interfaceDBQueryable
-
setLabel
public void setLabel(java.lang.String newLabel)
-
getLabel
public java.lang.String getLabel()
-
-