KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > platform > database > DBasePlatform


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.platform.database;
23
24 import java.io.*;
25 import java.util.*;
26 import oracle.toplink.essentials.internal.databaseaccess.*;
27
28 /**
29  * <p><b>Purpose</b>: Provides DBase specific behaviour.
30  * <p><b>Responsibilities</b>:<ul>
31  * <li> Writing Time & Timestamp as strings since they are not supported.
32  * </ul>
33  *
34  * @since TOPLink/Java 1.0
35  */

36 public class DBasePlatform extends oracle.toplink.essentials.platform.database.DatabasePlatform {
37     protected Hashtable buildFieldTypes() {
38         Hashtable fieldTypeMapping;
39
40         fieldTypeMapping = new Hashtable();
41         fieldTypeMapping.put(Boolean JavaDoc.class, new FieldTypeDefinition("NUMBER", 1));
42
43         fieldTypeMapping.put(Integer JavaDoc.class, new FieldTypeDefinition("NUMBER", 11));
44         fieldTypeMapping.put(Long JavaDoc.class, new FieldTypeDefinition("NUMBER", 19));
45         fieldTypeMapping.put(Float JavaDoc.class, new FieldTypeDefinition("NUMBER", 12, 5).setLimits(19, 0, 19));
46         fieldTypeMapping.put(Double JavaDoc.class, new FieldTypeDefinition("NUMBER", 10, 5).setLimits(19, 0, 19));
47         fieldTypeMapping.put(Short JavaDoc.class, new FieldTypeDefinition("NUMBER", 6));
48         fieldTypeMapping.put(Byte JavaDoc.class, new FieldTypeDefinition("NUMBER", 4));
49         fieldTypeMapping.put(java.math.BigInteger JavaDoc.class, new FieldTypeDefinition("NUMBER", 19));
50         fieldTypeMapping.put(java.math.BigDecimal JavaDoc.class, new FieldTypeDefinition("NUMBER", 19).setLimits(19, 0, 9));
51         fieldTypeMapping.put(Number JavaDoc.class, new FieldTypeDefinition("NUMBER", 19).setLimits(19, 0, 9));
52
53         fieldTypeMapping.put(String JavaDoc.class, new FieldTypeDefinition("CHAR", 255));
54         fieldTypeMapping.put(Character JavaDoc.class, new FieldTypeDefinition("CHAR", 1));
55
56         fieldTypeMapping.put(Byte JavaDoc[].class, new FieldTypeDefinition("BINARY"));
57         fieldTypeMapping.put(Character JavaDoc[].class, new FieldTypeDefinition("MEMO"));
58         fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BINARY"));
59         fieldTypeMapping.put(char[].class, new FieldTypeDefinition("MEMO"));
60         fieldTypeMapping.put(java.sql.Blob JavaDoc.class, new FieldTypeDefinition("BINARY"));
61         fieldTypeMapping.put(java.sql.Clob JavaDoc.class, new FieldTypeDefinition("MEMO"));
62
63         fieldTypeMapping.put(java.sql.Date JavaDoc.class, new FieldTypeDefinition("DATE", false));
64         fieldTypeMapping.put(java.sql.Time JavaDoc.class, new FieldTypeDefinition("CHAR", 15));
65         fieldTypeMapping.put(java.sql.Timestamp JavaDoc.class, new FieldTypeDefinition("CHAR", 25));
66
67         return fieldTypeMapping;
68     }
69
70     /**
71      * INTERNAL:
72      * DBase does not support Time/Timestamp so we must map to strings.
73      * 2.0p22: protected->public INTERNAL
74      */

75     public Object JavaDoc convertToDatabaseType(Object JavaDoc value) {
76         Object JavaDoc dbValue = super.convertToDatabaseType(value);
77         if ((dbValue instanceof java.sql.Time JavaDoc) || (dbValue instanceof java.sql.Timestamp JavaDoc)) {
78             return dbValue.toString();
79         }
80         return dbValue;
81     }
82
83     /**
84      * INTERNAL:
85      * returns the maximum number of characters that can be used in a field
86      * name on this platform.
87      */

88     public int getMaxFieldNameSize() {
89         return 10;
90     }
91     
92     /**
93      * INTERNAL:
94      */

95     public String JavaDoc getSelectForUpdateString() {
96         return " FOR UPDATE OF *";
97     }
98
99     public boolean isDBase() {
100         return true;
101     }
102
103     /**
104      * INTERNAL:
105      * Builds a table of minimum numeric values keyed on java class. This is used for type testing but
106      * might also be useful to end users attempting to sanitize values.
107      * <p><b>NOTE</b>: BigInteger & BigDecimal minimums are dependent upon their precision & Scale
108      */

109     public Hashtable maximumNumericValues() {
110         Hashtable values = new Hashtable();
111
112         values.put(Integer JavaDoc.class, new Integer JavaDoc(Integer.MAX_VALUE));
113         values.put(Long JavaDoc.class, Long.valueOf("922337203685478000"));
114         values.put(Double JavaDoc.class, new Double JavaDoc("99999999.999999999"));
115         values.put(Short JavaDoc.class, new Short JavaDoc(Short.MIN_VALUE));
116         values.put(Byte JavaDoc.class, new Byte JavaDoc(Byte.MIN_VALUE));
117         values.put(Float JavaDoc.class, new Float JavaDoc("99999999.999999999"));
118         values.put(java.math.BigInteger JavaDoc.class, new java.math.BigInteger JavaDoc("922337203685478000"));
119         values.put(java.math.BigDecimal JavaDoc.class, new java.math.BigDecimal JavaDoc("999999.999999999"));
120         return values;
121     }
122
123     /**
124      * INTERNAL:
125      * Builds a table of minimum numeric values keyed on java class. This is used for type testing but
126      * might also be useful to end users attempting to sanitize values.
127      * <p><b>NOTE</b>: BigInteger & BigDecimal minimums are dependent upon their precision & Scale
128      */

129     public Hashtable minimumNumericValues() {
130         Hashtable values = new Hashtable();
131
132         values.put(Integer JavaDoc.class, new Integer JavaDoc(Integer.MIN_VALUE));
133         values.put(Long JavaDoc.class, Long.valueOf("-922337203685478000"));
134         values.put(Double JavaDoc.class, new Double JavaDoc("-99999999.999999999"));
135         values.put(Short JavaDoc.class, new Short JavaDoc(Short.MIN_VALUE));
136         values.put(Byte JavaDoc.class, new Byte JavaDoc(Byte.MIN_VALUE));
137         values.put(Float JavaDoc.class, new Float JavaDoc("-99999999.999999999"));
138         values.put(java.math.BigInteger JavaDoc.class, new java.math.BigInteger JavaDoc("-922337203685478000"));
139         values.put(java.math.BigDecimal JavaDoc.class, new java.math.BigDecimal JavaDoc("-999999.999999999"));
140         return values;
141     }
142
143     /**
144      * INTERNAL:
145      * Append the receiver's field 'NOT NULL' constraint clause to a writer.
146      */

147     public void printFieldNotNullClause(Writer writer) {
148         // Do nothing
149
}
150
151     /**
152      * INTERNAL:
153      * JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
154      */

155     public boolean shouldUseJDBCOuterJoinSyntax() {
156         return false;
157     }
158     
159     /**
160      * INTERNAL:
161      */

162     public boolean supportsForeignKeyConstraints() {
163         return false;
164     }
165     
166     /**
167      * INTERNAL:
168      */

169     public boolean supportsPrimaryKeyConstraint() {
170         return false;
171     }
172 }
173
Popular Tags