#601607 : renamed StoreClause to DMLClause and made it the supertype for DeleteClause

This commit is contained in:
Timo Westkämper 2010-07-09 14:54:46 +00:00
parent 5e81a1feb6
commit 03b0c4e93e
21 changed files with 101 additions and 40 deletions

View File

@ -47,14 +47,23 @@ public class ColDeleteClause<T> implements DeleteClause<ColDeleteClause<T>>{
}
@Override
public ColDeleteClause<T> where(EBoolean... o) {
query.where(o);
public <P> ColDeleteClause<T> set(Path<P> path, P value) {
if (value != null){
query.where(path.asExpr().eq(value));
}else{
query.where(path.isNull());
}
return this;
}
@Override
public ColDeleteClause<T> where(EBoolean... o) {
query.where(o);
return this;
}
@Override
public String toString(){
return "delete " + query.toString();
}
}

View File

@ -10,17 +10,17 @@ import javax.annotation.Nullable;
import com.mysema.query.types.Path;
/**
* Parent interface for InsertClause and UpdateClause
* Parent interface for DeleteClause, InsertClause and UpdateCluase
*
* @author tiwe
*
* @param <C>
*/
public interface StoreClause<C extends StoreClause<C>> {
public interface DMLClause<C extends DMLClause<C>> {
/**
* Execute the clause and return the amount of inserted/updated rows/items
* Execute the clause and return the amount of deleted/inserted/updated rows/items
*
* @return
*/

View File

@ -14,7 +14,7 @@ import com.mysema.query.types.expr.EBoolean;
*
* @param <C>
*/
public interface DeleteClause<C extends DeleteClause<C>> {
public interface DeleteClause<C extends DeleteClause<C>> extends DMLClause<C>{
/**
* Defines the filter constraints
@ -24,10 +24,4 @@ public interface DeleteClause<C extends DeleteClause<C>> {
*/
C where(EBoolean... o);
/**
* Execute the delete clause and return the amount of deleted rows/items
*
* @return
*/
long execute();
}

View File

@ -15,7 +15,7 @@ import com.mysema.query.types.SubQuery;
*
* @param <C>
*/
public interface InsertClause<C extends InsertClause<C>> extends StoreClause<C>{
public interface InsertClause<C extends InsertClause<C>> extends DMLClause<C>{
/**
* Define the columns to be populated

View File

@ -17,7 +17,7 @@ import com.mysema.query.types.expr.EBoolean;
*
* @param <C>
*/
public interface UpdateClause<C extends UpdateClause<C>> extends StoreClause<C>{
public interface UpdateClause<C extends UpdateClause<C>> extends DMLClause<C>{
/**
* Set the paths to be updated

View File

@ -7,6 +7,8 @@ package com.mysema.query.types;
import java.util.List;
import com.mysema.query.types.expr.ESimple;
/**
* Custom provides base types for custom expressions with integrated
* serialization templates
@ -48,6 +50,6 @@ public interface Custom<T> {
*
* @return
*/
Expr<T> asExpr();
ESimple<T> asExpr();
}

View File

@ -43,15 +43,6 @@ public abstract class Expr<D> implements Serializable{
public abstract void accept(Visitor v);
/**
* Used for safe casts from Path, SubQuery, Operation and Custom to Expr
*
* @return
*/
public final Expr<D> asExpr(){
return this;
}
public abstract Expr<D> as(Path<D> alias);
/**

View File

@ -7,6 +7,8 @@ package com.mysema.query.types;
import java.util.List;
import com.mysema.query.types.expr.ESimple;
/**
* Operation represents an operation with operator and arguments
*
@ -20,7 +22,7 @@ public interface Operation<RT> {
*
* @return
*/
Expr<RT> asExpr();
ESimple<RT> asExpr();
/**
* Get the argument with the given index

View File

@ -8,6 +8,7 @@ package com.mysema.query.types;
import java.lang.reflect.AnnotatedElement;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.ESimple;
/**
* Path represents a path expression
@ -21,7 +22,7 @@ public interface Path<C> {
*
* @return
*/
Expr<C> asExpr();
ESimple<C> asExpr();
/**
* Get the metadata for this path

View File

@ -7,6 +7,8 @@ package com.mysema.query.types;
import com.mysema.query.QueryMetadata;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.ESimple;
import com.mysema.query.types.query.Detachable;
/**
*
@ -46,6 +48,6 @@ public interface SubQuery<T>{
*
* @return
*/
Expr<T> asExpr();
ESimple<T> asExpr();
}

View File

@ -11,6 +11,7 @@ import java.util.List;
import com.mysema.query.types.Custom;
import com.mysema.query.types.Expr;
import com.mysema.query.types.Template;
import com.mysema.query.types.expr.ESimple;
/**
* Mixin implementation of the Custom interface
@ -23,7 +24,7 @@ public final class CustomMixin<T> implements Custom<T>, Serializable {
private static final long serialVersionUID = 6951623726800809083L;
private final Expr<T> self;
private final ESimple<T> self;
private final List<Expr<?>> args;
@ -75,7 +76,7 @@ public final class CustomMixin<T> implements Custom<T>, Serializable {
}
@Override
public Expr<T> asExpr() {
public ESimple<T> asExpr() {
return self;
}
}

View File

@ -36,6 +36,15 @@ public abstract class ESimple<D> extends Expr<D> {
public ESimple(Class<? extends D> type) {
super(type);
}
/**
* Used for safe casts from Path, SubQuery, Operation and Custom to Expr
*
* @return
*/
public final ESimple<D> asExpr(){
return this;
}
@Override
public ENumber<Long> count(){

View File

@ -26,7 +26,7 @@ public final class OperationMixin<RT> implements Operation<RT>, Serializable {
private final Operator<? super RT> operator;
private final Expr<RT> self;
private final ESimple<RT> self;
public OperationMixin(Operation<RT> self, Operator<? super RT> operator, List<Expr<?>> args){
this.self = self.asExpr();
@ -35,7 +35,7 @@ public final class OperationMixin<RT> implements Operation<RT>, Serializable {
}
@Override
public Expr<RT> asExpr() {
public ESimple<RT> asExpr() {
return self;
}

View File

@ -16,6 +16,7 @@ import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.PathType;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.ESimple;
import com.mysema.query.types.expr.OBoolean;
import com.mysema.util.ReflectionUtils;
@ -38,7 +39,7 @@ public final class PathMixin<T> implements Path<T>, Serializable {
private final Path<?> root;
private final Expr<T> self;
private final ESimple<T> self;
@Nullable
private AnnotatedElement annotatedElement;
@ -50,7 +51,7 @@ public final class PathMixin<T> implements Path<T>, Serializable {
}
@Override
public Expr<T> asExpr() {
public ESimple<T> asExpr() {
return self;
}

View File

@ -75,7 +75,7 @@ public final class ListSubQuery<A> extends ECollectionBase<List<A>,A> implements
@SuppressWarnings("unchecked")
public Expr<?> as(Expr<?> alias) {
return OSimple.create(alias.getType(),(Operator)Ops.ALIAS, this, alias.asExpr());
return OSimple.create(alias.getType(),(Operator)Ops.ALIAS, this, alias);
}
}

View File

@ -12,6 +12,7 @@ import com.mysema.query.types.Expr;
import com.mysema.query.types.Ops;
import com.mysema.query.types.SubQuery;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.ESimple;
import com.mysema.query.types.expr.OBoolean;
/**
@ -27,7 +28,7 @@ public class SubQueryMixin<T> implements SubQuery<T>{
private final QueryMetadata metadata;
private final Expr<T> self;
private final ESimple<T> self;
public SubQueryMixin(SubQuery<T> self, QueryMetadata metadata){
this.self = self.asExpr();
@ -69,7 +70,7 @@ public class SubQueryMixin<T> implements SubQuery<T>{
}
@Override
public Expr<T> asExpr() {
public ESimple<T> asExpr() {
return self;
}

View File

@ -18,7 +18,9 @@ import com.mysema.query.dml.DeleteClause;
import com.mysema.query.hql.HQLSerializer;
import com.mysema.query.hql.HQLTemplates;
import com.mysema.query.hql.JPQLTemplates;
import com.mysema.query.types.Path;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.path.NullExpr;
import com.mysema.query.types.path.PEntity;
/**
@ -60,6 +62,16 @@ public class HibernateDeleteClause implements DeleteClause<HibernateDeleteClause
return query.executeUpdate();
}
@Override
public <T> HibernateDeleteClause set(Path<T> path, T value) {
if (value != null){
md.addWhere(path.asExpr().eq(value));
}else{
md.addWhere(path.isNull());
}
return this;
}
@Override
public HibernateDeleteClause where(EBoolean... o) {
md.addWhere(o);

View File

@ -17,7 +17,9 @@ import com.mysema.query.dml.DeleteClause;
import com.mysema.query.hql.HQLSerializer;
import com.mysema.query.hql.HQLTemplates;
import com.mysema.query.hql.JPQLTemplates;
import com.mysema.query.types.Path;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.path.NullExpr;
import com.mysema.query.types.path.PEntity;
/**
@ -54,6 +56,16 @@ public class JPADeleteClause implements DeleteClause<JPADeleteClause>{
JPAUtil.setConstants(query, constants, metadata.getParams());
return query.executeUpdate();
}
@Override
public <T> JPADeleteClause set(Path<T> path, T value) {
if (value != null){
metadata.addWhere(path.asExpr().eq(value));
}else{
metadata.addWhere(path.isNull());
}
return this;
}
@Override
public JPADeleteClause where(EBoolean... o) {

View File

@ -18,7 +18,9 @@ import com.mysema.query.QueryMetadata;
import com.mysema.query.dml.DeleteClause;
import com.mysema.query.jdoql.JDOQLSerializer;
import com.mysema.query.jdoql.JDOQLTemplates;
import com.mysema.query.types.Path;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.path.NullExpr;
import com.mysema.query.types.path.PEntity;
/**
@ -85,6 +87,16 @@ public class JDOQLDeleteClause implements DeleteClause<JDOQLDeleteClause>{
}
}
}
@Override
public <T> JDOQLDeleteClause set(Path<T> path, T value) {
if (value != null){
metadata.addWhere(path.asExpr().eq(value));
}else{
metadata.addWhere(path.isNull());
}
return this;
}
@Override
public JDOQLDeleteClause where(EBoolean... o) {

View File

@ -19,7 +19,9 @@ import com.mysema.query.dml.DeleteClause;
import com.mysema.query.sql.SQLSerializer;
import com.mysema.query.sql.SQLTemplates;
import com.mysema.query.types.Param;
import com.mysema.query.types.Path;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.path.NullExpr;
import com.mysema.query.types.path.PEntity;
import com.mysema.util.JDBCUtil;
@ -80,6 +82,16 @@ public class SQLDeleteClause implements DeleteClause<SQLDeleteClause> {
}
}
}
@Override
public <T> SQLDeleteClause set(Path<T> path, T value) {
if (value != null){
where.and(path.asExpr().eq(value));
}else{
where.and(path.isNull());
}
return this;
}
@Override
public SQLDeleteClause where(EBoolean... o) {

View File

@ -18,7 +18,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mysema.query.QueryException;
import com.mysema.query.dml.StoreClause;
import com.mysema.query.dml.DMLClause;
import com.mysema.query.sql.SQLQuery;
import com.mysema.query.sql.SQLQueryImpl;
import com.mysema.query.sql.SQLSerializer;
@ -39,7 +39,7 @@ import com.mysema.util.JDBCUtil;
*
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public class SQLMergeClause implements StoreClause<SQLMergeClause>{
public class SQLMergeClause implements DMLClause<SQLMergeClause>{
private static final Logger logger = LoggerFactory.getLogger(SQLMergeClause.class);
@ -105,7 +105,7 @@ public class SQLMergeClause implements StoreClause<SQLMergeClause>{
}
@SuppressWarnings("unchecked")
private void populate(StoreClause<?> clause) {
private void populate(DMLClause<?> clause) {
for (int i = 0; i < columns.size(); i++){
clause.set((Path)columns.get(i), (Expr)values.get(i));
}