KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > types > BigIntegerType


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.access.types;
20
21 import java.math.BigInteger JavaDoc;
22 import java.sql.CallableStatement JavaDoc;
23 import java.sql.PreparedStatement JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25
26 import org.apache.cayenne.dba.TypesMapping;
27 import org.apache.cayenne.map.DbAttribute;
28 import org.apache.cayenne.validation.ValidationResult;
29
30 /**
31  * @since 3.0
32  * @author Andrus Adamchik
33  */

34 public class BigIntegerType implements ExtendedType {
35
36     public String JavaDoc getClassName() {
37         return BigInteger JavaDoc.class.getName();
38     }
39
40     public Object JavaDoc materializeObject(ResultSet JavaDoc rs, int index, int type) throws Exception JavaDoc {
41         Object JavaDoc object = rs.getObject(index);
42         if (rs.wasNull()) {
43             return null;
44         }
45
46         return new BigInteger JavaDoc(object.toString());
47     }
48
49     public Object JavaDoc materializeObject(CallableStatement JavaDoc rs, int index, int type)
50             throws Exception JavaDoc {
51         Object JavaDoc object = rs.getObject(index);
52         if (rs.wasNull()) {
53             return null;
54         }
55
56         return new BigInteger JavaDoc(object.toString());
57     }
58
59     public void setJdbcObject(
60             PreparedStatement JavaDoc statement,
61             Object JavaDoc value,
62             int pos,
63             int type,
64             int precision) throws Exception JavaDoc {
65
66         if (value == null) {
67             statement.setNull(pos, type);
68         }
69         else if (TypesMapping.isNumeric(type)) {
70             statement.setLong(pos, ((BigInteger JavaDoc) value).longValue());
71         }
72         else {
73             throw new IllegalArgumentException JavaDoc(
74                     "Can't map BigInteger to a non-numeric type: "
75                             + TypesMapping.getSqlNameByType(type));
76         }
77     }
78
79     /**
80      * @deprecated since 3.0 as validation should not be done at the DataNode level.
81      */

82     public boolean validateProperty(
83             Object JavaDoc source,
84             String JavaDoc property,
85             Object JavaDoc value,
86             DbAttribute dbAttribute,
87             ValidationResult validationResult) {
88         return true;
89     }
90 }
91
Popular Tags