View Javadoc

1   package com.explosion.expfmodules.rdbmsconn;
2   /* =============================================================================
3    *       
4    *     Copyright 2004 Stephen Cowx
5    *
6    *     Licensed under the Apache License, Version 2.0 (the "License");
7    *     you may not use this file except in compliance with the License.
8    *     You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *     Unless required by applicable law or agreed to in writing, software
13   *     distributed under the License is distributed on an "AS IS" BASIS,
14   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *     See the License for the specific language governing permissions and
16   *     limitations under the License.
17   * 
18   * =============================================================================
19   */
20  
21  import java.util.Hashtable;
22  import java.util.Properties;
23  import java.util.Vector;
24  import java.util.prefs.Preferences;
25  import javax.swing.JPanel;
26  import com.explosion.expf.ExpActionListener;
27  import com.explosion.expf.ExpConstants;
28  import com.explosion.expf.ExpModuleManager;
29  import com.explosion.expf.preferences.SystemPreferences;
30  import com.explosion.utilities.preferences.Preference;
31  /***
32   * Author: Stephen Cowx
33   * Date: Dec 9, 2002
34   * Time: 11:48:47 PM
35   * 
36   * This module provides database connectivity descriptor persistence to other modules.
37    */
38  public class RdbmsConnModuleManager implements ExpModuleManager
39  {
40    
41  private static final String MODULE_PREFIX = "/dbstore";
42  private Vector preferences = new Vector();
43    private Hashtable preferenceHash = new Hashtable();
44    private static RdbmsConnModuleManager instance = null;
45    private ExpActionListener globalActionListener = null;
46    
47    /* Connection related */
48    private DriverDescriptorManager driverDescriptorManager;
49    private ConnectionDescriptorManager connectionDescriptorManager;
50      
51    public RdbmsConnModuleManager()
52    {
53    	instance = this;
54    }
55    
56    public void initialiseGui() throws Exception
57    {
58      
59    }
60    
61    public String getVersion()
62    {
63      return "1.0";
64    }
65  
66    public String getName()
67    {
68      return "RDBMS Connectivity";
69    }
70  
71    public String getDescription()
72    {
73      return "Support for persisting database connection information and connecting to databases.";
74    }
75  
76    public void applyPreferences()
77    {
78    }
79  
80    public void initialiseCore(Properties properties)
81    {
82      try
83      {
84        String appPrefix =  (String) SystemPreferences.getPreference(ExpConstants.EXPF_APP_PREFIX).getValue();
85        
86        Preferences prefs = Preferences.userRoot().node(appPrefix+MODULE_PREFIX);
87  
88        Preferences drvrDescriptors = prefs.node(RdbmsConnConstants.DRVR_DESCRIPTORS);
89        driverDescriptorManager = new DriverDescriptorManager(drvrDescriptors);
90  //      String driverFileName = properties.getProperty(RdbmsConnConstants.DRIVER_PROPERTIES_FILE_NAME_OVERRIDE);
91  //      if (driverFileName != null )
92  //      {
93  //         driverDescriptorManager.loadUsing(getPreferenceRoot(),driverFileName);
94  //      }
95  //      else
96  //      {
97  //        driverDescriptorManager.loadUsing(prefs);
98  //      }
99      
100       Preferences cnctnDescriptors = prefs.node(RdbmsConnConstants.CONNECTION_DESCRIPTORS);
101       connectionDescriptorManager = new ConnectionDescriptorManager(driverDescriptorManager, cnctnDescriptors);
102       
103       Preference maxRowsReturned = new Preference(RdbmsConnConstants.RDBMS_OPTION_MAXROWSRETURNED, Preference.PROPERTY_TYPE_INT, new Integer(50000), prefs);
104       maxRowsReturned.setLongName("Maximum rows returned.");
105       maxRowsReturned.setDescription("This indicates the maximum number of rows to return from the database for any query.  Setting this value to 0 means that there will be no limit.");
106       preferences.addElement(maxRowsReturned);
107       preferenceHash.put(RdbmsConnConstants.RDBMS_OPTION_MAXROWSRETURNED, maxRowsReturned);
108       
109       
110     }
111     catch (Exception e)
112     {
113       com.explosion.utilities.exception.ExceptionManagerFactory.getExceptionManager().manageException(e, "Exception caught while initialising dbstore properties.");
114     }
115   }
116 
117   public Vector getPreferences()
118   {
119     return null;
120   }
121 
122 
123   public Preference getPreference(String preferenceName)
124   {
125   	return (Preference) preferenceHash.get(preferenceName);
126   }
127   
128   public JPanel getPreferencesEditor()
129   {
130     return null;
131   }
132   
133   public ExpActionListener getGlobalListener()
134   {
135   	return globalActionListener;
136   }
137   
138   public static RdbmsConnModuleManager instance()
139   {
140     return instance;
141   }
142  
143   public String getPreferenceRoot()
144   {
145     return (String) SystemPreferences.getPreference(ExpConstants.EXPF_APP_PREFIX).getValue()+MODULE_PREFIX;
146   }
147   
148   /***
149    * Returns the connectionDescriptorManager.
150    * @return ConnectionDescriptorManager
151    */
152   public ConnectionDescriptorManager getConnectionDescriptorManager()
153   {
154     return connectionDescriptorManager;
155   }
156 
157   /***
158    * Sets the connectionDescriptorManager.
159    * @param connectionDescriptorManager The connectionDescriptorManager to set
160    */
161   public void setConnectionDescriptorManager(ConnectionDescriptorManager connectionDescriptorManager)
162   {
163     this.connectionDescriptorManager = connectionDescriptorManager;
164   }
165   
166   /***
167    * Returns the driverDescriptorManager.
168    * @return DriverDescriptorManager
169    */
170   public DriverDescriptorManager getDriverDescriptorManager()
171   {
172     return driverDescriptorManager;
173   }
174 
175   /***
176    * Sets the driverDescriptorManager.
177    * @param driverDescriptorManager The driverDescriptorManager to set
178    */
179   public void setDriverDescriptorManager(DriverDescriptorManager driverDescriptorManager)
180   {
181     this.driverDescriptorManager = driverDescriptorManager;
182   }
183   
184 }