|
From: <tr...@us...> - 2003-06-27 02:06:02
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/util In directory sc8-pr-cvs1:/tmp/cvs-serv31771/src/com/babeldoc/sql/util Modified Files: SqlQueryManager.java TableKeyHelper.java VelocitySqlContext.java Log Message: Reformatted and updated license header Index: SqlQueryManager.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/util/SqlQueryManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SqlQueryManager.java 22 May 2003 03:20:32 -0000 1.5 --- SqlQueryManager.java 27 Jun 2003 02:05:59 -0000 1.6 *************** *** 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.util; --- 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.util; *************** *** 30,46 **** import java.sql.SQLException; /** ! * Description: Provides a very simple interface to the conifguration ! * manager stuff for get sql query strings. This is a useful abstraction ! * so that the queries can get changes on the fly, etc. * * @author bmcdonald * @version 1.0 */ - public class SqlQueryManager { ! /** ! * Configuration constants ! */ public static String CONFIG_FILENAME = "sql/query"; public static String SCANNER_THREADS = "scannerThreads"; --- 74,88 ---- import java.sql.SQLException; + /** ! * Description: Provides a very simple interface to the conifguration manager ! * stuff for get sql query strings. This is a useful abstraction so that the ! * queries can get changes on the fly, etc. * * @author bmcdonald * @version 1.0 */ public class SqlQueryManager { ! /** Configuration constants */ public static String CONFIG_FILENAME = "sql/query"; public static String SCANNER_THREADS = "scannerThreads"; *************** *** 50,54 **** * * @param queryName the name of query ! * @param queryName actual query */ public static String getSqlQuery(String queryName) { --- 92,97 ---- * * @param queryName the name of query ! * ! * @return DOCUMENT ME! */ public static String getSqlQuery(String queryName) { *************** *** 57,68 **** /** * Get the prepared statement * * @param queryName the name of the query * @return prepared statement */ ! public static PreparedStatement prepareStatement(Connection connection, String queryName) ! throws com.babeldoc.core.GeneralException, SQLException { String query = getSqlQuery(queryName); if (query == null) { throw new GeneralException(I18n.get("sql.301", queryName)); --- 100,127 ---- /** + * Main - for testing + * + * @param args + */ + public static void main(String[] args) { + SqlQueryManager sqlQueryManager1 = new SqlQueryManager(); + } + + /** * Get the prepared statement * + * @param connection DOCUMENT ME! * @param queryName the name of the query + * * @return prepared statement + * + * @throws com.babeldoc.core.GeneralException DOCUMENT ME! + * @throws SQLException DOCUMENT ME! + * @throws GeneralException DOCUMENT ME! */ ! public static PreparedStatement prepareStatement(Connection connection, ! String queryName) throws com.babeldoc.core.GeneralException, SQLException { String query = getSqlQuery(queryName); + if (query == null) { throw new GeneralException(I18n.get("sql.301", queryName)); *************** *** 70,81 **** return connection.prepareStatement(query); } - } - - /** - * Main - for testing - * @param args - */ - public static void main(String[] args) { - SqlQueryManager sqlQueryManager1 = new SqlQueryManager(); } } --- 129,132 ---- Index: TableKeyHelper.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/util/TableKeyHelper.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TableKeyHelper.java 22 May 2003 03:20:32 -0000 1.4 --- TableKeyHelper.java 27 Jun 2003 02:05:59 -0000 1.5 *************** *** 1,24 **** ! /* ! * $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.util; --- 1,67 ---- ! /* ==================================================================== ! * 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.util; *************** *** 30,37 **** import java.sql.ResultSet; /** ! * Simple class to create new ids using a db table to keep ! * track of the max id for that table. Useful to get unique keys ! * in a db independent way. * * @author Bmcdonald --- 73,80 ---- import java.sql.ResultSet; + /** ! * Simple class to create new ids using a db table to keep track of the max id ! * for that table. Useful to get unique keys in a db independent way. * * @author Bmcdonald *************** *** 39,46 **** */ public class TableKeyHelper { ! ! /** ! * Configuration constants ! */ public static String TABLE_KEY_GET = "tableKeyGet"; public static String TABLE_KEY_UPDATE = "tableKeyUpdate"; --- 82,86 ---- */ public class TableKeyHelper { ! /** Configuration constants */ public static String TABLE_KEY_GET = "tableKeyGet"; public static String TABLE_KEY_UPDATE = "tableKeyUpdate"; *************** *** 55,63 **** /** * Return the new available key for the table. * @param con * @param tableName * @return */ ! public synchronized static Long getNextId(Connection con, String tableName) { //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] Called"); PreparedStatement pstmt = null; --- 95,105 ---- /** * Return the new available key for the table. + * * @param con * @param tableName + * * @return */ ! public static synchronized Long getNextId(Connection con, String tableName) { //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] Called"); PreparedStatement pstmt = null; *************** *** 67,70 **** --- 109,113 ---- String keyUpdate = SqlQueryManager.getSqlQuery(TABLE_KEY_UPDATE); String keyCreate = SqlQueryManager.getSqlQuery(TABLE_KEY_CREATE); + try { //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] Getting next id"); *************** *** 73,78 **** --- 116,123 ---- //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] keyQuery = "+keyQuery); pstmt.setString(1, tableName); + //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] after set"); result = pstmt.executeQuery(); + if (result.next()) { //LogService.getLogger().logDebug("[TableKeyHelper.getNextId] Updating existing row"); *************** *** 82,85 **** --- 127,131 ---- pstmt2.setString(2, tableName); pstmt2.executeUpdate(); + return new Long(seqValue); } else { *************** *** 88,91 **** --- 134,138 ---- pstmt2.setString(1, tableName); pstmt2.executeUpdate(); + return new Long(0); } *************** *** 94,104 **** } finally { try { ! if (result != null) result.close(); ! if (pstmt != null) pstmt.close(); ! if (pstmt2 != null) pstmt2.close(); } catch (Exception e) { LogService.getInstance().logError(I18n.get("sql.403"), e); } } return new Long(-1); } --- 141,160 ---- } finally { try { ! if (result != null) { ! result.close(); ! } ! ! if (pstmt != null) { ! pstmt.close(); ! } ! ! if (pstmt2 != null) { ! pstmt2.close(); ! } } catch (Exception e) { LogService.getInstance().logError(I18n.get("sql.403"), e); } } + return new Long(-1); } Index: VelocitySqlContext.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/util/VelocitySqlContext.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** VelocitySqlContext.java 22 May 2003 03:20:32 -0000 1.3 --- VelocitySqlContext.java 27 Jun 2003 02:05:59 -0000 1.4 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime$ * * ! * 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.util; --- 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.util; *************** *** 29,42 **** import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; /** ! * Velocity context object to be added the variable processor to do all kinds of nifty ! * sql tricks. This will allow velocity scripts to do all these nice tricks too. * * @author bmcdonald * @version 1.0 */ - public class VelocitySqlContext { /** --- 73,88 ---- import java.sql.ResultSet; import java.sql.Statement; + import java.util.ArrayList; + /** ! * Velocity context object to be added the variable processor to do all kinds ! * of nifty sql tricks. This will allow velocity scripts to do all these nice ! * tricks too. * * @author bmcdonald * @version 1.0 */ public class VelocitySqlContext { /** *************** *** 45,54 **** --- 91,104 ---- * @param resourceName the name of the resource * @param table the sql table name to get the next id for + * + * @return DOCUMENT ME! */ public String getNextTableId(String resourceName, String table) { IResource resource = ResourceFactory.getResource(resourceName); Connection connection = null; + try { connection = (Connection) resource.checkOut(); + return TableKeyHelper.getNextId(connection, table).toString(); } catch (Exception e) { *************** *** 60,87 **** } } return null; } /** ! * Execute sql update * ! * @param resourceName the name of the resource ! * @param sql the sql statement to execute */ ! public void executeSqlUpdate(String resourceName, String sql) { IResource resource = ResourceFactory.getResource(resourceName); Connection connection = null; Statement stmt = null; try { connection = (Connection) resource.checkOut(); stmt = connection.createStatement(); ! stmt.executeUpdate(sql); } catch (Exception e) { LogService.getInstance().logError(e); } finally { try { stmt.close(); } catch (Exception e) { } try { resource.checkIn(connection); --- 110,160 ---- } } + return null; } /** ! * Execute a sql select. * ! * @param resourceName resource name ! * @param sql the statement to execute ! * ! * @return arraylist of arraylists */ ! public ArrayList executeSqlSelect(String resourceName, String sql) { ! ArrayList rows = new ArrayList(); IResource resource = ResourceFactory.getResource(resourceName); Connection connection = null; Statement stmt = null; + ResultSet rs = null; + try { connection = (Connection) resource.checkOut(); stmt = connection.createStatement(); ! rs = stmt.executeQuery(sql); ! ! while (rs.next()) { ! int numColumns = rs.getMetaData().getColumnCount(); ! ArrayList colums = new ArrayList(numColumns); ! ! for (int i = 0; i < numColumns; ++i) { ! colums.add(rs.getString(i + 1)); ! } ! ! rows.add(colums); ! } } catch (Exception e) { LogService.getInstance().logError(e); } finally { try { + rs.close(); + } catch (Exception e) { + } + + try { stmt.close(); } catch (Exception e) { } + try { resource.checkIn(connection); *************** *** 89,131 **** } } } /** ! * Execute a sql select. * ! * @param resourceName resource name ! * @param sql the statement to execute ! * @return arraylist of arraylists */ ! public ArrayList executeSqlSelect(String resourceName, String sql) { ! ArrayList rows = new ArrayList(); IResource resource = ResourceFactory.getResource(resourceName); Connection connection = null; Statement stmt = null; ! ResultSet rs = null; try { connection = (Connection) resource.checkOut(); stmt = connection.createStatement(); ! rs = stmt.executeQuery(sql); ! ! while (rs.next()) { ! int numColumns = rs.getMetaData().getColumnCount(); ! ArrayList colums = new ArrayList(numColumns); ! for (int i = 0; i < numColumns; ++i) { ! colums.add(rs.getString(i + 1)); ! } ! rows.add(colums); ! } } catch (Exception e) { LogService.getInstance().logError(e); } finally { try { - rs.close(); - } catch (Exception e) { - } - try { stmt.close(); } catch (Exception e) { } try { resource.checkIn(connection); --- 162,192 ---- } } + + return rows; } /** ! * Execute sql update * ! * @param resourceName the name of the resource ! * @param sql the sql statement to execute */ ! public void executeSqlUpdate(String resourceName, String sql) { IResource resource = ResourceFactory.getResource(resourceName); Connection connection = null; Statement stmt = null; ! try { connection = (Connection) resource.checkOut(); stmt = connection.createStatement(); ! stmt.executeUpdate(sql); } catch (Exception e) { LogService.getInstance().logError(e); } finally { try { stmt.close(); } catch (Exception e) { } + try { resource.checkIn(connection); *************** *** 133,137 **** } } - return rows; } ! } \ No newline at end of file --- 194,197 ---- } } } ! } |