Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b527ee2
Add ModelSetup to unify setup codes
TimothyGillespie Mar 21, 2021
480b883
Merge branch 'master' into TimothyGillespie/addOrderByTests
TimothyGillespie Mar 31, 2021
49e4fa0
Add assertOrderByContains method
TimothyGillespie Mar 31, 2021
8aaedb2
Add SectionIndexOutOfBoundException
TimothyGillespie Mar 31, 2021
1ae8ac8
Add retrieval methods for the sections
TimothyGillespie Mar 31, 2021
5d4e233
Add JavaDocs for getSectionList too
TimothyGillespie Mar 31, 2021
89c48dc
Add JavaDocs for getSectionList too
TimothyGillespie Mar 31, 2021
51907a4
Reorder methods more logically
TimothyGillespie Mar 31, 2021
ac7140e
Add assertSectionEquals method
TimothyGillespie Mar 31, 2021
5491a48
Remove OrderBy specific contains method
TimothyGillespie Mar 31, 2021
6f97433
Make assertion methods chainable
TimothyGillespie Mar 31, 2021
b73d7db
Add better fitting internal assert for the equal assertion
TimothyGillespie Mar 31, 2021
710b6c5
Add tests for OrderBy Clauses
TimothyGillespie Mar 31, 2021
9e857cf
Merge branch 'TimothyGillespie/addOrderByTests' of github.com:JavaWeb…
TimothyGillespie Mar 31, 2021
e4d3fc0
Remove explicit ASC as discussed
TimothyGillespie Apr 1, 2021
abdab9e
Add JavaDocs for QueryGroup
TimothyGillespie Apr 2, 2021
0a684f9
Add equals and hashcode overwrite to QueryColumn
TimothyGillespie Apr 2, 2021
17a7060
Add multiple order by capability
TimothyGillespie Apr 2, 2021
0037a3a
Merge branch 'TimothyGillespie/enableMultipleOrderBy' into TimothyGil…
TimothyGillespie Apr 2, 2021
fb00e4d
Adjust MySQL Query Building for the new OrderBy and fix OrderBy test
TimothyGillespie Apr 2, 2021
018ce02
Add test to assert the correct sort priority
TimothyGillespie Apr 2, 2021
c8e9a40
Add error case for calling order on same column twice
TimothyGillespie Apr 2, 2021
37ed312
Add note of purpose of OrderByClauseTest
TimothyGillespie Apr 2, 2021
5a74b53
Add JavaDocs to QueryOrderBy
TimothyGillespie Apr 2, 2021
5210447
Add JavaDocs to QueryOrderByElement
TimothyGillespie Apr 2, 2021
3bff425
Add JavaDocs to the order method on Query
TimothyGillespie Apr 2, 2021
e88bd3f
Merge pull request #21 from JavaWebStack/TimothyGillespie/addOrderByT…
TimothyGillespie Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add JavaDocs to the order method on Query
  • Loading branch information
TimothyGillespie committed Apr 2, 2021
commit 3bff425c49f79e32f3ce5e4584a86be15856b3b9
45 changes: 34 additions & 11 deletions src/main/java/org/javawebstack/orm/query/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,43 @@ public Query<T> search(String search) {
return this;
}

public Query<T> order(String orderBy) {
return order(orderBy, false);
}

public Query<T> order(String orderBy, boolean desc) {
return order(new QueryColumn(orderBy), desc);
}

public Query<T> order(QueryColumn orderBy, boolean desc) {
boolean success = this.order.add(orderBy, desc);
/**
* Sorts the results by the given column name ascendingly.
*
* @param columnName The name of the column to sort ascendingly by.
* @return The Query object with the given order by information added.
* @throws ORMQueryException if the order operation is called twice on a column specification with the same name.
*/
public Query<T> order(String columnName) throws ORMQueryException {
return order(columnName, false);
}

/**
* Sorts the results by the given column name with the given order direction.
*
* @param columnName The name of the column to sort ascendingly by.
* @param desc If true it will order descendingly, if false it will order ascendingly.
* @return The Query object with the given order by information added.
* @throws ORMQueryException if the order operation is called twice on a column specification with the same name.
*/
public Query<T> order(String columnName, boolean desc) throws ORMQueryException {
return order(new QueryColumn(columnName), desc);
}

/**
* Sorts the results by the given column with the given order direction.
*
* @param column The column encoded as QueryColumn object.
* @param desc If true it will order descendingly, if false it will order ascendingly.
* @return The Query object with the given order by information added.
* @throws ORMQueryException if the order operation is called twice on a column specification with the same name.
*/
public Query<T> order(QueryColumn column, boolean desc) throws ORMQueryException{
boolean success = this.order.add(column, desc);
if(!success) {
throw new ORMQueryException(String.format(
"The column %s could not be ordered %s. This is probably caused by calling .order() on this column twice.",
orderBy.toString(),
column.toString(),
desc ? "descendingly" : "ascendingly"
));
}
Expand Down