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.xml
Date Tue, 27 Feb 2001 18:19:17 GMT
bloritsch    01/02/27 10:19:16

  Modified:    src/org/apache/cocoon/acting Tag: xml-cocoon2
                        AbstractDatabaseAction.java DatabaseAddAction.java
                        DatabaseDeleteAction.java DatabaseUpdateAction.java
               webapp/docs/samples/forms Tag: xml-cocoon2 employee.xml
  Log:
  More fixes to DatabaseAction system
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +2 -2      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.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- AbstractDatabaseAction.java	2001/02/27 17:06:00	1.1.2.6
  +++ AbstractDatabaseAction.java	2001/02/27 18:19:05	1.1.2.7
  @@ -141,7 +141,7 @@
    * </table>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2001/02/27 17:06:00 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2001/02/27 18:19:05 $
    */
   public abstract class AbstractDatabaseAction extends ComposerAction implements Configurable
{
       private static Map configurations = new HashMap();
  @@ -249,7 +249,7 @@
       /**
        * Set the Statement column so that the results are mapped correctly.
        */
  -    protected final void setColumn(PreparedStatement statement, int position, HttpRequest
request, Configuration entry) throws Exception {
  +    protected void setColumn(PreparedStatement statement, int position, HttpRequest request,
Configuration entry) throws Exception {
           Integer typeObject = (Integer) AbstractDatabaseAction.typeConstants.get(entry.getAttribute("type"));
   
           if (typeObject == null) {
  
  
  
  1.1.2.5   +75 -1     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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- DatabaseAddAction.java	2001/02/27 16:49:13	1.1.2.4
  +++ DatabaseAddAction.java	2001/02/27 18:19:07	1.1.2.5
  @@ -40,10 +40,11 @@
    * only one table at a time to update.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/27 16:49:13 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/02/27 18:19:07 $
    */
   public class DatabaseAddAction extends AbstractDatabaseAction {
       private static final Map addStatements = new HashMap();
  +    private static final Map selectStatements = new HashMap();
   
       /**
        * Delete a record from the database.  This action assumes that
  @@ -60,12 +61,23 @@
               datasource = this.getDataSource(conf);
               conn = datasource.getConnection();
               HttpRequest request = (HttpRequest) objectModel.get(Constants.REQUEST_OBJECT);
  +            conn.setAutoCommit(false);
   
               PreparedStatement statement = conn.prepareStatement(query);
   
  +            Iterator keys = conf.getChild("table").getChild("keys").getChildren("key");
               Iterator values = conf.getChild("table").getChild("values").getChildren("value");
               int currentIndex = 1;
   
  +
  +            while (keys.hasNext()) {
  +                Configuration key = (Configuration) keys.next();
  +                if ("manual".equals(key.getAttribute("mode", "automatic"))) {
  +                    this.setColumn(statement, currentIndex, request, key);
  +                    currentIndex++;
  +                }
  +            }
  +
               for (int i = currentIndex; values.hasNext(); i++) {
                   Configuration itemConf = (Configuration) values.next();
                   this.setColumn(statement, i, request, itemConf);
  @@ -73,7 +85,12 @@
               }
   
               statement.execute();
  +            conn.commit();
  +            statement.close();
           } catch (Exception e) {
  +            if (conn != null) {
  +                conn.rollback();
  +            }
               throw new ProcessingException("Could not add record", e);
           } finally {
               if (conn != null) {
  @@ -104,6 +121,7 @@
               if (query == null) {
                   Configuration table = conf.getChild("table");
                   Iterator values = table.getChild("values").getChildren("value");
  +                Iterator keys = table.getChild("keys").getChildren("key");
   
                   StringBuffer queryBuffer = new StringBuffer("INSERT INTO ");
                   queryBuffer.append(table.getAttribute("name"));
  @@ -111,6 +129,20 @@
   
                   boolean firstIteration = true;
   
  +                while (keys.hasNext()) {
  +                    Configuration key = (Configuration) keys.next();
  +                    if ("manual".equals(key.getAttribute("mode", "automatic"))) {
  +                        if (firstIteration) {
  +                            firstIteration = false;
  +                        } else {
  +                            queryBuffer.append(", ");
  +                        }
  +
  +                        queryBuffer.append(key.getAttribute("dbcol"));
  +                        this.setSelectQuery(conf, key);
  +                    }
  +                }
  +
                   while (values.hasNext()) {
                       if (firstIteration) {
                           firstIteration = false;
  @@ -143,5 +175,47 @@
           }
   
           return query;
  +    }
  +
  +    protected final void setColumn(PreparedStatement statement, int position, HttpRequest
request, Configuration entry) throws Exception {
  +        super.setColumn(statement, position, request, entry);
  +
  +        if ("key".equals(entry.getName())) {
  +            String mode = entry.getAttribute("mode", "automatic");
  +
  +            if ("manual".equals(mode)) {
  +                String query = this.getSelectQuery(entry);
  +                Connection conn = statement.getConnection();
  +
  +                ResultSet set = conn.createStatement().executeQuery(query);
  +                int value = set.getInt("maxid");
  +
  +                getLogger().info("Reassigning column " + position + "'" + entry.getAttribute("dbcol")
+ "' to: " + value);
  +                statement.setInt(position, value);
  +
  +                set.getStatement().close();
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Set the String representation of the MaxID lookup statement.  This is
  +     * mapped to the Configuration object itself, so if it doesn't exist,
  +     * it will be created.
  +     */
  +    private final synchronized void setSelectQuery(Configuration conf, Configuration entry)
throws ConfigurationException {
  +        Configuration table = conf.getChild("table");
  +        Iterator values = table.getChild("values").getChildren("value");
  +
  +        StringBuffer queryBuffer = new StringBuffer("SELECT max(");
  +        queryBuffer.append(entry.getAttribute("dbcol"));
  +        queryBuffer.append(") AS maxid FROM ");
  +        queryBuffer.append(table.getAttribute("name"));
  +
  +        DatabaseAddAction.addStatements.put(entry, queryBuffer.toString());
  +    }
  +
  +    private final synchronized String getSelectQuery(Configuration entry) throws ConfigurationException
{
  +        return (String) DatabaseAddAction.selectStatements.get(entry);
       }
   }
  
  
  
  1.1.2.5   +7 -1      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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- DatabaseDeleteAction.java	2001/02/27 16:49:13	1.1.2.4
  +++ DatabaseDeleteAction.java	2001/02/27 18:19:08	1.1.2.5
  @@ -43,7 +43,7 @@
    * the keys.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/02/27 16:49:13 $
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/02/27 18:19:08 $
    */
   public final class DatabaseDeleteAction extends AbstractDatabaseAction {
       private static final Map deleteStatements = new HashMap();
  @@ -63,6 +63,7 @@
               datasource = this.getDataSource(conf);
               conn = datasource.getConnection();
               HttpRequest request = (HttpRequest) objectModel.get(Constants.REQUEST_OBJECT);
  +            conn.setAutoCommit(false);
   
               PreparedStatement statement = conn.prepareStatement(query);
   
  @@ -74,7 +75,12 @@
               }
   
               statement.execute();
  +            conn.commit();
  +            statement.close();
           } catch (Exception e) {
  +            if (conn != null) {
  +                conn.rollback();
  +            }
               throw new ProcessingException("Could not delete record", e);
           } finally {
               if (conn != null) {
  
  
  
  1.1.2.9   +8 -1      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.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- DatabaseUpdateAction.java	2001/02/27 17:05:57	1.1.2.8
  +++ DatabaseUpdateAction.java	2001/02/27 18:19:09	1.1.2.9
  @@ -40,7 +40,7 @@
    * only one table at a time to update.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.8 $ $Date: 2001/02/27 17:05:57 $
  + * @version CVS $Revision: 1.1.2.9 $ $Date: 2001/02/27 18:19:09 $
    */
   public class DatabaseUpdateAction extends AbstractDatabaseAction {
       private static final Map updateStatements = new HashMap();
  @@ -60,6 +60,7 @@
               datasource = this.getDataSource(conf);
               conn = datasource.getConnection();
               HttpRequest request = (HttpRequest) objectModel.get(Constants.REQUEST_OBJECT);
  +            conn.setAutoCommit(false);
   
               PreparedStatement statement = conn.prepareStatement(query);
   
  @@ -79,7 +80,13 @@
               }
   
               statement.execute();
  +            conn.commit();
  +            statement.close();
           } catch (Exception e) {
  +            if (conn != null) {
  +                conn.rollback();
  +            }
  +
               throw new ProcessingException("Could not update record", e);
           } finally {
               if (conn != null) {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +1 -1      xml-cocoon/webapp/docs/samples/forms/Attic/employee.xml
  
  Index: employee.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/webapp/docs/samples/forms/Attic/employee.xml,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- employee.xml	2001/02/27 17:10:29	1.1.2.1
  +++ employee.xml	2001/02/27 18:19:14	1.1.2.2
  @@ -4,7 +4,7 @@
     <connection>personnel</connection>
     <table name="employee_table">
       <keys>
  -      <key param="employee" dbcol="id" type="int"/>
  +      <key param="employee" dbcol="id" type="int" mode="manual"/>
       </keys>
       <values>
         <value param="name" dbcol="name" type="string"/>
  
  
  

Mime
View raw message