-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applies LIMIT clauses more aggresively to avoid pulling back entire tables. Also reworked how in memory order-by works because, um, it wasn't working. Also brought the MySQL schema in line with the hsql schema.
- Loading branch information
Showing
18 changed files
with
674 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/java/org/hibernate/shards/criteria/InMemoryOrderBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (C) 2008 Google Inc. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
*/ | ||
package org.hibernate.shards.criteria; | ||
|
||
import org.hibernate.criterion.Order; | ||
|
||
/** | ||
* Describes an 'order by' that we're going to apply in memory | ||
* | ||
* @author maxr@google.com (Max Ross) | ||
*/ | ||
public class InMemoryOrderBy { | ||
|
||
// This is the full path to the property we're sorting by. | ||
// For example, if the criteria is on Building and we're sorting by numFloors | ||
// the expression is just 'numFloors.' However, if the criteria is on Building | ||
// and we're sorting by floor number (Building has 0 to n Floors and each Floor | ||
// has a 'number' member) then the expression is 'floors.number' | ||
private final String expression; | ||
private final boolean isAscending; | ||
|
||
/** | ||
* Constructs an InMemoryOrderBy instance | ||
* @param associationPath The association path leading to the object to which | ||
* the provided {@link Order} parameter applies. Null if the {@link Order} | ||
* parameter applies to the top level object | ||
* @param order A standard Hibernate {@link Order} object. | ||
*/ | ||
public InMemoryOrderBy(String associationPath, Order order) { | ||
this.expression = getAssociationPrefix(associationPath) + getSortingProperty(order); | ||
this.isAscending = isAscending(order); | ||
} | ||
|
||
private static String getAssociationPrefix(String associationPath) { | ||
return associationPath == null ? "" : associationPath + "."; | ||
} | ||
|
||
private static boolean isAscending(Order order) { | ||
return order.toString().toUpperCase().endsWith("ASC"); | ||
} | ||
|
||
public String getExpression() { | ||
return expression; | ||
} | ||
|
||
public boolean isAscending() { | ||
return isAscending; | ||
} | ||
|
||
private static String getSortingProperty(Order order) { | ||
/** | ||
* This method relies on the format that Order is using: | ||
* propertyName + ' ' + (ascending?"asc":"desc") | ||
*/ | ||
String str = order.toString(); | ||
return str.substring(0, str.indexOf(' ')); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.