1 package org.whatsitcalled.webflange.model;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6 import org.hibernate.Session;
7 import org.hibernate.Transaction;
8 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
9 import org.whatsitcalled.webflange.file.FileManager;
10 import org.whatsitcalled.webflange.file.FileManagerException;
11
12 public class ScriptDAOHibernate extends HibernateDaoSupport implements
13 ScriptDAO {
14 Logger LOGGER = Logger.getLogger(ScriptDAOHibernate.class);
15
16 FileManager fileManager;
17
18 public Script getScript(Long id) {
19 return (Script) getHibernateTemplate().get(Script.class, id);
20 }
21
22 public List getScripts() {
23 return getHibernateTemplate().find("from Script");
24 }
25
26 public List getScripts(int first, int count, String orderby) {
27
28 String SQL = "from Script order by " + orderby;
29 List scriptList = getHibernateTemplate().find(SQL);
30 System.out.println("Size=" + scriptList.size());
31 return scriptList;
32 }
33
34 public void removeScript(Long id) {
35 Script script = getScript(id);
36 try {
37 fileManager.deleteScriptFile(script);
38 } catch (FileManagerException e) {
39
40 e.printStackTrace();
41 }
42 getHibernateTemplate().delete(script);
43 }
44
45 public void saveScript(Script script) {
46
47 getHibernateTemplate().saveOrUpdate(script);
48 }
49
50 public Script findByName(String name) {
51 String SQL = " from Script as p where p.name=?";
52 List scriptList = getHibernateTemplate().find(SQL, name);
53 Script script = null;
54 if (scriptList.size() > 0) {
55 script = (Script) scriptList.get(0);
56 }
57 return script;
58 }
59
60 public FileManager getFileManager() {
61 return fileManager;
62 }
63
64 public void setFileManager(FileManager fileManager) {
65 this.fileManager = fileManager;
66 }
67
68 }