01: /*
02: * Jython Database Specification API 2.0
03: *
04: * $Id: MySQLDataHandler.java 2469 2005-05-16 06:43:33Z otmarhumbel $
05: *
06: * Copyright (c) 2001 brian zimmer <bzimmer@ziclix.com>
07: *
08: */
09: 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;
16: import java.io.ByteArrayInputStream;
17: import java.io.InputStream;
18: import java.sql.PreparedStatement;
19: import java.sql.SQLException;
20: import java.sql.Types;
21:
22: /**
23: * MySQL specific data handling.
24: *
25: * @author brian zimmer
26: * @author last revised by $Author: otmarhumbel $
27: * @version $Revision: 2469 $
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 getRowIdMethodName() {
41: return "getLastInsertID";
42: }
43:
44: /**
45: * Handle LONGVARCHAR.
46: */
47: public void setJDBCObject(PreparedStatement stmt, int index,
48: PyObject object, int type) throws SQLException {
49:
50: if (DataHandler.checkNull(stmt, index, object, type)) {
51: return;
52: }
53:
54: switch (type) {
55:
56: case Types.LONGVARCHAR:
57: String varchar;
58: if (object instanceof PyFile) {
59: varchar = ((PyFile) object).read();
60: } else {
61: varchar = (String) object.__tojava__(String.class);
62: }
63: InputStream stream = new ByteArrayInputStream(varchar
64: .getBytes());
65:
66: stream = new BufferedInputStream(stream);
67:
68: stmt.setAsciiStream(index, stream, varchar.length());
69: break;
70:
71: default:
72: super.setJDBCObject(stmt, index, object, type);
73: break;
74: }
75: }
76: }
|