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.edl.impl.extract; 017 018 import javax.persistence.CascadeType; 019 import javax.persistence.Column; 020 import javax.persistence.Entity; 021 import javax.persistence.FetchType; 022 import javax.persistence.GeneratedValue; 023 import javax.persistence.Id; 024 import javax.persistence.JoinColumn; 025 import javax.persistence.ManyToOne; 026 import javax.persistence.Table; 027 import javax.persistence.Version; 028 029 import org.hibernate.annotations.GenericGenerator; 030 import org.hibernate.annotations.Parameter; 031 import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; 032 import org.kuali.rice.edl.framework.extract.FieldDTO; 033 import org.kuali.rice.krad.service.KRADServiceLocator; 034 035 /** 036 * 037 * 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 * 041 */ 042 @Entity 043 @Table(name="KREW_EDL_FLD_DMP_T") 044 //@Sequence(name="KREW_EDL_FLD_DMP_S", property="fieldId") 045 public class Fields { 046 047 private static final long serialVersionUID = -6136544551121011531L; 048 049 @Id 050 @GeneratedValue(generator="KREW_EDL_FLD_DMP_S") 051 @GenericGenerator(name="KREW_EDL_FLD_DMP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ 052 @Parameter(name="sequence_name",value="KREW_EDL_FLD_DMP_S"), 053 @Parameter(name="value_column",value="id") 054 }) 055 @Column(name="EDL_FIELD_DMP_ID") 056 private Long fieldId; 057 @Column(name="DOC_HDR_ID") 058 private String docId; 059 @Column(name="FLD_NM") 060 private String fieldName; 061 @Column(name="FLD_VAL") 062 private String fieldValue; 063 @Version 064 @Column(name="VER_NBR") 065 private Integer lockVerNbr; 066 067 @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.PERSIST}) 068 @JoinColumn(name="DOC_HDR_ID", insertable=false, updatable=false) 069 private Dump dump; 070 071 //@PrePersist 072 public void beforeInsert(){ 073 OrmUtils.populateAutoIncValue(this, KRADServiceLocator.getEntityManagerFactory().createEntityManager()); 074 } 075 076 077 public Long getFieldId() { 078 return fieldId; 079 } 080 public String getDocId() { 081 return docId; 082 } 083 public void setDocId(final String docId) { 084 this.docId = docId; 085 } 086 public String getFieldValue() { 087 return fieldValue; 088 } 089 public void setFieldValue(final String fieldValue) { 090 this.fieldValue = fieldValue; 091 } 092 public String getFiledName() { 093 return fieldName; 094 } 095 public void setFieldName(final String filedName) { 096 this.fieldName = filedName; 097 } 098 public Integer getLockVerNbr() { 099 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