001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.messaging;
017
018import org.kuali.rice.core.api.util.io.SerializationUtils;
019import org.kuali.rice.ksb.api.messaging.AsynchronousCall;
020
021import javax.persistence.*;
022import java.io.Serializable;
023
024/**
025 * Holds message payload content.  Needed to proxy the content so we don't have to 
026 * take the hit when grabbing large amounts of persisted messages at time.
027 * 
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 *
030 */
031@Entity
032@Table(name="KRSB_MSG_PYLD_T")
033public class PersistedMessagePayload implements Serializable {
034    
035    private static final long serialVersionUID = 508778527504899029L;
036    
037    @Id
038        @Column(name="MSG_QUE_ID")
039        private Long routeQueueId;
040    @Lob
041        @Basic(fetch=FetchType.LAZY)
042        @Column(name="MSG_PYLD", length=4000)
043        private String payload;
044    @Transient
045    private AsynchronousCall methodCall;
046    @Transient
047    private PersistedMessageBO message;
048    
049    public PersistedMessagePayload() {}
050    
051    public PersistedMessagePayload (AsynchronousCall methodCall, PersistedMessageBO message) {
052        this.setPayload(SerializationUtils.serializeToBase64(methodCall));
053        this.methodCall = methodCall;
054        this.message = message;
055    }
056    
057    public String getPayload() {
058        return this.payload;
059    }
060    public void setPayload(String payload) {
061        this.payload = payload;
062    }
063    public Long getRouteQueueId() {
064        return this.routeQueueId;
065    }
066    public void setRouteQueueId(Long routeQueueId) {
067        this.routeQueueId = routeQueueId;
068    }
069    public AsynchronousCall getMethodCall() {
070        if (this.methodCall != null) {
071            return this.methodCall;
072        } 
073        this.methodCall = (AsynchronousCall) SerializationUtils.deserializeFromBase64(getPayload());
074        return this.methodCall;
075    }
076
077    public PersistedMessageBO getMessage() {
078        return this.message;
079    }
080
081    public void setMessage(PersistedMessageBO message) {
082        this.message = message;
083    }
084
085    public void setMethodCall(AsynchronousCall methodCall) {
086        this.methodCall = methodCall;
087    }
088    
089
090}
091