KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > presentation > UpdateSite


1 /*
2  * snapper
3  *
4  * Enhydra super-servlet presentation object
5  *
6  */

7
8 package org.enhydra.snapper.presentation;
9
10 // Enhydra SuperServlet imports
11

12 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
13
14 // Enhydra SuperServlet specification imports
15

16 import org.enhydra.dods.DODS;
17 import org.enhydra.snapper.SnapperManager;
18
19 import org.enhydra.snapper.spec.*;
20
21 import org.enhydra.xml.xmlc.XMLObject;
22
23 // Standard imports
24

25 public class UpdateSite extends BasePO {
26
27
28     protected XMLObject getDOM() throws Exception JavaDoc {
29         
30         String JavaDoc siteID = comms.request.getParameter("id");
31
32         Site site = null;
33         Path[] pathArray = null;
34         UpdaterSpec updater = null;
35         Update update = null;
36         
37         if (comms.request.getParameter("action") !=null){
38                 if (comms.request.getParameter("action").equals("updateAllAtOnce")){
39                     updateAtOnce();}
40                 else updateOneByOne();
41             
42             throw new ClientPageRedirectException(comms.request
43                     .getAppFileURIPath("SiteListPresentation.po"));
44         }
45                     
46                     
47         try {
48             site = (SiteFactory.getSite("org.enhydra.snapper.business.SiteImpl")).findSiteByID(siteID, dbTransaction);
49
50             if (site.getLOCKED() == true) {
51             SnapperManager.getInstance().getLoggingManager().info(
52             "Site locked! Indexing Aborted.");
53             throw new ClientPageRedirectException(comms.request
54                     .getAppFileURIPath("SiteListPresentation.po?l=" + site.getName()));
55         }
56         } catch (Exception JavaDoc e) {SnapperManager.getInstance().getLoggingManager().error("Could not check lock");}
57
58         
59         try{
60             update = UpdateThreadFactory.getUpdateThread("org.enhydra.snapper.business.UpdateThread");
61         } catch (Exception JavaDoc ex) {System.out.println("Exception: " + ex);
62         }
63         
64         update.update(siteID, DODS.getDatabaseManager());
65         SnapperManager.getInstance().addThread(siteID, update);
66         
67         Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) update, siteID);
68         DODS.register(newThread,DODS.getDatabaseManager());
69         newThread.start();
70         
71         //new Thread((Runnable) update, siteID).start();
72

73         throw new ClientPageRedirectException(comms.request.getAppFileURIPath("SiteListPresentation.po?u=" + site.getName()));
74
75     }
76     
77     private void updateAtOnce(){
78         Site[] list;
79         try {
80             SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
81             list = sl.getList(dbTransaction);
82             
83         }catch (Exception JavaDoc ex){
84             System.out.println("Exception: "+ex);
85             list = null;
86         }
87         
88         for (int numSites = 0; numSites < list.length; numSites++) {
89             try{
90                 String JavaDoc id = list[numSites].getID();
91                 Update update = UpdateThreadFactory.getUpdateThread("org.enhydra.snapper.business.UpdateThread");
92                 update.update(id, DODS.getDatabaseManager());
93                 
94                 Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) update, id);
95                 DODS.register(newThread,DODS.getDatabaseManager());
96                 newThread.start();
97                 
98                // new Thread((Runnable) update, id).start();
99
SnapperManager.getInstance().addThread(id, update);
100             } catch (Exception JavaDoc e){SnapperManager.getInstance().getLoggingManager().error("Could not update site");}
101         }
102     }
103     
104     private void updateOneByOne(){
105         Site[] list;
106         try {
107             SiteList sl = SiteListFactory.getSiteList("org.enhydra.snapper.business.SiteListImpl");
108             list = sl.getList(dbTransaction);
109             String JavaDoc[] ids = new String JavaDoc[list.length];
110             for (int i=0; i< list.length; i++){
111                 ids[i] = list[i].getID();
112             }
113             
114             UpdateAll updateall;
115             updateall = UpdateAllFactory.getUpdateAll("org.enhydra.snapper.business.UpdateAllImpl");
116             updateall.update(ids, DODS.getDatabaseManager());
117             
118             Thread JavaDoc newThread = new Thread JavaDoc((Runnable JavaDoc) updateall);
119             DODS.register(newThread,DODS.getDatabaseManager());
120             newThread.start();
121             
122             //new Thread((Runnable) updateall).start();
123

124         }catch (Exception JavaDoc ex){
125             System.out.println("Exception: "+ex);
126             list = null;
127         }
128         
129     }
130 }
131
Popular Tags