1919
2020import org .apache .log4j .Logger ;
2121import org .buddycloud .channelserver .channel .LocalDomainChecker ;
22+ import org .buddycloud .channelserver .utils .configuration .DatabaseLoader ;
2223import org .xmpp .packet .JID ;
2324
2425public class Configuration extends Properties {
2526
26-
2727 private static final Logger LOGGER = Logger .getLogger (Configuration .class );
2828
2929 private static final long serialVersionUID = 1L ;
@@ -65,11 +65,11 @@ public class Configuration extends Properties {
6565
6666 public static final String XMPP_HOST = "xmpp.host" ;
6767
68- public static final String DATABASE_ENV = "database " ;
68+ public static final String DATABASE_ENV = "DATABASE " ;
6969
70- private static final String JDBC_CONNECTION_STRING = "jdbc.proxool.driver-url" ;
71- private static final String JDBC_PASSWORD = "jdbc.password" ;
72- private static final String JDBC_USER = "jdbc.user" ;
70+ public static final String JDBC_CONNECTION_STRING = "jdbc.proxool.driver-url" ;
71+ public static final String JDBC_PASSWORD = "jdbc.password" ;
72+ public static final String JDBC_USER = "jdbc.user" ;
7373
7474 private static Configuration instance = null ;
7575
@@ -86,36 +86,15 @@ private Configuration() {
8686 if (null == databaseConnectionString ) {
8787 loadConfigurationFromFile ();
8888 } else {
89- loadConfigurationFromDatabase (databaseConnectionString );
89+ DatabaseLoader loader = new DatabaseLoader (this , databaseConnectionString );
90+ loader .load ();
9091 }
9192
9293 } catch (Exception e ) {
9394 LOGGER .error ("Could not load configuration" );
9495 System .exit (1 );
9596 }
96- }
97-
98- private void loadConfigurationFromDatabase (String connectionString ) throws SQLException {
99- Connection connection = null ;
100- try {
101- connection = DriverManager .getConnection (connectionString );
102- PreparedStatement statement = connection .prepareStatement ("SELECT \" key\" , \" value\" FROM 'configuration';" );
103- ResultSet rs = statement .executeQuery ();
104- while (rs .next ()) {
105- conf .setProperty (rs .getString (1 ), rs .getString (2 ));
106- }
107- conf .setProperty (JDBC_CONNECTION_STRING , connectionString );
108- conf .remove (JDBC_USER );
109- conf .remove (JDBC_PASSWORD );
110- } catch (SQLException e ) {
111- LOGGER .error ("Could not get configuration from database" );
112- System .exit (1 );
113- } finally {
114- if (null != connection ) {
115- connection .close ();
116- }
117- }
118-
97+ setupCollections ();
11998 }
12099
121100 private void loadConfigurationFromFile () throws IOException {
@@ -177,7 +156,6 @@ public void putProperty(String key, String value) {
177156
178157 public void load (InputStream inputStream ) throws IOException {
179158 conf .load (inputStream );
180- setupCollections ();
181159 }
182160
183161 private Collection <String > getStringArrayProperty (String key ) {
@@ -291,4 +269,12 @@ public String getDatabaseConnectionUrl() {
291269 public boolean containsKey (Object value ) {
292270 return conf .containsKey (value );
293271 }
272+
273+ public Object setProperty (String key , String value ) {
274+ return conf .setProperty (key , value );
275+ }
276+
277+ public void removeKey (String key ) {
278+ conf .remove (key );
279+ }
294280}
0 commit comments