KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Jython Database Specification API 2.0
3  *
4  * $Id: SQLServerDataHandler.java,v 1.4 2005/02/23 04:26:19 bzimmer 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 com.ziclix.python.sql.FilterDataHandler;
13 import com.ziclix.python.sql.Procedure;
14 import com.ziclix.python.sql.PyCursor;
15 import com.ziclix.python.sql.procedure.SQLServerProcedure;
16 import org.python.core.Py;
17 import org.python.core.PyObject;
18
19 import java.sql.ResultSet JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.sql.Types JavaDoc;
22
23 /**
24  * SQLServer specific data handling.
25  *
26  * @author brian zimmer
27  * @author last revised by $Author: bzimmer $
28  * @version $Revision: 1.4 $
29  */

30 public class SQLServerDataHandler extends FilterDataHandler {
31
32     /**
33      * Field UNICODE_VARCHAR
34      */

35     public static final int UNICODE_VARCHAR = -9;
36
37     /**
38      * Decorator for handling SQLServer specific issues.
39      *
40      * @param datahandler the delegate DataHandler
41      */

42     public SQLServerDataHandler(DataHandler datahandler) {
43         super(datahandler);
44     }
45
46     public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException JavaDoc {
47         return new SQLServerProcedure(cursor, name);
48     }
49
50     /**
51      * Given a ResultSet, column and type, return the appropriate
52      * Jython object.
53      * <p/>
54      * <p>Note: DO NOT iterate the ResultSet.
55      *
56      * @param set the current ResultSet set to the current row
57      * @param col the column number (adjusted properly for JDBC)
58      * @param type the column type
59      * @throws SQLException if the type is unmappable
60      */

61     public PyObject getPyObject(ResultSet JavaDoc set, int col, int type) throws SQLException JavaDoc {
62
63         PyObject obj = Py.None;
64
65         switch (type) {
66
67             case UNICODE_VARCHAR:
68                 obj = super.getPyObject(set, col, Types.VARCHAR);
69                 break;
70
71             default :
72                 obj = super.getPyObject(set, col, type);
73         }
74
75         return (set.wasNull() || (obj == null)) ? Py.None : obj;
76     }
77 }
78
Popular Tags