1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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