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.kew.engine.node;
017
018import javax.persistence.AttributeOverride;
019import javax.persistence.AttributeOverrides;
020import javax.persistence.Column;
021import javax.persistence.Entity;
022import javax.persistence.JoinColumn;
023import javax.persistence.ManyToOne;
024import javax.persistence.Table;
025import javax.persistence.Version;
026import java.util.Map;
027
028/**
029 * A piece of state on a {@link Branch} stored as a key-value pair of Strings.
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033@Entity
034@Table(name="KREW_RTE_BRCH_ST_T")
035@AttributeOverrides({
036@AttributeOverride(name="stateId", column=@Column(name="RTE_BRCH_ST_ID")),
037@AttributeOverride(name="versionNumber", column=@Column(name="VER_NBR", insertable = false, updatable = false))
038})
039public class BranchState extends State {
040    /**
041     * Prefix under which "variables" are stored in the branch state table, to distinguish
042     * them from non-variable key/value pairs.
043     */
044    public static final String VARIABLE_PREFIX = "var::";
045
046    private static final long serialVersionUID = -7642477013444817952L;
047
048    @ManyToOne
049        @JoinColumn(name="RTE_BRCH_ID", nullable = false)
050        private Branch branch;
051
052    @Version
053        @Column(name="VER_NBR")
054        private Integer lockVerNbr;
055
056    public BranchState() {}
057    
058    public BranchState(String key, String value) {
059        super(key, value);
060    }
061    
062    public Branch getBranch() {
063        return branch;
064    }
065
066    public void setBranch(Branch branch) {
067        this.branch = branch;
068    }
069
070    public String getBranchStateId() {
071        return getStateId();
072    }
073
074    public Integer getLockVerNbr() {
075        return lockVerNbr;
076    }
077
078    public void setLockVerNbr(Integer lockVerNbr) {
079        this.lockVerNbr = lockVerNbr;
080    }
081
082    public BranchState deepCopy(Map<Object, Object> visited) {
083        if (visited.containsKey(this)) {
084            return (BranchState)visited.get(this);
085        }
086        BranchState copy = new BranchState(getKey(), getValue());
087        visited.put(this, copy);
088        copy.stateId = stateId;
089        copy.lockVerNbr = lockVerNbr;
090        if (branch != null) {
091            copy.branch = branch.deepCopy(visited);
092        }
093        return copy;
094    }
095
096}
097