View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/server/src/java/org/astrogrid/community/server/database/manager/DatabaseManagerImpl.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.6 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: DatabaseManagerImpl.java,v $
9    *   Revision 1.6  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.5.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.5  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.4.52.2  2004/06/17 15:24:31  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.4.52.1  2004/06/17 13:38:59  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
26   *
27   */
28  package org.astrogrid.community.server.database.manager ;
29  
30  import org.apache.commons.logging.Log ;
31  import org.apache.commons.logging.LogFactory ;
32  
33  import java.net.URL ;
34  
35  import org.exolab.castor.jdo.JDO ;
36  
37  import org.astrogrid.community.common.database.manager.DatabaseManager ;
38  
39  import org.astrogrid.community.server.service.CommunityServiceImpl ;
40  import org.astrogrid.community.server.database.configuration.DatabaseConfiguration ;
41  
42  /***
43   * Server side implementation of the DatabaseManager service.
44   *
45   */
46  public class DatabaseManagerImpl
47      extends CommunityServiceImpl
48      implements DatabaseManager
49      {
50      /***
51       * Our debug logger.
52       *
53       */
54      private static Log log = LogFactory.getLog(DatabaseManagerImpl.class);
55  
56      /***
57       * Public constructor, using default database configuration.
58       *
59       */
60      public DatabaseManagerImpl()
61          {
62          super() ;
63          }
64  
65      /***
66       * Public constructor, using specific database configuration.
67       *
68       */
69      public DatabaseManagerImpl(DatabaseConfiguration config)
70          {
71          super(config) ;
72          }
73  
74      /***
75       * Get the current database name.
76       *
77       */
78      public String getDatabaseName()
79          {
80          String result = null ;
81          if (null != this.getDatabaseConfiguration())
82              {
83              result = this.getDatabaseConfiguration().getDatabaseName() ;
84              }
85          return result ;
86          }
87  
88      /***
89       * Get our JDO configuration resource name.
90       *
91       */
92      public String getDatabaseConfigResource()
93          {
94          String result = null ;
95          if (null != this.getDatabaseConfiguration())
96              {
97              result = this.getDatabaseConfiguration().getDatabaseConfigResource() ;
98              }
99          return result ;
100         }
101 
102     /***
103      * Get the database SQL script name.
104      *
105      */
106     public String getDatabaseScriptResource()
107         {
108         String result = null ;
109         if (null != this.getDatabaseConfiguration())
110             {
111             result = this.getDatabaseConfiguration().getDatabaseScriptResource() ;
112             }
113         return result ;
114         }
115 
116     /***
117      * Get the database configuration URL.
118      *
119      */
120     public String getDatabaseConfigUrl()
121         {
122         String result = null ;
123         if (null != this.getDatabaseConfiguration())
124             {
125             URL url = this.getDatabaseConfiguration().getDatabaseConfigUrl() ;
126             if (null != url)
127                 {
128                 result = url.toString() ;
129                 }
130             }
131         return result ;
132         }
133 
134     /***
135      * Get the database engine description.
136      *
137      */
138     public String getDatabaseDescription()
139         {
140         String result = null ;
141         if (null != this.getDatabaseConfiguration())
142             {
143             JDO jdo = this.getDatabaseConfiguration().getDatabaseEngine() ;
144             if (null != jdo)
145                 {
146                 result = jdo.getDescription() ;
147                 }
148             }
149         return result ;
150         }
151 
152     /***
153      * Check our database tables.
154      *
155      */
156     public boolean checkDatabaseTables()
157         {
158         boolean result = false ;
159         if (null != this.getDatabaseConfiguration())
160             {
161             try {
162                 result = this.getDatabaseConfiguration().checkDatabaseTables() ;
163                 }
164             catch (Exception ouch)
165                 {
166                 logException(ouch, "DatabaseManagerImpl.checkDatabaseTables()") ;
167                 }
168             }
169         return result ;
170         }
171 
172     /***
173      * Create our database tables.
174      * Use with care ... this may delete any existing data.
175      *
176      */
177     public void resetDatabaseTables()
178         {
179         if (null != this.getDatabaseConfiguration())
180             {
181             try {
182                 this.getDatabaseConfiguration().resetDatabaseTables() ;
183                 }
184             catch (Exception ouch)
185                 {
186                 logException(ouch, "DatabaseManagerImpl.createDatabaseTables()") ;
187                 }
188             }
189         }
190     }
191 
192 
193