Return-Path: Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 60895 invoked by uid 1152); 27 Feb 2001 16:49:19 -0000 Date: 27 Feb 2001 16:49:19 -0000 Message-ID: <20010227164919.60891.qmail@apache.org> From: bloritsch@apache.org To: xml-cocoon-cvs@apache.org Subject: cvs commit: xml-cocoon/src/org/apache/cocoon/acting DatabaseUpdateAction.java DatabaseDeleteAction.java DatabaseAddAction.java ComposerAction.java AbstractDatabaseAction.java bloritsch 01/02/27 08:49:19 Modified: src/org/apache/cocoon/acting Tag: xml-cocoon2 DatabaseUpdateAction.java DatabaseDeleteAction.java DatabaseAddAction.java ComposerAction.java AbstractDatabaseAction.java Log: Added various NullPointer Fixes. It is still fairly fragile though... Revision Changes Path No revision No revision 1.1.2.7 +11 -7 xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseUpdateAction.java Index: DatabaseUpdateAction.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseUpdateAction.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- DatabaseUpdateAction.java 2001/02/26 22:23:33 1.1.2.6 +++ DatabaseUpdateAction.java 2001/02/27 16:49:12 1.1.2.7 @@ -40,7 +40,7 @@ * only one table at a time to update. * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.6 $ $Date: 2001/02/26 22:23:33 $ + * @version CVS $Revision: 1.1.2.7 $ $Date: 2001/02/27 16:49:12 $ */ public class DatabaseUpdateAction extends AbstractDatabaseAction { private static final Map updateStatements = new HashMap(); @@ -58,7 +58,13 @@ Configuration conf = this.getConfiguration(param.getParameter("form-descriptor", null)); String query = this.getUpdateQuery(conf); datasource = this.getDataSource(conf); + + getLogger().info("The datasource used is: " + datasource); + conn = datasource.getConnection(); + + getLogger().info("The connection used is: " + conn); + HttpRequest request = (HttpRequest) objectModel.get(Constants.REQUEST_OBJECT); PreparedStatement statement = conn.prepareStatement(query); @@ -69,17 +75,13 @@ for (int i = currentIndex; values.hasNext(); i++) { Configuration itemConf = (Configuration) values.next(); - String parameter = itemConf.getAttribute("param"); - Object value = request.get(parameter); - this.setColumn(statement, i, value, itemConf); + this.setColumn(statement, i, request, itemConf); currentIndex = i; } for (int i = currentIndex; keys.hasNext(); i++) { Configuration itemConf = (Configuration) keys.next(); - String parameter = itemConf.getAttribute("param"); - Object value = request.get(parameter); - this.setColumn(statement, i, value, itemConf); + this.setColumn(statement, i, request, itemConf); } statement.execute(); @@ -146,6 +148,8 @@ queryBuffer.append(((Configuration) keys.next()).getAttribute("dbcol")); queryBuffer.append(" = ?"); } + + query = queryBuffer.toString(); } DatabaseUpdateAction.updateStatements.put(conf, query); 1.1.2.4 +4 -4 xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseDeleteAction.java Index: DatabaseDeleteAction.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseDeleteAction.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DatabaseDeleteAction.java 2001/02/26 21:13:39 1.1.2.3 +++ DatabaseDeleteAction.java 2001/02/27 16:49:13 1.1.2.4 @@ -43,7 +43,7 @@ * the keys. * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/02/26 21:13:39 $ + * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/27 16:49:13 $ */ public final class DatabaseDeleteAction extends AbstractDatabaseAction { private static final Map deleteStatements = new HashMap(); @@ -70,9 +70,7 @@ for (int i = 1; keys.hasNext(); i++) { Configuration itemConf = (Configuration) keys.next(); - String parameter = itemConf.getAttribute("param"); - Object value = request.get(parameter); - this.setColumn(statement, i, value, itemConf); + this.setColumn(statement, i, request, itemConf); } statement.execute(); @@ -124,6 +122,8 @@ queryBuffer.append(((Configuration) keys.next()).getAttribute("dbcol")); queryBuffer.append(" = ?"); } + + query = queryBuffer.toString(); } DatabaseDeleteAction.deleteStatements.put(conf, query); 1.1.2.4 +4 -4 xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseAddAction.java Index: DatabaseAddAction.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/DatabaseAddAction.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- DatabaseAddAction.java 2001/02/26 22:22:08 1.1.2.3 +++ DatabaseAddAction.java 2001/02/27 16:49:13 1.1.2.4 @@ -40,7 +40,7 @@ * only one table at a time to update. * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/02/26 22:22:08 $ + * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/27 16:49:13 $ */ public class DatabaseAddAction extends AbstractDatabaseAction { private static final Map addStatements = new HashMap(); @@ -68,9 +68,7 @@ for (int i = currentIndex; values.hasNext(); i++) { Configuration itemConf = (Configuration) values.next(); - String parameter = itemConf.getAttribute("param"); - Object value = request.get(parameter); - this.setColumn(statement, i, value, itemConf); + this.setColumn(statement, i, request, itemConf); currentIndex = i; } @@ -137,6 +135,8 @@ queryBuffer.append("?"); } + + query = queryBuffer.toString(); } DatabaseAddAction.addStatements.put(conf, query); 1.1.2.4 +3 -2 xml-cocoon/src/org/apache/cocoon/acting/Attic/ComposerAction.java Index: ComposerAction.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/ComposerAction.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- ComposerAction.java 2001/02/12 13:30:43 1.1.2.3 +++ ComposerAction.java 2001/02/27 16:49:14 1.1.2.4 @@ -9,6 +9,7 @@ import org.apache.avalon.Composer; import org.apache.avalon.ComponentManager; +import org.apache.avalon.ComponentManagerException; import org.apache.cocoon.Cocoon; /** @@ -16,7 +17,7 @@ * that extends this to access SitemapComponents. * * @author Giacomo Pati - * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/02/12 13:30:43 $ + * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/27 16:49:14 $ */ public abstract class ComposerAction extends AbstractAction implements Composer { @@ -27,7 +28,7 @@ * Set the current ComponentManager instance used by this * Composer. */ - public void compose(ComponentManager manager) { + public void compose(ComponentManager manager) throws ComponentManagerException { this.manager=manager; } } 1.1.2.5 +35 -14 xml-cocoon/src/org/apache/cocoon/acting/Attic/AbstractDatabaseAction.java Index: AbstractDatabaseAction.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/AbstractDatabaseAction.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- AbstractDatabaseAction.java 2001/02/26 22:53:39 1.1.2.4 +++ AbstractDatabaseAction.java 2001/02/27 16:49:15 1.1.2.5 @@ -32,6 +32,7 @@ import org.xml.sax.InputSource; import org.apache.avalon.Component; +import org.apache.avalon.ComponentManager; import org.apache.avalon.ComponentSelector; import org.apache.avalon.ComponentManagerException; import org.apache.avalon.Configurable; @@ -44,6 +45,7 @@ import org.apache.cocoon.Roles; import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.environment.http.HttpRequest; import org.apache.cocoon.generation.ImageDirectoryGenerator; import org.apache.cocoon.components.url.URLFactory; import org.apache.cocoon.components.parser.Parser; @@ -139,7 +141,7 @@ * * * @author Berin Loritsch - * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/26 22:53:39 $ + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/02/27 16:49:15 $ */ public abstract class AbstractDatabaseAction extends ComposerAction implements Configurable { private static Map configurations = new HashMap(); @@ -168,6 +170,15 @@ } /** + * Compose the Actions so that we can select our databases. + */ + public void compose(ComponentManager manager) throws ComponentManagerException { + this.dbselector = (ComponentSelector) manager.lookup(Roles.DB_CONNECTION); + + super.compose(manager); + } + + /** * Set up the Database environment so that the configuration for the * Form is handled properly. Please note that multiple Actions can * share the same configurations. By using this approach, we can @@ -238,16 +249,26 @@ /** * Set the Statement column so that the results are mapped correctly. */ - protected final void setColumn(PreparedStatement statement, int position, Object value, Configuration entry) throws Exception { + protected final void setColumn(PreparedStatement statement, int position, HttpRequest request, Configuration entry) throws Exception { Integer typeObject = (Integer) AbstractDatabaseAction.typeConstants.get(entry.getAttribute("type")); if (typeObject == null) { throw new SQLException("Can't set column because the type is invalid"); } + String attribute = entry.getAttribute("param", ""); + String value = request.getParameter(attribute); + + getLogger().info("Setting parameter '" + attribute + "' to: " + value); + + if (value == null) { + statement.setNull(position, typeObject.intValue()); + return; + } + switch (typeObject.intValue()) { case Types.CLOB: - File asciiFile = (File) value; + File asciiFile = (File) request.get(attribute); FileInputStream asciiStream = new FileInputStream(asciiFile); statement.setAsciiStream(position, asciiStream, (int) asciiFile.length()); break; @@ -255,39 +276,39 @@ statement.setBigDecimal(position, new BigDecimal((String) value)); break; case Types.BLOB: - File binaryFile = (File) value; + File binaryFile = (File) request.get(attribute); FileInputStream binaryStream = new FileInputStream(binaryFile); statement.setBinaryStream(position, binaryStream, (int) binaryFile.length()); break; case Types.TINYINT: - statement.setByte(position, (new Byte((String) value)).byteValue()); + statement.setByte(position, (new Byte(value)).byteValue()); break; case Types.VARCHAR: - statement.setString(position, (String) value); + statement.setString(position, value); break; case Types.DATE: - statement.setDate(position, new Date(this.dateValue((String) value, entry.getAttribute("format", "M/d/yyyy")))); + statement.setDate(position, new Date(this.dateValue(value, entry.getAttribute("format", "M/d/yyyy")))); break; case Types.DOUBLE: - statement.setDouble(position, (new Double((String) value)).doubleValue()); + statement.setDouble(position, (new Double(value)).doubleValue()); break; case Types.FLOAT: - statement.setFloat(position, (new Float((String) value)).floatValue()); + statement.setFloat(position, (new Float(value)).floatValue()); break; case Types.INTEGER: - statement.setInt(position, (new Integer((String) value)).intValue()); + statement.setInt(position, (new Integer(value)).intValue()); break; case Types.NUMERIC: - statement.setLong(position, (new Long((String) value)).longValue()); + statement.setLong(position, (new Long(value)).longValue()); break; case Types.SMALLINT: - statement.setShort(position, (new Short((String) value)).shortValue()); + statement.setShort(position, (new Short(value)).shortValue()); break; case Types.TIME: - statement.setTime(position, new Time(this.dateValue((String) value, entry.getAttribute("format", "h:m:s a")))); + statement.setTime(position, new Time(this.dateValue(value, entry.getAttribute("format", "h:m:s a")))); break; case Types.TIMESTAMP: - statement.setTimestamp(position, new Timestamp(this.dateValue((String) value, entry.getAttribute("format", "M/d/yyyy h:m:s a")))); + statement.setTimestamp(position, new Timestamp(this.dateValue(value, entry.getAttribute("format", "M/d/yyyy h:m:s a")))); break; case Types.OTHER: statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));