001 /**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016 package org.kuali.student.common_test_tester.support;
017
018 import java.util.List;
019
020 import javax.persistence.EntityManager;
021 import javax.persistence.PersistenceContext;
022 import javax.persistence.Query;
023
024 public class MyDaoImpl implements MyDao {
025
026 private EntityManager entityManager;
027
028 @PersistenceContext
029 public void setEntityManager(EntityManager entityManager) {
030 this.entityManager = entityManager;
031 }
032
033 public String createValue(Value value) {
034 entityManager.persist(value);
035 return value.getId();
036 }
037
038 public String findValue(String id) {
039 Value tv = entityManager.find(Value.class, id);
040 if(tv==null){
041 return null;
042 }
043 return tv.getValue();
044 }
045
046 @SuppressWarnings("unchecked")
047 public Value findValueFromValue(String value) {
048 Query q = entityManager.createQuery("SELECT v FROM Value v WHERE v.value=:valueIn");
049 q.setParameter("valueIn", value);
050 for(Value tv : (List<Value>)q.getResultList()){
051 return tv;
052 }
053 return null;
054 }
055
056 public boolean updateValue(String id, String value) {
057 Value v = entityManager.find(Value.class, id);
058 v.setValue(value);
059 entityManager.merge(v);
060 return true;
061 }
062
063 }