KickJava   Java API By Example, From Geeks To Geeks.

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


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.expressions.*;
27 import oracle.toplink.essentials.internal.databaseaccess.*;
28 import oracle.toplink.essentials.internal.sessions.AbstractSession;
29
30 /**
31  * <p><b>Purpose</b>: Provides Microsoft Access specific behaviour.
32  *
33  * @since TOPLink/Java 1.0
34  */

35 public class AccessPlatform extends oracle.toplink.essentials.platform.database.DatabasePlatform {
36     protected Hashtable buildClassTypes() {
37         Hashtable classTypeMapping = super.buildClassTypes();
38
39         // In access LONG means numeric not CLOB like in Oracle
40
classTypeMapping.put("LONG", Long JavaDoc.class);
41         classTypeMapping.put("TEXT", String JavaDoc.class);
42
43         return classTypeMapping;
44     }
45
46     protected Hashtable buildFieldTypes() {
47         Hashtable fieldTypeMapping;
48
49         fieldTypeMapping = new Hashtable();
50         fieldTypeMapping.put(Boolean JavaDoc.class, new FieldTypeDefinition("BIT", false));
51
52         fieldTypeMapping.put(Integer JavaDoc.class, new FieldTypeDefinition("LONG", false));
53         fieldTypeMapping.put(Long JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
54         fieldTypeMapping.put(Float JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
55         fieldTypeMapping.put(Double JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
56         fieldTypeMapping.put(Short JavaDoc.class, new FieldTypeDefinition("SHORT", false));
57         fieldTypeMapping.put(Byte JavaDoc.class, new FieldTypeDefinition("BYTE", false));
58         fieldTypeMapping.put(java.math.BigInteger JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
59         fieldTypeMapping.put(java.math.BigDecimal JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
60         fieldTypeMapping.put(Number JavaDoc.class, new FieldTypeDefinition("DOUBLE", false));
61
62         fieldTypeMapping.put(String JavaDoc.class, new FieldTypeDefinition("TEXT", 255));
63         fieldTypeMapping.put(Character JavaDoc.class, new FieldTypeDefinition("TEXT", 1));
64         
65         fieldTypeMapping.put(Byte JavaDoc[].class, new FieldTypeDefinition("LONGBINARY", false));
66         fieldTypeMapping.put(Character JavaDoc[].class, new FieldTypeDefinition("MEMO", false));
67         fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("LONGBINARY", false));
68         fieldTypeMapping.put(char[].class, new FieldTypeDefinition("MEMO", false));
69         fieldTypeMapping.put(java.sql.Blob JavaDoc.class, new FieldTypeDefinition("LONGBINARY", false));
70         fieldTypeMapping.put(java.sql.Clob JavaDoc.class, new FieldTypeDefinition("MEMO", false));
71         
72         fieldTypeMapping.put(java.sql.Date JavaDoc.class, new FieldTypeDefinition("DATETIME", false));
73         fieldTypeMapping.put(java.sql.Time JavaDoc.class, new FieldTypeDefinition("DATETIME", false));
74         fieldTypeMapping.put(java.sql.Timestamp JavaDoc.class, new FieldTypeDefinition("DATETIME", false));
75
76         return fieldTypeMapping;
77     }
78
79     /**
80      * INTERNAL:
81      * returns the maximum number of characters that can be used in a field
82      * name on this platform.
83      */

84     public int getMaxFieldNameSize() {
85         return 64;
86     }
87
88     /**
89      * INTERNAL:
90      * Access do not support millisecond well, truncate the millisecond from the timestamp
91      */

92     public java.sql.Timestamp JavaDoc getTimestampFromServer(AbstractSession session, String JavaDoc sessionName) {
93         if (getTimestampQuery() == null) {
94             java.sql.Timestamp JavaDoc currentTime = new java.sql.Timestamp JavaDoc(System.currentTimeMillis());
95             currentTime.setNanos(0);
96             return currentTime;
97         } else {
98             getTimestampQuery().setSessionName(sessionName);
99             return (java.sql.Timestamp JavaDoc)session.executeQuery(getTimestampQuery());
100         }
101     }
102
103     /**
104      * INTERNAL:
105      * Initialize any platform-specific operators
106      */

107     protected void initializePlatformOperators() {
108         super.initializePlatformOperators();
109
110         addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.ToUpperCase, "UCASE"));
111         addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.ToLowerCase, "LCASE"));
112     }
113
114     public boolean isAccess() {
115         return true;
116     }
117
118     /**
119      * INTERNAL:
120      * Builds a table of maximum numeric values keyed on java class. This is used for type testing but
121      * might also be useful to end users attempting to sanitize values.
122      * <p><b>NOTE</b>: BigInteger & BigDecimal maximums are dependent upon their precision & Scale
123      */

124     public Hashtable maximumNumericValues() {
125         Hashtable values = new Hashtable();
126
127         values.put(Integer JavaDoc.class, new Integer JavaDoc(Integer.MAX_VALUE));
128         values.put(Long JavaDoc.class, new Long JavaDoc(Long.MAX_VALUE));
129         values.put(Double JavaDoc.class, new Double JavaDoc(Double.MAX_VALUE));
130         values.put(Short JavaDoc.class, new Short JavaDoc(Short.MAX_VALUE));
131         values.put(Byte JavaDoc.class, new Byte JavaDoc(Byte.MAX_VALUE));
132         values.put(Float JavaDoc.class, new Float JavaDoc(123456789));
133         values.put(java.math.BigInteger JavaDoc.class, new java.math.BigInteger JavaDoc("999999999999999"));
134         values.put(java.math.BigDecimal JavaDoc.class, new java.math.BigDecimal JavaDoc("99999999999999999999.9999999999999999999"));
135         return values;
136     }
137
138     /**
139      * INTERNAL:
140      * Builds a table of minimum numeric values keyed on java class. This is used for type testing but
141      * might also be useful to end users attempting to sanitize values.
142      * <p><b>NOTE</b>: BigInteger & BigDecimal minimums are dependent upon their precision & Scale
143      */

144     public Hashtable minimumNumericValues() {
145         Hashtable values = new Hashtable();
146
147         values.put(Integer JavaDoc.class, new Integer JavaDoc(Integer.MIN_VALUE));
148         values.put(Long JavaDoc.class, new Long JavaDoc(Long.MIN_VALUE));
149         values.put(Double JavaDoc.class, new Double JavaDoc(Double.MIN_VALUE));
150         values.put(Short JavaDoc.class, new Short JavaDoc(Short.MIN_VALUE));
151         values.put(Byte JavaDoc.class, new Byte JavaDoc(Byte.MIN_VALUE));
152         values.put(Float JavaDoc.class, new Float JavaDoc(-123456789));
153         values.put(java.math.BigInteger JavaDoc.class, new java.math.BigInteger JavaDoc("-999999999999999"));
154         values.put(java.math.BigDecimal JavaDoc.class, new java.math.BigDecimal JavaDoc("-9999999999999999999.9999999999999999999"));
155         return values;
156     }
157
158     /**
159      * INTERNAL:
160      * Append the receiver's field 'NOT NULL' constraint clause to a writer.
161      */

162     public void printFieldNotNullClause(Writer writer) {
163         // Do nothing
164
}
165
166     /**
167      * INTERNAL:
168      * This is used as some databases create the primary key constraint differently, i.e. Access.
169      */

170     public boolean requiresNamedPrimaryKeyConstraints() {
171         return true;
172     }
173
174     /**
175      * INTERNAL:
176      * JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
177      */

178     public boolean shouldUseJDBCOuterJoinSyntax() {
179         return false;
180     }
181 }
182
Popular Tags