View Javadoc

1   package org.whatsitcalled.webflange.model;
2   
3   import java.util.List;
4   
5   import org.apache.commons.io.IOUtils;
6   import org.apache.log4j.Logger;
7   import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
8   import org.whatsitcalled.webflange.ResourceFactory;
9   import org.whatsitcalled.webflange.engine.TestSchedulerException;
10  import org.whatsitcalled.webflange.file.FileManager;
11  import org.whatsitcalled.webflange.file.FileManagerException;
12  
13  public class LoadTestDAOHibernate extends HibernateDaoSupport implements
14  		LoadTestDAO {
15  
16  	Logger LOGGER = Logger.getLogger(LoadTestDAOHibernate.class);
17  	FileManager fileManager;
18  
19  	public LoadTest getLoadTest(Long id) {
20  		return (LoadTest) getHibernateTemplate().get(LoadTest.class, id);
21  	}
22  
23  	public List getLoadTests() {
24  		List find = getHibernateTemplate().find("from LoadTest");
25  		return find;
26  	}
27  
28  	public List getLoadTests(int first, int count, String orderby) {
29  		String SQL = "from LoadTest order by " + orderby;
30  		List testList = getHibernateTemplate().find(SQL);
31  		//System.out.println("Size=" + testList.size());
32  		return testList;
33  	}
34  
35  	public void removeLoadTest(Long id) {
36  		LoadTest loadTest = getLoadTest(id);
37  		try {
38  			fileManager.deletePropertyFile(loadTest);
39  		} catch (FileManagerException e) {
40  			// TODO throw DAO exception
41  			e.printStackTrace();
42  		}
43  		
44  		getHibernateTemplate().delete(loadTest);
45  	}
46  
47  	public void saveLoadTest(LoadTest loadTest) {
48  
49  		getHibernateTemplate().saveOrUpdate(loadTest);
50  		try {
51  			ResourceFactory.getTestScheduler().processTest(loadTest);
52  		} catch (TestSchedulerException e) {
53  			//TODO This should throw when validation fails
54  			LOGGER.error("Unable to process LoadTest: " + loadTest);
55  		}
56  		
57  	}
58  
59  	public LoadTest findByName(String name) {
60  		String SQL = " from LoadTest as t where t.name=?";
61  		List testList = getHibernateTemplate().find(SQL, name);
62  		LoadTest loadTest = null;
63  		if (testList.size() > 0) {
64  			loadTest = (LoadTest) testList.get(0);
65  		}
66  		return loadTest;
67  	}
68  
69  	public List findByProject(Long projectId) {
70  		String SQL = " from LoadTest as t where t.project.id=?";
71  		List testList = getHibernateTemplate().find(SQL, projectId);
72  		//System.out.println("Size=" + testList.size());
73  		return testList;
74  	}
75  
76  	public List findByScript(Long scriptId) {
77  		String SQL = " from LoadTest as t where t.script.id=?";
78  		List testList = getHibernateTemplate().find(SQL, scriptId);
79  		//System.out.println("Size=" + testList.size());
80  		return testList;
81  	}
82  
83  	public FileManager getFileManager() {
84  		return fileManager;
85  	}
86  
87  	public void setFileManager(FileManager fileManager) {
88  		this.fileManager = fileManager;
89  	}
90  }