|
From: <tr...@us...> - 2003-06-27 02:06:02
|
Update of /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage In directory sc8-pr-cvs1:/tmp/cvs-serv31771/src/com/babeldoc/sql/pipeline/stage Modified Files: SqlEnrichPipelineStage.java SqlWriterPipelineStage.java Log Message: Reformatted and updated license header Index: SqlEnrichPipelineStage.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlEnrichPipelineStage.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** SqlEnrichPipelineStage.java 8 Jun 2003 18:23:47 -0000 1.11 --- SqlEnrichPipelineStage.java 27 Jun 2003 02:05:59 -0000 1.12 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/24 18:15:55 $ * * ! * 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.pipeline.stage; --- 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.pipeline.stage; *************** *** 37,40 **** --- 81,85 ---- import java.sql.*; + import java.util.ArrayList; import java.util.Collection; *************** *** 44,68 **** /** ! * Pipeline stage to enrich a document using sql statements. This pipeline stage ! * provides two methods for getting sql results into document attributes. ! * ! * 1. The attribute names and values are derived from the results of sql statements ! * in that the name of the attribute is the name of a column or label and the value is ! * value of that column or label. ! * 2. Each attribute is associated with a sql statement and its value is the first column and * first row of the resultset. * ! * @author Dejan Krsmanovic <a href="mailto:dej...@ya...">dej...@ya...</a> * @version 1.0 */ public class SqlEnrichPipelineStage extends PipelineStage { ! /** ! * constants ! */ ! public final static String ATTRIBUTE_SQL = "attributeSql"; ! public final static String SQL_SCRIPT = "sqlScript"; ! public final static String RESOURCE_NAME = "resourceName"; ! public final static String DEFAULT_VALUE = "defaultValue"; //Connection pool --- 89,110 ---- /** ! * Pipeline stage to enrich a document using sql statements. This pipeline ! * stage provides two methods for getting sql results into document ! * attributes. 1. The attribute names and values are derived from the results ! * of sql statements in that the name of the attribute is the name of a column ! * or label and the value is value of that column or label. 2. Each attribute ! * is associated with a sql statement and its value is the first column and * first row of the resultset. * ! * @author Dejan Krsmanovic * @version 1.0 */ public class SqlEnrichPipelineStage extends PipelineStage { ! /** constants */ ! public static final String ATTRIBUTE_SQL = "attributeSql"; ! public static final String SQL_SCRIPT = "sqlScript"; ! public static final String RESOURCE_NAME = "resourceName"; ! public static final String DEFAULT_VALUE = "defaultValue"; //Connection pool *************** *** 74,106 **** public SqlEnrichPipelineStage() { super(new PipelineStageInfo() { ! public String getName() { ! return "SqlEnrich"; ! } ! public String getDescription() { ! return I18n.get("sql.100"); ! } ! public Collection getTypeSpecificOptions() { ! ArrayList options = new ArrayList(); ! options.add(new ConfigOption(RESOURCE_NAME, IConfigOptionType.STRING, ! null, true, I18n.get("sql.101"))); ! IConfigOptionType attrs = new ComplexConfigOptionType( new ConfigOption[] { ! new ConfigOption(ATTRIBUTE_SQL, IConfigOptionType.STRING, null, false, I18n.get("sql.102")) ! }); ! IConfigOptionType scripts = new ComplexConfigOptionType( new ConfigOption[] { ! new ConfigOption(SQL_SCRIPT, IConfigOptionType.MULTI, null, false, I18n.get("sql.106")) ! }); ! options.add(new ConfigOption(ATTRIBUTE_SQL, attrs, ! null, false, I18n.get("sql.102"))); ! options.add(new ConfigOption(SQL_SCRIPT, scripts, ! null, false, I18n.get("sql.106"))); ! return options; } ! }); } --- 116,213 ---- public SqlEnrichPipelineStage() { super(new PipelineStageInfo() { ! public String getName() { ! return "SqlEnrich"; ! } ! public String getDescription() { ! return I18n.get("sql.100"); ! } ! public Collection getTypeSpecificOptions() { ! ArrayList options = new ArrayList(); ! options.add(new ConfigOption(RESOURCE_NAME, IConfigOptionType.STRING, ! null, true, I18n.get("sql.101"))); ! IConfigOptionType attrs = new ComplexConfigOptionType(new ConfigOption[] { new ConfigOption( ! ATTRIBUTE_SQL, IConfigOptionType.STRING, null, false, ! I18n.get("sql.102")) }); ! IConfigOptionType scripts = new ComplexConfigOptionType(new ConfigOption[] { new ConfigOption( ! SQL_SCRIPT, IConfigOptionType.MULTI, null, false, ! I18n.get("sql.106")) }); ! options.add(new ConfigOption(ATTRIBUTE_SQL, attrs, null, false, ! I18n.get("sql.102"))); ! options.add(new ConfigOption(SQL_SCRIPT, scripts, null, false, ! I18n.get("sql.106"))); ! return options; ! } ! }); ! } ! ! /** ! * execute the sql statement and convert to a hashmap of name/value pairs. ! * Each name is the column/label of the result and the value is the value ! * for its corresponding column/label. ! * ! * @param sqlStatement ! * ! * @return hashmap of name/value pairs ! * ! * @throws PipelineException ! */ ! public HashMap getValuesFromSql(String sqlStatement) ! throws PipelineException { ! Connection conn = null; ! Statement stmt = null; ! ResultSet rs = null; ! HashMap values = new HashMap(); ! ! try { ! conn = getConnection(); ! stmt = conn.createStatement(); ! LogService.getInstance().logDebug("Executing statement: " + sqlStatement); ! rs = stmt.executeQuery(sqlStatement); ! ! //Assume that statement returned only one record with one column ! //Others will be ignored ! if (rs.next()) { ! ResultSetMetaData metaData = rs.getMetaData(); ! ! for (int i = 1, count = metaData.getColumnCount(); i <= count; i++) { ! String name = metaData.getColumnLabel(i); ! Object value = rs.getObject(i); ! values.put(name, value); ! } } ! } catch (ResourceException e) { ! throw new PipelineException(I18n.get("sql.103"), e); ! } catch (SQLException e) { ! throw new PipelineException(I18n.get("sql.104", sqlStatement), e); ! } finally { ! try { ! if (rs != null) { ! rs.close(); ! } ! } catch (Exception ignoreThis) { ! } ! ! try { ! if (stmt != null) { ! stmt.close(); ! } ! } catch (Exception ignoreThis) { ! } ! ! try { ! if (conn != null) { ! resource.checkIn(conn); ! } ! } catch (Exception ignoreThis) { ! } ! } ! ! return values; } *************** *** 109,118 **** * * @return set of results from the processing */ public PipelineStageResult[] process() throws PipelineException { - // Check that the resource is set ! if (! hasOption(RESOURCE_NAME)) ! { throw new PipelineException(I18n.get("sql.201")); } --- 216,225 ---- * * @return set of results from the processing + * + * @throws PipelineException DOCUMENT ME! */ public PipelineStageResult[] process() throws PipelineException { // Check that the resource is set ! if (!hasOption(RESOURCE_NAME)) { throw new PipelineException(I18n.get("sql.201")); } *************** *** 120,124 **** //First process scripts //Get all sql scripts ! NameValuePair[] sqlScripts = this.getOptionList(new String[]{SQL_SCRIPT}); String defaultValue = this.getOptions(DEFAULT_VALUE); --- 227,231 ---- //First process scripts //Get all sql scripts ! NameValuePair[] sqlScripts = this.getOptionList(new String[] { SQL_SCRIPT }); String defaultValue = this.getOptions(DEFAULT_VALUE); *************** *** 146,150 **** getDocument().put(name, value); ! LogService.getInstance().logDebug("Adding new attribute: "+name+"=" + value); } } --- 253,258 ---- getDocument().put(name, value); ! LogService.getInstance().logDebug("Adding new attribute: " + name + ! "=" + value); } } *************** *** 153,159 **** //Now process attribute scripts ! NameValuePair[] attributes = this.getOptionList(new String[]{ATTRIBUTE_SQL}); ! if (sqlScripts == null && attributes == null) ! { throw new PipelineException(I18n.get("sql.202")); } --- 261,267 ---- //Now process attribute scripts ! NameValuePair[] attributes = this.getOptionList(new String[] { ATTRIBUTE_SQL }); ! ! if ((sqlScripts == null) && (attributes == null)) { throw new PipelineException(I18n.get("sql.202")); } *************** *** 171,175 **** getDocument().put(varname, value); ! LogService.getInstance().logDebug("Adding new attribute: "+varname+"="+value); } } --- 279,284 ---- getDocument().put(varname, value); ! LogService.getInstance().logDebug("Adding new attribute: " + varname + ! "=" + value); } } *************** *** 179,186 **** --- 288,318 ---- /** + * Get the named resource name from the resource factory + * + * @return + * + * @throws PipelineException + * @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")); + } + + return ((Connection) resource.checkOut()); + } + + /** * Execute the sql statement and return the results. * * @param sqlStatement + * * @return + * * @throws PipelineException */ *************** *** 232,318 **** return result; } - } - - /** - * 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")); - } - - return ((Connection) resource.checkOut()); - } - - /** - * execute the sql statement and convert to a hashmap of name/value pairs. - * Each name is the column/label of the result and the value is the value for - * its corresponding column/label. - * - * @param sqlStatement - * @return hashmap of name/value pairs - * @throws PipelineException - */ - public HashMap getValuesFromSql(String sqlStatement) - throws PipelineException { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - HashMap values = new HashMap(); - - try { - conn = getConnection(); - stmt = conn.createStatement(); - LogService.getInstance().logDebug("Executing statement: " + sqlStatement); - rs = stmt.executeQuery(sqlStatement); - - //Assume that statement returned only one record with one column - //Others will be ignored - if (rs.next()) { - ResultSetMetaData metaData = rs.getMetaData(); - - for (int i = 1, count = metaData.getColumnCount(); i <= count; i++) { - String name = metaData.getColumnLabel(i); - Object value = rs.getObject(i); - values.put(name, value); - } - } - } catch (ResourceException e) { - throw new PipelineException(I18n.get("sql.103"), e); - } catch (SQLException e) { - throw new PipelineException(I18n.get("sql.104", sqlStatement), e); - } finally { - try { - if (rs != null) { - rs.close(); - } - } catch (Exception ignoreThis) { - } - - try { - if (stmt != null) { - stmt.close(); - } - } catch (Exception ignoreThis) { - } - - try { - if (conn != null) { - resource.checkIn(conn); - } - } catch (Exception ignoreThis) { - } - } - - return values; } } --- 364,367 ---- Index: SqlWriterPipelineStage.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/sql/src/com/babeldoc/sql/pipeline/stage/SqlWriterPipelineStage.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** SqlWriterPipelineStage.java 8 Jun 2003 18:23:47 -0000 1.12 --- SqlWriterPipelineStage.java 27 Jun 2003 02:05:59 -0000 1.13 *************** *** 1,22 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/24 18:15:55 $ * * ! * 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.pipeline.stage; --- 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.pipeline.stage; *************** *** 35,41 **** --- 79,87 ---- import java.io.BufferedReader; import java.io.StringReader; + import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; + import java.util.ArrayList; import java.util.Collection; *************** *** 43,75 **** /** - * @author bruce - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ - /** * Pipeline stage for executing sql statements * ! * @author Dejan Krsmanovic <a href="mailto:dej...@ya...">dej...@ya...</a> * @version 1.0 */ ! public class SqlWriterPipelineStage ! extends PipelineStage { ! /** ! * Constants ! */ ! public final static String RESOURCE_NAME = "resourceName"; ! public final static String USE_BATCH = "useBatch"; ! public final static String BATCH_SIZE = "batchSize"; ! public final static String SQL = "sql"; //This is used for specifying message that should be retuned. It should be //placed inside comments ! public final static String MESSAGE_TAG = "messageTag"; ! public final static String FAIL_ON_FIRST = "failOnFirst"; private IResource resource = null; private boolean batchSupported = false; private int batchSize = 20; - private String messageTag = "message:"; /** --- 89,112 ---- /** * Pipeline stage for executing sql statements * ! * @author Dejan Krsmanovic * @version 1.0 */ ! public class SqlWriterPipelineStage extends PipelineStage { ! /** Constants */ ! public static final String RESOURCE_NAME = "resourceName"; ! public static final String USE_BATCH = "useBatch"; ! public static final String BATCH_SIZE = "batchSize"; ! public static final String SQL = "sql"; //This is used for specifying message that should be retuned. It should be //placed inside comments ! public static final String MESSAGE_TAG = "messageTag"; ! public static final String FAIL_ON_FIRST = "failOnFirst"; private IResource resource = null; + private String messageTag = "message:"; private boolean batchSupported = false; private int batchSize = 20; /** *************** *** 78,119 **** public SqlWriterPipelineStage() { super(new com.babeldoc.core.pipeline.PipelineStageInfo() { ! public String getName() { ! return "SqlWriter"; } ! public String getDescription() { ! return I18n.get("sql.190"); } ! public Collection getTypeSpecificOptions() { ! ArrayList options = new ArrayList(); ! options.add(new ConfigOption ! (RESOURCE_NAME, ! IConfigOptionType.STRING, ! null, true, I18n.get("sql.101"))); ! options.add(new ConfigOption ! (USE_BATCH, ! IConfigOptionType.BOOLEAN, ! "false", false, I18n.get("sql.191"))); ! options.add(new ConfigOption ! (BATCH_SIZE, ! IConfigOptionType.INTEGER, ! "20", false, I18n.get("sql.192"))); ! options.add(new ConfigOption ! (SQL, ! IConfigOptionType.STRING, ! null, true, I18n.get("sql.193"))); ! options.add(new ConfigOption ! (FAIL_ON_FIRST, ! IConfigOptionType.BOOLEAN, ! "false", false, I18n.get("sql.194"))); ! options.add(new ConfigOption ! (MESSAGE_TAG, ! IConfigOptionType.STRING, ! null, true, I18n.get("sql.195"))); ! return options; } ! }); } --- 115,188 ---- public SqlWriterPipelineStage() { super(new com.babeldoc.core.pipeline.PipelineStageInfo() { ! public String getName() { ! return "SqlWriter"; ! } ! ! public String getDescription() { ! return I18n.get("sql.190"); ! } ! ! public Collection getTypeSpecificOptions() { ! ArrayList options = new ArrayList(); ! ! options.add(new ConfigOption(RESOURCE_NAME, IConfigOptionType.STRING, ! null, true, I18n.get("sql.101"))); ! options.add(new ConfigOption(USE_BATCH, IConfigOptionType.BOOLEAN, ! "false", false, I18n.get("sql.191"))); ! options.add(new ConfigOption(BATCH_SIZE, IConfigOptionType.INTEGER, ! "20", false, I18n.get("sql.192"))); ! options.add(new ConfigOption(SQL, IConfigOptionType.STRING, null, ! true, I18n.get("sql.193"))); ! options.add(new ConfigOption(FAIL_ON_FIRST, ! IConfigOptionType.BOOLEAN, "false", false, I18n.get("sql.194"))); ! options.add(new ConfigOption(MESSAGE_TAG, IConfigOptionType.STRING, ! null, true, I18n.get("sql.195"))); ! ! return options; ! } ! }); ! } ! ! /** ! * Process the pipeline document ! * ! * @return ! * ! * @throws PipelineException ! */ ! public PipelineStageResult[] process() throws PipelineException { ! try { ! batchSupported = "true".equalsIgnoreCase(getOptions(USE_BATCH)); ! ! if (this.hasOption(MESSAGE_TAG)) { ! messageTag = getOptions(MESSAGE_TAG); } ! String batchSizeOpt = getOptions(BATCH_SIZE); ! boolean failOnFirst = "true".equalsIgnoreCase(getOptions(FAIL_ON_FIRST)); ! ! if ((batchSizeOpt != null) && !batchSizeOpt.equals("")) { ! try { ! batchSize = Integer.parseInt(batchSizeOpt); ! } catch (NumberFormatException nfe) { ! } } ! if (!hasOption(RESOURCE_NAME)) { ! throw new PipelineException(I18n.get("sql.201")); ! } ! String sqlScript = this.getOptions(SQL); ! ! if ((sqlScript == null) || sqlScript.equals("")) { ! throw new PipelineException(I18n.get("sql.200")); } ! ! executeSqlScript(sqlScript, failOnFirst); ! ! return super.processHelper(); ! } catch (Exception e) { ! throw new PipelineException(I18n.get("sql.104"), e); ! } } *************** *** 122,125 **** --- 191,195 ---- * * @return a new database connection + * * @throws ResourceException */ *************** *** 127,133 **** if (resource == null) { resource = ResourceFactory.getResource(getOptions(RESOURCE_NAME)); ! if (resource == null) ! { ! throw new ResourceException(I18n.get("sql.103")); } } --- 197,203 ---- if (resource == null) { resource = ResourceFactory.getResource(getOptions(RESOURCE_NAME)); ! ! if (resource == null) { ! throw new ResourceException(I18n.get("sql.103")); } } *************** *** 138,141 **** --- 208,219 ---- /** * Execute the sql script + * + * @param sqlScript DOCUMENT ME! + * @param failOnFirst DOCUMENT ME! + * + * @return DOCUMENT ME! + * + * @throws Exception DOCUMENT ME! + * @throws PipelineException DOCUMENT ME! */ private boolean executeSqlScript(String sqlScript, boolean failOnFirst) *************** *** 157,161 **** String currentComment = ""; - //String command = br.readLine(); int currentBatchSize = 0; --- 235,238 ---- *************** *** 167,175 **** String command = br.readLine(); LogService.getInstance().logDebug("Current line= " + command); if (command == null) { ! if (batchSupported && currentBatchSize > 0) { stmt.executeBatch(); LogService.getInstance().logDebug("Executed " + currentBatchSize + ! " statements in batch"); } --- 244,253 ---- String command = br.readLine(); LogService.getInstance().logDebug("Current line= " + command); + if (command == null) { ! if (batchSupported && (currentBatchSize > 0)) { stmt.executeBatch(); LogService.getInstance().logDebug("Executed " + currentBatchSize + ! " statements in batch"); } *************** *** 188,192 **** //Only single line comments are supported if ((command.startsWith("--") || command.startsWith("/*")) && ! (command.length() > 2)) { currentComment = command.substring(2); --- 266,270 ---- //Only single line comments are supported if ((command.startsWith("--") || command.startsWith("/*")) && ! (command.length() > 2)) { currentComment = command.substring(2); *************** *** 195,201 **** currentComment.length() - 3); } //this is not executable statement. Get next one! continue; - } --- 273,279 ---- currentComment.length() - 3); } + //this is not executable statement. Get next one! continue; } *************** *** 207,211 **** stmt.addBatch(command); LogService.getInstance().logDebug("Command " + command + ! " added to batch list"); currentBatchSize++; --- 285,289 ---- stmt.addBatch(command); LogService.getInstance().logDebug("Command " + command + ! " added to batch list"); currentBatchSize++; *************** *** 213,221 **** stmt.executeBatch(); LogService.getInstance().logDebug("Executed " + ! currentBatchSize + " statements in batch"); } } else { LogService.getInstance().logDebug("Executing statement: " + ! command); stmt.execute(command); } --- 291,299 ---- stmt.executeBatch(); LogService.getInstance().logDebug("Executed " + ! currentBatchSize + " statements in batch"); } } else { LogService.getInstance().logDebug("Executing statement: " + ! command); stmt.execute(command); } *************** *** 223,231 **** commandCount = 0; } - } catch (SQLException ex) { //if current comment starts with message tag then it should be displayed //instead of actual error message String currentMessage; if (currentComment.startsWith(messageTag)) { //remove message tag --- 301,309 ---- commandCount = 0; } } catch (SQLException ex) { //if current comment starts with message tag then it should be displayed //instead of actual error message String currentMessage; + if (currentComment.startsWith(messageTag)) { //remove message tag *************** *** 234,242 **** --- 312,323 ---- currentMessage = ex.getMessage(); } + LogService.getInstance().logWarn(I18n.get("sql.196", currentMessage)); + if (failOnFirst) { //if fail on first command then immediately rollback and throw //exception. Otherwise, execute all script and then rollback conn.rollback(); + // getLog().debug("Rollback!"); throw new PipelineException(currentMessage); *************** *** 254,257 **** --- 335,339 ---- } else { conn.rollback(); + // getLog().debug("rollback... throwing exception"); throw new PipelineException(errorMessage); *************** *** 274,314 **** } catch (Exception ex) { } - } - } - - /** - * Process the pipeline document - * - * @return - * @throws PipelineException - */ - public PipelineStageResult[] process() throws PipelineException { - try { - batchSupported = "true".equalsIgnoreCase(getOptions(USE_BATCH)); - if (this.hasOption(MESSAGE_TAG)) { - messageTag = getOptions(MESSAGE_TAG); - } - String batchSizeOpt = getOptions(BATCH_SIZE); - boolean failOnFirst = "true".equalsIgnoreCase(getOptions(FAIL_ON_FIRST)); - - if ((batchSizeOpt != null) && !batchSizeOpt.equals("")) { - try { - batchSize = Integer.parseInt(batchSizeOpt); - } catch (NumberFormatException nfe) { - } - } - if (! hasOption(RESOURCE_NAME)) - { - throw new PipelineException(I18n.get("sql.201")); - } - String sqlScript = this.getOptions(SQL); - if (sqlScript == null || sqlScript.equals("")) { - throw new PipelineException(I18n.get("sql.200")); - } - executeSqlScript(sqlScript, failOnFirst); - - return super.processHelper(); - } catch (Exception e) { - throw new PipelineException(I18n.get("sql.104"), e); } } --- 356,359 ---- |