|
From: <tr...@us...> - 2003-07-15 22:46:59
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage In directory sc8-pr-cvs1:/tmp/cvs-serv24833/sql/src/com/babeldoc/sql/pipeline/stage Modified Files: SqlQueryPipelineStage.java Log Message: added the header and some small reformattings. Index: SqlQueryPipelineStage.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlQueryPipelineStage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SqlQueryPipelineStage.java 14 Jul 2003 22:43:30 -0000 1.1 --- SqlQueryPipelineStage.java 15 Jul 2003 22:46:56 -0000 1.2 *************** *** 1,2 **** --- 1,68 ---- + /* ==================================================================== + * 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.pipeline.stage; *************** *** 7,15 **** import com.babeldoc.core.option.ConfigOption; import com.babeldoc.core.option.IConfigOptionType; ! import com.babeldoc.core.pipeline.PipelineException; ! import com.babeldoc.core.pipeline.PipelineStage; ! import com.babeldoc.core.pipeline.PipelineStageInfo; ! import com.babeldoc.core.pipeline.PipelineStageResult; ! import com.babeldoc.core.pipeline.PipelineDocument; import com.babeldoc.core.resource.IResource; import com.babeldoc.core.resource.ResourceException; --- 73,77 ---- import com.babeldoc.core.option.ConfigOption; import com.babeldoc.core.option.IConfigOptionType; ! import com.babeldoc.core.pipeline.*; import com.babeldoc.core.resource.IResource; import com.babeldoc.core.resource.ResourceException; *************** *** 19,24 **** import java.util.ArrayList; import java.util.Collection; - import java.util.HashMap; - import java.util.Iterator; /** --- 81,84 ---- *************** *** 32,36 **** public final static String SQL = "sql"; public final static String RESOURCE_NAME = "resourceName"; ! //Connection pool private IResource resource = null; --- 92,96 ---- public final static String SQL = "sql"; public final static String RESOURCE_NAME = "resourceName"; ! //Connection pool private IResource resource = null; *************** *** 54,58 **** null, true, I18n.get("sql.901"))); ! IConfigOptionType queries = new ComplexConfigOptionType( new ConfigOption[] { new ConfigOption(SQL, IConfigOptionType.MULTI, null, false, I18n.get("sql.902")) }); --- 114,118 ---- null, true, I18n.get("sql.901"))); ! IConfigOptionType queries = new ComplexConfigOptionType(new ConfigOption[]{ new ConfigOption(SQL, IConfigOptionType.MULTI, null, false, I18n.get("sql.902")) }); *************** *** 74,88 **** // Check that the resource is set ! if (! hasOption(RESOURCE_NAME)) ! { throw new PipelineException(I18n.get("sql.201")); } NameValuePair[] queries = this.getOptionList(new String[]{SQL}); ! StringBuffer xml = new StringBuffer(); xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); xml.append("<queryresults>\n"); ! Connection conn = null; Statement stmt = null; --- 134,147 ---- // Check that the resource is set ! if (!hasOption(RESOURCE_NAME)) { throw new PipelineException(I18n.get("sql.201")); } NameValuePair[] queries = this.getOptionList(new String[]{SQL}); ! StringBuffer xml = new StringBuffer(); xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); xml.append("<queryresults>\n"); ! Connection conn = null; Statement stmt = null; *************** *** 90,121 **** String sql = null; try { ! conn = getConnection(); ! ! // Iterate through sqls ! if ((queries != null) && (queries.length > 0)) { ! for (int i = 0; i < queries.length; ++i) { ! String queryName = queries[i].getName(); ! xml.append("<" + queryName + ">\n"); ! sql = queries[i].getValue(); ! stmt = conn.createStatement(); ! LogService.getInstance().logDebug("Executing " + sql); ! rs = stmt.executeQuery(sql); ! ResultSetMetaData metaData = rs.getMetaData(); ! while (rs.next()) { ! xml.append("<row>\n"); ! for (int j = 1, count = metaData.getColumnCount(); j <= count; j++) { ! String name = metaData.getColumnLabel(j).toLowerCase(); ! Object value = rs.getObject(j); ! xml.append("<" + name + ">"); ! xml.append(value); ! xml.append("</" + name + ">\n"); ! } ! xml.append("</row>\n"); ! } ! xml.append("</" + queryName + ">\n"); ! } ! } ! } ! catch (ResourceException e) { throw new PipelineException(I18n.get("sql.103"), e); } catch (SQLException e) { --- 149,179 ---- String sql = null; try { ! conn = getConnection(); ! ! // Iterate through sqls ! if ((queries != null) && (queries.length > 0)) { ! for (int i = 0; i < queries.length; ++i) { ! String queryName = queries[i].getName(); ! xml.append("<" + queryName + ">\n"); ! sql = queries[i].getValue(); ! stmt = conn.createStatement(); ! LogService.getInstance().logDebug("Executing " + sql); ! rs = stmt.executeQuery(sql); ! ResultSetMetaData metaData = rs.getMetaData(); ! while (rs.next()) { ! xml.append("<row>\n"); ! for (int j = 1, count = metaData.getColumnCount(); j <= count; j++) { ! String name = metaData.getColumnLabel(j).toLowerCase(); ! Object value = rs.getObject(j); ! xml.append("<" + name + ">"); ! xml.append(value); ! xml.append("</" + name + ">\n"); ! } ! xml.append("</row>\n"); ! } ! xml.append("</" + queryName + ">\n"); ! } ! } ! } catch (ResourceException e) { throw new PipelineException(I18n.get("sql.103"), e); } catch (SQLException e) { *************** *** 143,170 **** } } ! xml.append("</queryresults>\n"); ! PipelineDocument newDoc = new PipelineDocument(this.getDocument(), xml.toString().getBytes()); newDoc.setMimeType("text/xml"); ! return super.processHelper(newDoc); } ! /** * Get the named resource name from the resource factory * * @return - * @throws PipelineException * @throws ResourceException */ private Connection getConnection() ! throws PipelineException, ResourceException { if (resource == null) { resource = ResourceFactory.getResource(this.getOptions(RESOURCE_NAME)); } ! if (resource == null) ! { throw new ResourceException(I18n.get("sql.103")); } --- 201,226 ---- } } ! xml.append("</queryresults>\n"); ! PipelineDocument newDoc = new PipelineDocument(this.getDocument(), xml.toString().getBytes()); newDoc.setMimeType("text/xml"); ! return super.processHelper(newDoc); } ! /** * Get the named resource name from the resource factory * * @return * @throws ResourceException */ private Connection getConnection() ! throws ResourceException { if (resource == null) { resource = ResourceFactory.getResource(this.getOptions(RESOURCE_NAME)); } ! if (resource == null) { throw new ResourceException(I18n.get("sql.103")); } |