01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.sql.conv;
12:
13: import com.versant.core.jdbc.JdbcConverter;
14: import com.versant.core.jdbc.JdbcConverterFactory;
15: import com.versant.core.jdbc.JdbcTypeRegistry;
16: import com.versant.core.jdbc.metadata.JdbcColumn;
17:
18: import javax.jdo.JDOFatalDataStoreException; //todo: appears only in throws clause
19: import java.sql.ResultSet;
20: import java.sql.SQLException;
21: import java.sql.PreparedStatement;
22: import java.math.BigInteger;
23:
24: /**
25: * BigInteger converter for Interbase and Firebird.
26: */
27: public class BigIntegerConverter extends JdbcConverterBase {
28:
29: public static class Factory extends NoArgJdbcConverterFactory {
30:
31: private BigIntegerConverter converter;
32:
33: /**
34: * Create a converter for col using props as parameters. Return null if
35: * no converter is required.
36: */
37: public JdbcConverter createJdbcConverter(JdbcColumn col,
38: Object args, JdbcTypeRegistry jdbcTypeRegistry) {
39: if (converter == null)
40: converter = new BigIntegerConverter();
41: return converter;
42: }
43:
44: }
45:
46: /**
47: * Get the value of col from rs at position index.
48: * @exception java.sql.SQLException on SQL errors
49: * @exception javax.jdo.JDOFatalDataStoreException if the ResultSet value is invalid
50: */
51: public Object get(ResultSet rs, int index, JdbcColumn col)
52: throws SQLException, JDOFatalDataStoreException {
53: String d = rs.getString(index);
54: if (rs.wasNull())
55: return null;
56: return new BigInteger(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 ps, int index, JdbcColumn col,
65: Object value) throws SQLException,
66: JDOFatalDataStoreException {
67: if (value == null) {
68: ps.setNull(index, col.jdbcType);
69: } else {
70: BigInteger bigInteger = (BigInteger) value;
71: ps.setDouble(index, bigInteger.doubleValue());
72: }
73: }
74:
75: /**
76: * Get the type of our expected value objects (e.g. java.util.Locale
77: * for a converter for Locale's).
78: */
79: public Class getValueType() {
80: return BigInteger.class;
81: }
82:
83: }
|