KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactions > SaveImage


1 package transactions;
2
3 import dinamica.*;
4 import java.io.*;
5
6 /**
7  * Save image to blob column
8  * The SQL will be preprocessed to set all
9  * the required static values.
10  *
11  * @author Martin Cordova
12  * */

13 public class SaveImage extends GenericTransaction
14 {
15
16     /* (non-Javadoc)
17      * @see dinamica.GenericTransaction#service(dinamica.Recordset)
18      */

19     public int service(Recordset inputParams) throws Throwable JavaDoc
20     {
21         int rc = super.service(inputParams);
22         
23         //set image size field
24
String JavaDoc path = (String JavaDoc)inputParams.getValue("file");
25         File f = new File(path);
26         Integer JavaDoc size = new Integer JavaDoc((int)f.length());
27         inputParams.setValue("image_size", size);
28
29         //fix original filename (remove path)
30
String JavaDoc fileName = (String JavaDoc)inputParams.getValue("file.filename");
31         fileName = fileName.substring(fileName.lastIndexOf(File.separator)+1);
32         inputParams.setValue("file.filename", fileName);
33         
34         //prepare sql template
35
String JavaDoc sql = getResource("query.sql");
36         sql = getSQL(sql, inputParams);
37         
38         //get db object and save blob
39
Db db = getDb();
40         db.saveBlob(sql, path);
41         
42         return rc;
43         
44     }
45
46 }
47
Popular Tags