|
From: <tr...@us...> - 2003-06-27 02:06:02
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/resource In directory sc8-pr-cvs1:/tmp/cvs-serv31771/src/com/babeldoc/sql/resource Modified Files: PooledJdbc.java SimpleJdbc.java Log Message: Reformatted and updated license header Index: PooledJdbc.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/resource/PooledJdbc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PooledJdbc.java 15 Mar 2003 23:45:36 -0000 1.2 --- PooledJdbc.java 27 Jun 2003 02:05:59 -0000 1.3 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/21 17:01:20 $ * * ! * babeldoc: universal document processor * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.babeldoc.sql.resource; --- 1,66 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ * */ package com.babeldoc.sql.resource; *************** *** 24,27 **** --- 68,72 ---- import com.babeldoc.core.resource.Resource; import com.babeldoc.core.resource.ResourceException; + import org.apache.commons.dbcp.ConnectionFactory; import org.apache.commons.dbcp.DriverManagerConnectionFactory; *************** *** 34,90 **** import java.sql.DriverManager; /** ! * The pooled driver. This driver uses the jakarta-commons pooling infrastructre ! * and is quite efficient. Use this, not the simple jdbc resource. * * @author Bmcdonald * @version 1.0 */ ! public class PooledJdbc ! extends Resource { ! ! /** ! * the connection pool stuff. ! */ private static PoolingDriver driver = new PoolingDriver(); ! /** ! * the user and database url stuff. ! */ private static String DB_USER = "dbUser"; private static String DB_PASSWD = "dbPassword"; private static String DB_URL = "dbUrl"; ! /** ! * Jdbc variables ! */ private String dbName; private String dbPasswd; private String dbUrl; - public void setupDriver(String connectURI) - throws Exception { - ObjectPool connectionPool = new GenericObjectPool(null); - ConnectionFactory connectionFactory = new - DriverManagerConnectionFactory(connectURI, dbName, dbPasswd); - PoolableConnectionFactory poolableConnectionFactory = - new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); - driver.registerPool(getName(), connectionPool); - - // convert to the url that talks to the connection pool - dbUrl = "jdbc:apache:commons:dbcp:" + getName(); - } - /** ! * Setup the jdbc stuff */ ! private void setupJdbc() ! throws Exception { try { ! dbName = getConfig().getString(DB_USER); ! dbPasswd = getConfig().getString(DB_PASSWD); ! setupDriver(getConfig().getString(DB_URL)); ! } catch (Exception x) { ! com.babeldoc.core.LogService.getInstance().logError(x); } } --- 79,117 ---- import java.sql.DriverManager; + /** ! * The pooled driver. This driver uses the jakarta-commons pooling ! * infrastructre and is quite efficient. Use this, not the simple jdbc ! * resource. * * @author Bmcdonald * @version 1.0 */ ! public class PooledJdbc extends Resource { ! /** the connection pool stuff. */ private static PoolingDriver driver = new PoolingDriver(); ! /** the user and database url stuff. */ private static String DB_USER = "dbUser"; private static String DB_PASSWD = "dbPassword"; private static String DB_URL = "dbUrl"; ! /** Jdbc variables */ private String dbName; private String dbPasswd; private String dbUrl; /** ! * Checkin this connection ! * ! * @param connection ! * ! * @throws ResourceException */ ! public synchronized void checkIn(Object connection) throws ResourceException { try { ! ((Connection) connection).close(); ! } catch (Exception e) { ! throw new ResourceException("[ResourceException.checkIn]", e); } } *************** *** 94,101 **** * * @return the connection ! * @throws com.babeldoc.core.resource.ResourceException */ ! public synchronized Object checkOut() ! throws ResourceException { try { // if we have no dbUrl, setup jdbc NOW --- 121,128 ---- * * @return the connection ! * ! * @throws ResourceException */ ! public synchronized Object checkOut() throws ResourceException { try { // if we have no dbUrl, setup jdbc NOW *************** *** 103,106 **** --- 130,134 ---- setupJdbc(); } + return DriverManager.getConnection(dbUrl, dbName, dbPasswd); } catch (Exception e) { *************** *** 110,123 **** /** ! * Checkin this connection ! * @param connection ! * @throws com.babeldoc.core.resource.ResourceException */ ! public synchronized void checkIn(Object connection) ! throws ResourceException { try { ! ((Connection) connection).close(); ! } catch (Exception e) { ! throw new ResourceException("[ResourceException.checkIn]", e); } } --- 138,171 ---- /** ! * TODO: DOCUMENT ME! ! * ! * @param connectURI DOCUMENT ME! ! * ! * @throws Exception DOCUMENT ME! */ ! public void setupDriver(String connectURI) throws Exception { ! ObjectPool connectionPool = new GenericObjectPool(null); ! ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, ! dbName, dbPasswd); ! PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, ! connectionPool, null, null, false, true); ! driver.registerPool(getName(), connectionPool); ! ! // convert to the url that talks to the connection pool ! dbUrl = "jdbc:apache:commons:dbcp:" + getName(); ! } ! ! /** ! * Setup the jdbc stuff ! * ! * @throws Exception DOCUMENT ME! ! */ ! private void setupJdbc() throws Exception { try { ! dbName = getConfig().getString(DB_USER); ! dbPasswd = getConfig().getString(DB_PASSWD); ! setupDriver(getConfig().getString(DB_URL)); ! } catch (Exception x) { ! com.babeldoc.core.LogService.getInstance().logError(x); } } Index: SimpleJdbc.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/resource/SimpleJdbc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleJdbc.java 15 Mar 2003 23:45:36 -0000 1.2 --- SimpleJdbc.java 27 Jun 2003 02:05:59 -0000 1.3 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/21 17:01:20 $ * * ! * babeldoc: universal document processor * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.babeldoc.sql.resource; --- 1,66 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ * */ package com.babeldoc.sql.resource; *************** *** 28,72 **** import java.sql.DriverManager; /** ! * How to get connections using the simplest jdbc code, etc. This merely creates ! * new connections every time the resource is checked out. Not too good especially ! * for drives / databases that have a limited number of connections like Oracle. ! * Use the Pooled driver instead. * * @author Bmcdonald * @version 1.0 */ ! public class SimpleJdbc ! extends Resource { ! ! public final static String DB_USER = "dbUser"; ! public final static String DB_PASSWD = "dbPassword"; ! public final static String DB_DRIVER = "dbDriver"; ! public final static String DB_URL = "dbUrl"; ! /** ! * Jdbc variables ! */ private String dbName; private String dbPasswd; - private String dbDriver; private String dbUrl; /** ! * Setup the jdbc stuff */ ! private void setupJdbc() { try { ! dbName = getConfig().getString(DB_USER); ! dbPasswd = getConfig().getString(DB_PASSWD); ! dbDriver = getConfig().getString(DB_DRIVER); ! dbUrl = getConfig().getString(DB_URL); ! ! if (dbName != null && dbPasswd != null && dbDriver != null && dbUrl != null) { ! Class.forName(dbDriver).newInstance(); ! } ! } catch (Exception x) { ! com.babeldoc.core.LogService.getInstance().logError(x); ! dbUrl = null; } } --- 72,109 ---- import java.sql.DriverManager; + /** ! * How to get connections using the simplest jdbc code, etc. This merely ! * creates new connections every time the resource is checked out. Not too ! * good especially for drives / databases that have a limited number of ! * connections like Oracle. Use the Pooled driver instead. * * @author Bmcdonald * @version 1.0 */ ! public class SimpleJdbc extends Resource { ! public static final String DB_USER = "dbUser"; ! public static final String DB_PASSWD = "dbPassword"; ! public static final String DB_DRIVER = "dbDriver"; ! public static final String DB_URL = "dbUrl"; ! private String dbDriver; ! /** Jdbc variables */ private String dbName; private String dbPasswd; private String dbUrl; /** ! * Checkin this connection ! * ! * @param connection ! * ! * @throws ResourceException */ ! public synchronized void checkIn(Object connection) throws ResourceException { try { ! ((Connection) connection).close(); ! } catch (Exception e) { ! throw new ResourceException("[ResourceException.checkIn]", e); } } *************** *** 76,83 **** * * @return the connection ! * @throws com.babeldoc.core.resource.ResourceException */ ! public synchronized Object checkOut() ! throws ResourceException { try { // if we have no dbUrl, setup jdbc NOW --- 113,120 ---- * * @return the connection ! * ! * @throws ResourceException */ ! public synchronized Object checkOut() throws ResourceException { try { // if we have no dbUrl, setup jdbc NOW *************** *** 85,88 **** --- 122,126 ---- setupJdbc(); } + return DriverManager.getConnection(dbUrl, dbName, dbPasswd); } catch (Exception e) { *************** *** 92,106 **** /** ! * Checkin this connection ! * ! * @param connection ! * @throws com.babeldoc.core.resource.ResourceException */ ! public synchronized void checkIn(Object connection) ! throws ResourceException { try { ! ((Connection) connection).close(); ! } catch (Exception e) { ! throw new ResourceException("[ResourceException.checkIn]", e); } } --- 130,149 ---- /** ! * Setup the jdbc stuff */ ! private void setupJdbc() { try { ! dbName = getConfig().getString(DB_USER); ! dbPasswd = getConfig().getString(DB_PASSWD); ! dbDriver = getConfig().getString(DB_DRIVER); ! dbUrl = getConfig().getString(DB_URL); ! ! if ((dbName != null) && (dbPasswd != null) && (dbDriver != null) && ! (dbUrl != null)) { ! Class.forName(dbDriver).newInstance(); ! } ! } catch (Exception x) { ! com.babeldoc.core.LogService.getInstance().logError(x); ! dbUrl = null; } } |