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.common_test_tester.support;
17  
18  import java.util.List;
19  
20  import javax.persistence.EntityManager;
21  import javax.persistence.PersistenceContext;
22  import javax.persistence.Query;
23  
24  @Deprecated
25  public class MyDaoImpl implements MyDao {
26  	
27  	private EntityManager entityManager;
28  
29  	@PersistenceContext
30  	public void setEntityManager(EntityManager entityManager) {
31  		this.entityManager = entityManager;
32  	}
33  	
34  	public String createValue(Value value) {
35  		entityManager.persist(value);
36  		return value.getId();
37  	}
38  
39  	public String findValue(String id) {
40  		Value tv =  entityManager.find(Value.class, id);
41  		if(tv==null){
42  			return null;
43  		}
44  		return tv.getValue();
45  	}
46  
47  	@SuppressWarnings("unchecked")
48  	public Value findValueFromValue(String value) {
49  		Query q = entityManager.createQuery("SELECT v FROM Value v WHERE v.value=:valueIn");
50  		q.setParameter("valueIn", value);
51  		for(Value tv : (List<Value>)q.getResultList()){
52  			return tv;
53  		}
54  		return null;
55  	}
56  
57  	public boolean updateValue(String id, String value) {
58  		Value v = entityManager.find(Value.class, id);
59  		v.setValue(value);
60  		entityManager.merge(v);
61  		return true;
62  	}
63  	
64  }