cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: xml-cocoon/webapp/docs/samples/forms employee.xsp
Date Wed, 10 Jan 2001 17:31:59 GMT
bloritsch    01/01/10 09:31:59

  Modified:    src/org/apache/cocoon/acting Tag: xml-cocoon2
                        AddEmployeeAction.java
               webapp   Tag: xml-cocoon2 cocoon.xconf
               webapp/docs/samples/forms Tag: xml-cocoon2 employee.xsp
  Log:
  Cleaned up examples and implemented some real logic to the Action
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +70 -2     xml-cocoon/src/org/apache/cocoon/acting/Attic/AddEmployeeAction.java
  
  Index: AddEmployeeAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/AddEmployeeAction.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- AddEmployeeAction.java	2000/12/30 23:01:01	1.1.2.2
  +++ AddEmployeeAction.java	2001/01/10 17:31:56	1.1.2.3
  @@ -7,6 +7,10 @@
    *****************************************************************************/
   package org.apache.cocoon.acting;
   
  +import java.sql.Connection;
  +import java.sql.PreparedStatement;
  +import java.sql.ResultSet;
  +import java.sql.SQLException;
   import java.util.Map;
   
   import javax.servlet.http.HttpServletRequest;
  @@ -14,10 +18,15 @@
   import javax.servlet.ServletContext;
   
   import org.apache.avalon.Component;
  +import org.apache.avalon.ComponentSelector;
  +import org.apache.avalon.ComponentManagerException;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.ConfigurationException;
   import org.apache.avalon.Parameters;
   
  +import org.apache.cocoon.Roles;
  +import org.apache.cocoon.components.datasource.DataSourceComponent;
  +
   import org.xml.sax.SAXException;
   import org.xml.sax.EntityResolver;
   
  @@ -25,14 +34,22 @@
   /**
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/12/30 23:01:01 $
  + * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/01/10 17:31:56 $
    */
   public class AddEmployeeAction extends ComposerAction {
   
  +    DataSourceComponent datasource = null;
  +
       /**
        * Get the <code>Configuration</code> object for this <code>Component</code>
        */
       public void configure( Configuration configuration) throws ConfigurationException {
  +        try {
  +            ComponentSelector selector = (ComponentSelector) this.manager.lookup(Roles.DB_CONNECTION);
  +            this.datasource = (DataSourceComponent) selector.select(configuration.getChild("use-connection").getValue());
  +        } catch (ComponentManagerException cme) {
  +            throw new ConfigurationException("Could not get the DataSource Object", cme);
  +        }
       }
   
       /**
  @@ -41,7 +58,58 @@
        */
       public Map act (EntityResolver resolver, Map objectModel, String src, Parameters par)
throws Exception {
           HttpServletRequest req = (HttpServletRequest) objectModel.get(Constants.REQUEST_OBJECT);
  -        req.setAttribute("message", "You have added the employee " + req.getParameter("name"));
  +        String name = req.getParameter("name");
  +        String department = req.getParameter("department");
  +
  +        if (addEmployee(name, department) == true) {
  +            req.setAttribute("message", "You have added the employee " + name);
  +        } else {
  +            req.setAttribute("message", "You did not add the employee " + name);
  +        }
           return null;
  +    }
  +
  +    private boolean addEmployee(String name, String department) {
  +        Connection conn = null;
  +        PreparedStatement ps = null;
  +        ResultSet rs = null;
  +        boolean returnValue = false;
  +
  +        try {
  +            conn = datasource.getConnection();
  +            conn.setAutoCommit(false);
  +            rs = conn.createStatement().executeQuery("SELECT Max(id) AS maxid FROM employee_table;");
  +            int maxid = -1;
  +
  +            if (rs.next() == true) {
  +                maxid = rs.getInt("maxid");
  +
  +                ps = conn.prepareStatement("INSERT INTO employee_table (id, name, department_id)
VALUES (?, ?, ?)");
  +                ps.setInt(1, maxid);
  +                ps.setString(2, name);
  +                ps.setString(3, department);
  +
  +                returnValue = ps.execute();
  +            }
  +        } catch (SQLException se) {
  +            // returnValue = false;
  +        } finally {
  +            try {
  +                if (returnValue = false) {
  +                    conn.rollback();
  +                } else {
  +                    conn.commit();
  +                }
  +
  +                ps.close();
  +                rs.close();
  +                rs.getStatement().close();
  +                conn.close();
  +            } catch (Exception e) {
  +                // we should never be here
  +            }
  +        }
  +
  +        return returnValue;
       }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.13  +4 -1      xml-cocoon/webapp/Attic/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/webapp/Attic/cocoon.xconf,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- cocoon.xconf	2001/01/08 20:32:44	1.1.2.12
  +++ cocoon.xconf	2001/01/10 17:31:57	1.1.2.13
  @@ -67,10 +67,13 @@
     <component role="org.apache.cocoon.components.datasource.DataSourceComponentSelector"
class="org.apache.cocoon.CocoonComponentSelector">
       <component-instance name="personnel" class="org.apache.cocoon.components.datasource.JdbcDataSource">
         <pool-controller min="5" max="10"/>
  -      <driver>postgresql.Driver</driver>
         <dburl>jdbc:postgresql://localhost/test</dburl>
         <user>test</user>
         <password>test</password>
  +    </component-instance>
  +
  +    <component-instance name="j2eePersonnel" class="org.apache.cocoon.components.datasource.J2eeDataSource">
  +      <dbname>cocoonPersonnel</dbname>
       </component-instance>
     </component>
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +1 -4      xml-cocoon/webapp/docs/samples/forms/Attic/employee.xsp
  
  Index: employee.xsp
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/webapp/docs/samples/forms/Attic/employee.xsp,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- employee.xsp	2001/01/08 15:30:03	1.1.2.2
  +++ employee.xsp	2001/01/10 17:31:58	1.1.2.3
  @@ -49,10 +49,7 @@
           <para>Department:
             <select name="department">
               <esql:execute-query inner-method="no">
  -              <esql:driver>postgresql.Driver</esql:driver>
  -              <esql:dburl>jdbc:postgresql://localhost/test</esql:dburl>
  -              <esql:username>test</esql:username>
  -              <esql:password>test</esql:password>
  +	      <esql:use-connection>personnel</esql:use-connection>
                 <esql:query>select id, name from department_table order by name</esql:query>
                 <esql:results>
                   <option>
  
  
  

Mime
View raw message