KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > conv > BigIntegerConverter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.sql.conv;
13
14 import com.versant.core.jdbc.JdbcConverter;
15 import com.versant.core.jdbc.JdbcConverterFactory;
16 import com.versant.core.jdbc.JdbcTypeRegistry;
17 import com.versant.core.jdbc.metadata.JdbcColumn;
18
19 import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
20
import java.sql.ResultSet JavaDoc;
21 import java.sql.SQLException JavaDoc;
22 import java.sql.PreparedStatement JavaDoc;
23 import java.math.BigInteger JavaDoc;
24
25
26 /**
27  * BigInteger converter for Interbase and Firebird.
28  */

29 public class BigIntegerConverter extends JdbcConverterBase {
30
31     public static class Factory extends NoArgJdbcConverterFactory {
32
33         private BigIntegerConverter converter;
34
35         /**
36          * Create a converter for col using props as parameters. Return null if
37          * no converter is required.
38          */

39         public JdbcConverter createJdbcConverter(JdbcColumn col, Object JavaDoc args,
40                 JdbcTypeRegistry jdbcTypeRegistry) {
41             if (converter == null) converter = new BigIntegerConverter();
42             return converter;
43         }
44
45     }
46
47     /**
48      * Get the value of col from rs at position index.
49      * @exception java.sql.SQLException on SQL errors
50      * @exception javax.jdo.JDOFatalDataStoreException if the ResultSet value is invalid
51      */

52     public Object JavaDoc get(ResultSet JavaDoc rs, int index, JdbcColumn col)
53             throws SQLException JavaDoc, JDOFatalDataStoreException {
54         String JavaDoc d = rs.getString(index);
55         if (rs.wasNull())return null;
56         return new BigInteger JavaDoc(d);
57     }
58
59     /**
60      * Set parameter index on ps to value (for col).
61      * @exception java.sql.SQLException on SQL errors
62      * @exception javax.jdo.JDOFatalDataStoreException if value is invalid
63      */

64     public void set(PreparedStatement JavaDoc ps, int index, JdbcColumn col, Object JavaDoc value)
65             throws SQLException JavaDoc, JDOFatalDataStoreException {
66         if (value == null) {
67             ps.setNull(index, col.jdbcType);
68         } else {
69             BigInteger JavaDoc bigInteger = (BigInteger JavaDoc)value;
70             ps.setDouble(index, bigInteger.doubleValue());
71         }
72     }
73
74     /**
75      * Get the type of our expected value objects (e.g. java.util.Locale
76      * for a converter for Locale's).
77      */

78     public Class JavaDoc getValueType() {
79         return BigInteger JavaDoc.class;
80     }
81
82 }
83
Popular Tags