View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine.node;
17  
18  import org.hibernate.annotations.GenericGenerator;
19  import org.hibernate.annotations.Parameter;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
22  import org.kuali.rice.kew.service.KEWServiceLocator;
23  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
24  
25  import javax.persistence.GeneratedValue;
26  import javax.persistence.Id;
27  import javax.persistence.MappedSuperclass;
28  import javax.persistence.PrePersist;
29  import java.util.LinkedHashMap;
30  
31  /**
32   * A KeyValuePair that adds an id fields that makes it sufficient for storing in a database.
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @MappedSuperclass
37  //@Sequence(name="KREW_RTE_NODE_S", property="stateId")
38  public abstract class State extends PersistableBusinessObjectBase implements KeyValue {
39      @Id
40      @GeneratedValue(generator="KREW_RTE_NODE_S")
41  	@GenericGenerator(name="KREW_RTE_NODE_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
42  			@Parameter(name="sequence_name",value="KREW_RTE_NODE_S"),
43  			@Parameter(name="value_column",value="id")
44  	})
45  	protected String stateId;
46  	private String key;
47      private String value;
48  
49      public State() {}
50      
51      public State(String key, String value) {
52      	this.key = key;
53      	this.value = value;
54      }
55  
56      @PrePersist
57      public void customPrePersist(){
58          OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
59      }
60  
61      public String getStateId() {
62          return stateId;
63      }
64  
65      public void setStateId(String stateId) {
66          this.stateId = stateId;
67      }
68      
69      @Override
70      public String getKey() {
71      	return key;
72      }
73      
74      @Override
75      public String getValue() {
76      	return value;
77      }
78      
79      public void setKey(String key) {
80  		this.key = key;
81  	}
82  
83  	public void setValue(String value) {
84  		this.value = value;
85  	}
86  	
87  	protected LinkedHashMap<String, Object> toStringMapperFields() {
88  		final LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
89  		map.put("stateId", stateId);
90  		map.put("key", key);
91  		map.put("value", value);
92  		return map;
93  	}
94  }