KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ziclix > python > sql > handler > MySQLDataHandler


1 /*
2  * Jython Database Specification API 2.0
3  *
4  * $Id: MySQLDataHandler.java,v 1.4 2005/05/16 06:43:33 otmarhumbel Exp $
5  *
6  * Copyright (c) 2001 brian zimmer <bzimmer@ziclix.com>
7  *
8  */

9 package com.ziclix.python.sql.handler;
10
11 import com.ziclix.python.sql.DataHandler;
12 import org.python.core.PyFile;
13 import org.python.core.PyObject;
14
15 import java.io.BufferedInputStream JavaDoc;
16 import java.io.ByteArrayInputStream JavaDoc;
17 import java.io.InputStream JavaDoc;
18 import java.sql.PreparedStatement JavaDoc;
19 import java.sql.SQLException JavaDoc;
20 import java.sql.Types JavaDoc;
21
22 /**
23  * MySQL specific data handling.
24  *
25  * @author brian zimmer
26  * @author last revised by $Author: otmarhumbel $
27  * @version $Revision: 1.4 $
28  */

29 public class MySQLDataHandler extends RowIdHandler {
30
31   /**
32    * Decorator for handling MySql specific issues.
33    *
34    * @param datahandler the delegate DataHandler
35    */

36   public MySQLDataHandler(DataHandler datahandler) {
37     super(datahandler);
38   }
39
40   protected String JavaDoc getRowIdMethodName() {
41     return "getLastInsertID";
42   }
43
44   /**
45    * Handle LONGVARCHAR.
46    */

47   public void setJDBCObject(PreparedStatement JavaDoc stmt, int index, PyObject object, int type) throws SQLException JavaDoc {
48
49     if (DataHandler.checkNull(stmt, index, object, type)) {
50       return;
51     }
52
53     switch (type) {
54
55       case Types.LONGVARCHAR:
56         String JavaDoc varchar;
57         if (object instanceof PyFile) {
58           varchar = ((PyFile) object).read();
59         } else {
60           varchar = (String JavaDoc) object.__tojava__(String JavaDoc.class);
61         }
62         InputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(varchar.getBytes());
63
64         stream = new BufferedInputStream JavaDoc(stream);
65
66         stmt.setAsciiStream(index, stream, varchar.length());
67         break;
68
69       default :
70         super.setJDBCObject(stmt, index, object, type);
71         break;
72     }
73   }
74 }
75
Popular Tags