View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/install/src/java/org/astrogrid/community/install/ant/DatabaseManagerTask.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/06/18 13:45:20 $</cvs:date>
5    * <cvs:version>$Revision: 1.3 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: DatabaseManagerTask.java,v $
9    *   Revision 1.3  2004/06/18 13:45:20  dave
10   *   Merged development branch, dave-dev-200406081614, into HEAD
11   *
12   *   Revision 1.2.32.1  2004/06/17 13:38:59  dave
13   *   Tidied up old CVS log entries
14   *
15   * </cvs:log>
16   *
17   *
18   */
19  package org.astrogrid.community.install.ant ;
20  
21  import java.net.URL ;
22  
23  import org.apache.tools.ant.Task ;
24  import org.apache.tools.ant.BuildException ;
25  
26  import org.astrogrid.community.client.database.manager.DatabaseManagerSoapDelegate ;
27  
28  /***
29   * An Ant task to control the Community DatabaseManager service.
30   * 
31   */
32  public class DatabaseManagerTask
33      extends Task
34      {
35      /***
36       * Our debug flag.
37       *
38       */
39      private static final boolean DEBUG_FLAG = true ;
40  
41      /***
42       * Public constructor.
43       *
44       */
45      public DatabaseManagerTask()
46          {
47          //
48          // Initialise our base class.
49          super() ;
50          }
51  
52      /***
53       * Public constructor.
54       *
55       */
56      public DatabaseManagerTask(Task parent)
57          {
58          //
59          // Initialise our base class.
60          super() ;
61          //
62          // Set our project.
63          setProject(parent.getProject()) ;
64          }
65  
66      /***
67       * Initialise our Task.
68       *
69       */
70      public void init()
71          throws BuildException
72          {
73          if (DEBUG_FLAG) System.out.println("----\"----");
74          if (DEBUG_FLAG) System.out.println("DatabaseManagerTask.init()");
75          }
76  
77      /***
78       * Our DatabaseManager service endpoint.
79       *
80       */
81      private String endpoint ;
82  
83      /***
84       * Get our DatabaseManager service endpoint.
85       *
86       */
87      public String getEndpoint()
88          {
89          return this.endpoint ;
90          }
91  
92      /***
93       * Set our DatabaseManager service endpoint.
94       *
95       */
96      public void setEndpoint(String value)
97          {
98          this.endpoint = value ;
99          }
100 
101     /***
102      * The action we want to perform.
103      *
104      */
105     private String action ;
106 
107     /***
108      * Get the action we want to perform.
109      *
110      */
111     public String getAction()
112         {
113         return this.action ;
114         }
115 
116     /***
117      * Set the action we want to perform.
118      *
119      */
120     public void setAction(String value)
121         {
122         this.action = value ;
123         }
124 
125     /***
126      * Execute our Task.
127      *
128      */
129     public void execute()
130         throws BuildException
131         {
132         if (DEBUG_FLAG) System.out.println("----\"----");
133         if (DEBUG_FLAG) System.out.println("DatabaseManagerTask.execute()");
134         if (DEBUG_FLAG) System.out.println("  Action   : " + this.action);
135         if (DEBUG_FLAG) System.out.println("  Endpoint : " + this.endpoint);
136         //
137         // Check for null action.
138         if (null == action)
139             {
140             throw new BuildException(
141                 "No action specified"
142                 ) ;
143             }
144         //
145         // Check for null endpoint.
146         if (null == endpoint)
147             {
148             throw new BuildException(
149                 "No service endpoint specified"
150                 ) ;
151             }
152         //
153         // Try performing our action.
154         try {
155             //
156             // Create our SOAP delegate.
157             DatabaseManagerSoapDelegate delegate = new DatabaseManagerSoapDelegate(
158                 new URL(this.endpoint)
159                 ) ;
160             //
161             // Check the database status.
162             if ("debug".equals(action))
163                 {
164                 if (DEBUG_FLAG) System.out.println("  Database name   : " + delegate.getDatabaseName());
165                 if (DEBUG_FLAG) System.out.println("  Database config : " + delegate.getDatabaseConfigUrl());
166                 if (DEBUG_FLAG) System.out.println("  Database script : " + delegate.getDatabaseScriptResource());
167                 }
168             //
169             // Check the database tables.
170             if ("status".equals(action))
171                 {
172                 boolean status = delegate.checkDatabaseTables() ;
173                 if (DEBUG_FLAG) System.out.println("  Database tables healthy : " + status);
174                 }
175             //
176             // Reset the database tables.
177             if ("reset".equals(action))
178                 {
179                 if (DEBUG_FLAG) System.out.println("  Resetting database tables ....");
180                 delegate.resetDatabaseTables() ;
181                 boolean status = delegate.checkDatabaseTables() ;
182                 if (DEBUG_FLAG) System.out.println("  Database tables healthy : " + status);
183                 }
184             }
185         catch (Exception ouch)
186             {
187             throw new BuildException(ouch) ;
188             }
189         }
190     }
191