bloritsch    01/02/22 12:57:40

  Modified:    src/org/apache/cocoon/acting Tag: xml-cocoon2
                        ImageUploadAction.java
  Log:
  Updated with update logic
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +36 -4     
xml-cocoon/src/org/apache/cocoon/acting/Attic/ImageUploadAction.java
  
  Index: ImageUploadAction.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/acting/Attic/ImageUploadAction.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ImageUploadAction.java    2001/02/22 20:30:46     1.1.2.1
  +++ ImageUploadAction.java    2001/02/22 20:57:35     1.1.2.2
  @@ -46,7 +46,7 @@
    * at this time.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/02/22 20:30:46 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/02/22 20:57:35 $
    */
   public class ImageUploadAction extends ComposerAction implements 
Contextualizable {
       private final static int SIZE = 0;
  @@ -92,6 +92,7 @@
   
           String table = param.getParameter("table", null);
           String column = param.getParameter("image", null);
  +        String keycol = param.getParameter("key", null);
   
           if (table == null || column == null) {
               throw new ProcessingException("Cannot insert into a null 
table/column");
  @@ -110,7 +111,14 @@
               paramColumns[i] = 
param.getParameter(ImageUploadAction.PARAM_NAMES[i], null);
           }
   
  -        String query = this.setupInsertQuery(table, column, paramColumns, 
paramPositions);
  +        String query;
  +
  +        if (keycol == null || source == null) {
  +            query = this.setupInsertQuery(table, column, paramColumns, 
paramPositions);
  +        } else {
  +            query = this.setupUpdateQuery(table, column, paramColumns, 
paramPositions, keycol, source);
  +        }
  +
           File image = null;
   
           try {
  @@ -125,12 +133,18 @@
   
               statement.setBinaryStream(1, new FileInputStream(image), 
paramValues[ImageUploadAction.SIZE]);
   
  +            int maxIndex = 1;
               for (int i = 0; i < ImageUploadAction.NUM_PARAMS; i++) {
                   if (paramPositions[i] > 0) {
                       statement.setInt(paramPositions[i], paramValues[i]);
  +                    maxIndex = Math.max(paramPositions[i], maxIndex);
                   }
               }
   
  +            if (keycol != null && source != null) {
  +                statement.setString(maxIndex, source);
  +            }
  +
               statement.execute();
           } catch (Exception e) {
               getLogger().warn("Could not commit file: " + query, e);
  @@ -160,10 +174,8 @@
           }
   
           query.append(") VALUES (?");
  +
           int index = 2;
  -        int widthIndex = -1;
  -        int heightIndex = -1;
  -        int sizeIndex = -1;
   
           for (int i = 0; i < ImageUploadAction.NUM_PARAMS; i++) {
               if (paramNames[i] != null) {
  @@ -176,6 +188,26 @@
           }
   
           query.append(")");
  +
  +        return query.toString();
  +    }
  +
  +    String setupUpdateQuery(String table, String column, String[] 
paramNames, int[] paramPositions, String keyColumn, String key) {
  +        StringBuffer query = new StringBuffer("UPDATE ");
  +        query.append(table).append(" SET ").append(column).append(" = ?");
  +        int index = 2;
  +
  +        for (int i = 0; i < ImageUploadAction.NUM_PARAMS; i++) {
  +            if (paramNames[i] != null) {
  +                query.append(", ").append(paramNames[i]).append(" = ?");
  +                paramPositions[i] = index;
  +                index++;
  +            } else {
  +                paramPositions[i] = -1;
  +            }
  +        }
  +
  +        query.append(" WHERE ").append(keyColumn).append(" = ?");
   
           return query.toString();
       }
  
  
  

Reply via email to