KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > value > ValueStringBase


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.value;
6
7 import java.sql.PreparedStatement JavaDoc;
8 import java.sql.SQLException JavaDoc;
9
10 import org.h2.util.MathUtils;
11 import org.h2.util.StringUtils;
12
13 abstract class ValueStringBase extends Value {
14     protected String JavaDoc value;
15
16     protected ValueStringBase(String JavaDoc value) {
17         this.value = value;
18     }
19
20     public String JavaDoc getSQL() {
21         return StringUtils.quoteStringSQL(value);
22     }
23
24     public String JavaDoc getString() {
25         return value;
26     }
27
28     public long getPrecision() {
29         return value.length();
30     }
31
32     public Object JavaDoc getObject() {
33         return value;
34     }
35
36     public void set(PreparedStatement JavaDoc prep, int parameterIndex) throws SQLException JavaDoc {
37         prep.setString(parameterIndex, value);
38     }
39
40     public Value convertPrecision(long precision) {
41         if (precision == 0 || value.length() <= precision) {
42             return this;
43         }
44         int p = MathUtils.convertLongToInt(precision);
45         return ValueString.get(value.substring(0, p));
46     }
47
48 // public String getJavaString() {
49
// return StringUtils.quoteJavaString(value);
50
// }
51

52     public int getDisplaySize() {
53         return value.length();
54     }
55     
56     protected boolean isEqual(Value v) {
57         return v instanceof ValueString && value.equals(((ValueString)v).value);
58     }
59
60 }
61
Popular Tags