View Javadoc

1   /**
2    * Copyright 2005-2014 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.edl.impl.extract;
17  
18  import javax.persistence.CascadeType;
19  import javax.persistence.Column;
20  import javax.persistence.Entity;
21  import javax.persistence.FetchType;
22  import javax.persistence.GeneratedValue;
23  import javax.persistence.Id;
24  import javax.persistence.JoinColumn;
25  import javax.persistence.ManyToOne;
26  import javax.persistence.Table;
27  import javax.persistence.Version;
28  
29  import org.hibernate.annotations.GenericGenerator;
30  import org.hibernate.annotations.Parameter;
31  import org.kuali.rice.core.framework.persistence.jpa.OrmUtils;
32  import org.kuali.rice.edl.framework.extract.FieldDTO;
33  import org.kuali.rice.krad.service.KRADServiceLocator;
34  
35  /**
36   *
37   *
38   *
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   *
41   */
42  @Entity
43  @Table(name="KREW_EDL_FLD_DMP_T")
44  //@Sequence(name="KREW_EDL_FLD_DMP_S", property="fieldId")
45  public class Fields {
46  
47  	private static final long serialVersionUID = -6136544551121011531L;
48  
49      @Id
50      @GeneratedValue(generator="KREW_EDL_FLD_DMP_S")
51  	@GenericGenerator(name="KREW_EDL_FLD_DMP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
52  			@Parameter(name="sequence_name",value="KREW_EDL_FLD_DMP_S"),
53  			@Parameter(name="value_column",value="id")
54  	})
55  	@Column(name="EDL_FIELD_DMP_ID")
56  	private Long fieldId;
57      @Column(name="DOC_HDR_ID")
58  	private String docId;
59      @Column(name="FLD_NM")
60  	private String fieldName;
61      @Column(name="FLD_VAL")
62  	private String fieldValue;
63      @Version
64  	@Column(name="VER_NBR")
65  	private Integer lockVerNbr;
66  
67      @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST})
68  	@JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false)
69  	private Dump dump;
70  
71      //@PrePersist
72      public void beforeInsert(){
73          OrmUtils.populateAutoIncValue(this, KRADServiceLocator.getEntityManagerFactory().createEntityManager());
74      }
75  
76  
77  	public Long getFieldId() {
78  		return fieldId;
79  	}
80  	public String getDocId() {
81  		return docId;
82  	}
83  	public void setDocId(final String docId) {
84  		this.docId = docId;
85  	}
86  	public String getFieldValue() {
87  		return fieldValue;
88  	}
89  	public void setFieldValue(final String fieldValue) {
90  		this.fieldValue = fieldValue;
91  	}
92  	public String getFiledName() {
93  		return fieldName;
94  	}
95  	public void setFieldName(final String filedName) {
96  		this.fieldName = filedName;
97  	}
98  	public Integer getLockVerNbr() {
99  		return lockVerNbr;
100 	}
101 	public void setLockVerNbr(final Integer lockVerNbr) {
102 		this.lockVerNbr = lockVerNbr;
103 	}
104 	public Dump getDump() {
105 		return dump;
106 	}
107 	public void setDump(final Dump dump) {
108 		this.dump = dump;
109 	}
110 	
111 	public static FieldDTO to(Fields field) {
112 		if (field == null) {
113 			return null;
114 		}
115 		FieldDTO fieldDTO = new FieldDTO();
116 		fieldDTO.setDocId(field.getDocId());
117 		fieldDTO.setFieldName(field.getFiledName());
118 		fieldDTO.setFieldValue(field.getFieldValue());
119 		fieldDTO.setLockVerNbr(field.getLockVerNbr());
120 		return fieldDTO;
121 	}
122 	
123 	public static Fields from(FieldDTO fieldDTO, Dump dump) {
124 		if (fieldDTO == null) {
125 			return null;
126 		}
127 		Fields fields = new Fields();
128 		fields.setDump(dump);
129 		fields.setDocId(fieldDTO.getDocId());
130 		fields.setFieldName(fieldDTO.getFiledName());
131 		fields.setFieldValue(fieldDTO.getFieldValue());
132 		fields.setLockVerNbr(fieldDTO.getLockVerNbr());
133 		return fields;
134 	}
135 }
136