2015-09-23 65 views
1

我必須使用CASE WHEN THENEnumPathEnumPath與CaseBuilder(QueryDSL 3.6.2)

Expression<CampaignStatus> cases = new CaseBuilder().when(qCampaign.campaignStatus.gt(CampaignStatus.NOT_SENT)).then(CampaignStatus.ERROR); 

(CampaignStatus是枚舉)

,我想在一個更新請求,最終使用這種情況下,問題

EnumExpression<CampaignStatus> cases = new CaseBuilder().when(qCampaign.campaignStatus.eq(CampaignStatus.SENT)).then(CampaignStatus.ERROR).otherwise(CampaignStatus.ERROR); 
      new JPAUpdateClause(manager, qCampaign) 
        .set(qCampaign.campaignStatus, cases) 
        .where(qCampaign.id.eq(campaignId)) 
        .execute(); 

QCLASS:

@Generated("com.mysema.query.codegen.EntitySerializer") 
public class QCampaign extends EntityPathBase<Campaign> { 

    private static final long serialVersionUID = -1869070992L; 

    private static final PathInits INITS = PathInits.DIRECT2; 

    public static final QCampaign campaign = new QCampaign("campaign"); 

    public final StringPath address = createString("address"); 

    public final StringPath application = createString("application"); 

    public final StringPath applicationId = createString("applicationId"); 

    public final SetPath<CampaignFleet, QCampaignFleet> campaignFleet = this.<CampaignFleet, QCampaignFleet>createSet("campaignFleet", CampaignFleet.class, QCampaignFleet.class, PathInits.DIRECT2); 

    public final EnumPath<net.atos.tum.rcs.rmessage.core.enums.CampaignStatus> campaignStatus = createEnum("campaignStatus", net.atos.tum.rcs.rmessage.core.enums.CampaignStatus.class); 

    public final SetPath<CampaignVehicle, QCampaignVehicle> campaignVehicle = this.<CampaignVehicle, QCampaignVehicle>createSet("campaignVehicle", CampaignVehicle.class, QCampaignVehicle.class, PathInits.DIRECT2); 

    public final DateTimePath<java.util.Date> createDate = createDateTime("createDate", java.util.Date.class); 

    public final QDisplayMethod displayMethod; 

    public final StringPath gpsCoords = createString("gpsCoords"); 

    public final BooleanPath html = createBoolean("html"); 

    public final NumberPath<Long> id = createNumber("id", Long.class); 

    public final StringPath phoneNumber = createString("phoneNumber"); 

    public final BooleanPath pro = createBoolean("pro"); 

    public final StringPath progress = createString("progress"); 

    public final SetPath<PushConfig, QPushConfig> pushConfigs = this.<PushConfig, QPushConfig>createSet("pushConfigs", PushConfig.class, QPushConfig.class, PathInits.DIRECT2); 

    public final DateTimePath<java.util.Date> sendingDate = createDateTime("sendingDate", java.util.Date.class); 

    public final SetPath<TemplateMessage, QTemplateMessage> templateMessages = this.<TemplateMessage, QTemplateMessage>createSet("templateMessages", TemplateMessage.class, QTemplateMessage.class, PathInits.DIRECT2); 

    public final BooleanPath temporary = createBoolean("temporary"); 

    public final StringPath title = createString("title"); 

    public final QUser user; 

    public QCampaign(String variable) { 
     this(Campaign.class, forVariable(variable), INITS); 
    } 

    public QCampaign(Path<? extends Campaign> path) { 
     this(path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT); 
    } 

    public QCampaign(PathMetadata<?> metadata) { 
     this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT); 
    } 

    public QCampaign(PathMetadata<?> metadata, PathInits inits) { 
     this(Campaign.class, metadata, inits); 
    } 

    public QCampaign(Class<? extends Campaign> type, PathMetadata<?> metadata, PathInits inits) { 
     super(type, metadata, inits); 
     this.displayMethod = inits.isInitialized("displayMethod") ? new QDisplayMethod(forProperty("displayMethod")) : null; 
     this.user = inits.isInitialized("user") ? new QUser(forProperty("user"), inits.get("user")) : null; 
    } 

} 

例外:

10:41:50.436 [qtp1497627503-24] ERROR [] NewCampaign    Render queue error in SetupRender[NewCampaign]: org.hibernate.hql.internal.ast.tree.JavaConstantNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression 
org.apache.tapestry5.ioc.internal.util.TapestryException: org.hibernate.hql.internal.ast.tree.JavaConstantNode cannot be cast to org.hibernate.hql.internal.ast.tree.SelectExpression 
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:158) ~[tapestry-core-5.3.7.jar:?] 
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.render(ComponentPageElementImpl.java:186) ~[tapestry-core-5.3.7.jar:?] 
    at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72) [tapestry-core-5.3.7.jar:?] 
    at org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124) [tapestry-core-5.3.7.jar:?] 
    at $PageRenderQueue_53dac9603a07.render(Unknown Source) [?:?] 
    at $PageRenderQueue_53dac96039e5.render(Unknown Source) [?:?] 
    at org.apache.tapestry5.internal.services.MarkupRendererTerminator.renderMarkup(MarkupRendererTerminator.java:37) [tapestry-core-5.3.7.jar:?] 
    at org.got5.tapestry5.jquery.services.js.JSModule$1.renderMarkup(JSModule.java:44) [tapestry5-jquery-3.4.0.jar:?] 
+0

什麼問題?你可以發佈你的Q班嗎? –

+0

是的,這裏有什麼問題? –

+0

我想使用的更新是CaseBuilder:Expression cases = new CaseBuilder()。when(qCampaign.campaignStatus.gt(CampaignStatus.NOT_SENT))。then(CampaignStatus.ERROR); - > .set(qCampaign.campaignStatus,cases) –

回答

0

我找到了一個解決方案:

EnumExpression<CampaignVehicleStatusEnum> cases = new CaseBuilder() 
       .when(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.TO_SAVE)) 
        .then(EnumTemplate.create(CampaignVehicleStatusEnum.class, String.valueOf(CampaignVehicleStatusEnum.OK.getStatus()))) 
        .otherwise(EnumTemplate.create(CampaignVehicleStatusEnum.class, String.valueOf(CampaignVehicleStatusEnum.ERROR.getStatus()))); 

請求更新:

new JPAUpdateClause(manager, qCampaignVehicle) 
       .set(qCampaignVehicle.status, cases) 
       .where(qCampaignVehicle.pk.campaign.id.eq(campaignId)) 
       .where(qCampaignVehicle.pk.vehicle.id.in(listOfVehicleId)) 
       .where(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.TO_SAVE) 
         .or(qCampaignVehicle.status.eq(CampaignVehicleStatusEnum.ERROR_TO_SAVE))) 
       .execute();