001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.kew.engine.node;
017
018 import org.hibernate.annotations.GenericGenerator;
019 import org.hibernate.annotations.Parameter;
020 import org.kuali.rice.core.api.util.KeyValue;
021 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
022 import org.kuali.rice.kew.service.KEWServiceLocator;
023 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
024
025 import javax.persistence.GeneratedValue;
026 import javax.persistence.Id;
027 import javax.persistence.MappedSuperclass;
028 import javax.persistence.PrePersist;
029 import java.util.LinkedHashMap;
030
031 /**
032 * A KeyValuePair that adds an id fields that makes it sufficient for storing in a database.
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 @MappedSuperclass
037 //@Sequence(name="KREW_RTE_NODE_S", property="stateId")
038 public abstract class State extends PersistableBusinessObjectBase implements KeyValue {
039 @Id
040 @GeneratedValue(generator="KREW_RTE_NODE_S")
041 @GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
042 @Parameter(name="sequence_name",value="KREW_RTE_NODE_S"),
043 @Parameter(name="value_column",value="id")
044 })
045 protected String stateId;
046 private String key;
047 private String value;
048
049 public State() {}
050
051 public State(String key, String value) {
052 this.key = key;
053 this.value = value;
054 }
055
056 @PrePersist
057 public void customPrePersist(){
058 OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
059 }
060
061 public String getStateId() {
062 return stateId;
063 }
064
065 public void setStateId(String stateId) {
066 this.stateId = stateId;
067 }
068
069 @Override
070 public String getKey() {
071 return key;
072 }
073
074 @Override
075 public String getValue() {
076 return value;
077 }
078
079 public void setKey(String key) {
080 this.key = key;
081 }
082
083 public void setValue(String value) {
084 this.value = value;
085 }
086
087 protected LinkedHashMap<String, Object> toStringMapperFields() {
088 final LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
089 map.put("stateId", stateId);
090 map.put("key", key);
091 map.put("value", value);
092 return map;
093 }
094 }