1 /*** 2 * The contents of this file are subject to the Mozilla Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/MPL/ 6 * 7 * Software distributed under the License is distributed on an "AS 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is pow2toolkit library. 13 * 14 * The Initial Owner of the Original Code is 15 * Power Of Two S.R.L. (www.pow2.com) 16 * 17 * Portions created by Power Of Two S.R.L. are 18 * Copyright (C) Power Of Two S.R.L. 19 * All Rights Reserved. 20 * 21 * Contributor(s): 22 */ 23 24 package com.pow2.resources; 25 26 27 import javax.servlet.ServletException; 28 29 import com.pow2.dao.ConnectionFactory; 30 import com.pow2.dao.ConnectionProviderPrefs; 31 32 33 /*** 34 * ConnectionFactory init servlet. 35 * <br> 36 * Configure and initialize the ConnectionFactory object 37 * defining the following servlet into the web.xml file of your web-application. 38 * 39 * <code> 40 * <pre> 41 * <servlet> 42 * <servlet-name>connectionFactory-init</servlet-name> 43 * <servlet-class>com.pow2.resources.ConnectionFactoryInit</servlet-class> 44 * 45 * <load-on-startup>2</load-on-startup> 46 * </servlet> 47 * </pre> 48 * </code> 49 * 50 * Note: this servlet should be loaded <br>after</br> the Pow2ToolkitInit servlet. 51 */ 52 public class ConnectionFactoryInit extends InitServlet 53 { 54 /*** 55 * Initialize the ConnectionFactory object. 56 */ 57 public void init() throws ServletException 58 { 59 super.init(); 60 61 Prefs prefs = Prefs.instance(); 62 63 ConnectionProviderPrefs cpPrefs = new ConnectionProviderPrefs(); 64 cpPrefs.setConnectionProviderClass (prefs.getProperty("jdbc.cp.class")); 65 cpPrefs.setConnectionPoolURL (prefs.getProperty("jdbc.cp.url")); 66 cpPrefs.setJdbcDriver (prefs.getProperty("jdbc.driver")); 67 cpPrefs.setJdbcURL (prefs.getProperty("jdbc.url")); 68 cpPrefs.setUser (prefs.getProperty("jdbc.user")); 69 cpPrefs.setPassword (prefs.getProperty("jdbc.passwd")); 70 71 try 72 { 73 ConnectionFactory.instance().setProvider(cpPrefs); 74 } 75 catch(Exception e) 76 { 77 cat.error("::init - cannot set or initialize the connection provider", e); 78 throw new ServletException(e.getMessage()); 79 } 80 81 cat.info("::init - ConnectionFactory successfully configured"); 82 } 83 }