Add the actual Distinct class; fix bugs.
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
//
|
||||||
|
// Depot library - a Java relational persistence library
|
||||||
|
// http://code.google.com/p/depot/source/browse/trunk/LICENSE
|
||||||
|
|
||||||
|
package com.samskivert.depot.clause;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import com.samskivert.depot.PersistentRecord;
|
||||||
|
import com.samskivert.depot.expression.SQLExpression;
|
||||||
|
import com.samskivert.depot.impl.FragmentVisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a DISTINCT [ON <exp>] clause.
|
||||||
|
*
|
||||||
|
* Note: You almost certainly only ever want to use this in a SELECT statement.
|
||||||
|
*/
|
||||||
|
public class Distinct implements QueryClause
|
||||||
|
{
|
||||||
|
public Distinct (SQLExpression<?> on)
|
||||||
|
{
|
||||||
|
_on = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SQLExpression<?> getDistinctOn ()
|
||||||
|
{
|
||||||
|
return _on;
|
||||||
|
}
|
||||||
|
|
||||||
|
// from SQLExpression
|
||||||
|
public Object accept (FragmentVisitor<?> builder)
|
||||||
|
{
|
||||||
|
return builder.visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// from SQLExpression
|
||||||
|
public void addClasses (Collection<Class<? extends PersistentRecord>> classSet)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The expression to distinguish by, for DISTINCT ON, or null for mere DISTINCT. */
|
||||||
|
protected SQLExpression<?> _on;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ public class SelectClause
|
|||||||
_disMap.put(((FieldDefinition) clause).getField(), ((FieldDefinition) clause));
|
_disMap.put(((FieldDefinition) clause).getField(), ((FieldDefinition) clause));
|
||||||
|
|
||||||
} else if (clause instanceof Distinct) {
|
} else if (clause instanceof Distinct) {
|
||||||
checkArgument(_orderBy == null, "Query can't contain multiple Distinct clauses.");
|
checkArgument(_distinct == null, "Query can't contain multiple Distinct clauses.");
|
||||||
_distinct = (Distinct) clause;
|
_distinct = (Distinct) clause;
|
||||||
|
|
||||||
} else if (clause instanceof OrderBy) {
|
} else if (clause instanceof OrderBy) {
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public class HSQLBuilder
|
|||||||
public Void visit (Distinct distinct)
|
public Void visit (Distinct distinct)
|
||||||
{
|
{
|
||||||
if (distinct.getDistinctOn() != null) {
|
if (distinct.getDistinctOn() != null) {
|
||||||
throw new IllegalArgumentException("MySQL does not support DISTINCT ON");
|
throw new IllegalArgumentException("HSQL does not support DISTINCT ON");
|
||||||
}
|
}
|
||||||
return super.visit(distinct);
|
return super.visit(distinct);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user