View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.r1.common.entity;
17  
18  import java.util.Date;
19  
20  import javax.persistence.Embedded;
21  import javax.persistence.MappedSuperclass;
22  
23  import org.kuali.student.common.util.security.SecurityUtils;
24  
25  @MappedSuperclass
26  public abstract class MetaEntity extends BaseEntity{
27  	
28  	@Embedded
29  	private Meta meta;
30  	
31  	@Override
32  	protected void onPrePersist(){
33  		super.onPrePersist();
34  		if(meta==null){
35  			meta = new Meta();
36  		}
37  		meta.setCreateTime(new Date());
38  		meta.setUpdateTime(new Date());
39  
40  		String user = SecurityUtils.getCurrentPrincipalId();
41  		meta.setCreateId(user);
42  		meta.setUpdateId(user);
43  		
44  	}
45  	
46  	@Override
47  	protected void onPreUpdate(){
48  		super.onPreUpdate();
49  		//This code should not be here, but hibernate is calling update callback instead of prepersit if the id is not null.
50  		if(meta==null){
51  			meta = new Meta();
52  			meta.setCreateTime(new Date());
53  		}
54  
55  		meta.setUpdateTime(new Date());
56  
57  		String user = SecurityUtils.getCurrentPrincipalId();
58  		meta.setUpdateId(user);
59  	}
60  
61  	public Meta getMeta() {
62  		return meta;
63  	}
64  
65  	public void setMeta(Meta meta) {
66  		this.meta = meta;
67  	}
68  }