001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.platform.database;
038:
039: import java.io.*;
040: import java.util.*;
041: import oracle.toplink.essentials.internal.databaseaccess.*;
042:
043: /**
044: * <p><b>Purpose</b>: Provides DBase specific behaviour.
045: * <p><b>Responsibilities</b>:<ul>
046: * <li> Writing Time & Timestamp as strings since they are not supported.
047: * </ul>
048: *
049: * @since TOPLink/Java 1.0
050: */
051: public class DBasePlatform extends
052: oracle.toplink.essentials.platform.database.DatabasePlatform {
053: protected Hashtable buildFieldTypes() {
054: Hashtable fieldTypeMapping;
055:
056: fieldTypeMapping = new Hashtable();
057: fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition(
058: "NUMBER", 1));
059:
060: fieldTypeMapping.put(Integer.class, new FieldTypeDefinition(
061: "NUMBER", 11));
062: fieldTypeMapping.put(Long.class, new FieldTypeDefinition(
063: "NUMBER", 19));
064: fieldTypeMapping.put(Float.class, new FieldTypeDefinition(
065: "NUMBER", 12, 5).setLimits(19, 0, 19));
066: fieldTypeMapping.put(Double.class, new FieldTypeDefinition(
067: "NUMBER", 10, 5).setLimits(19, 0, 19));
068: fieldTypeMapping.put(Short.class, new FieldTypeDefinition(
069: "NUMBER", 6));
070: fieldTypeMapping.put(Byte.class, new FieldTypeDefinition(
071: "NUMBER", 4));
072: fieldTypeMapping.put(java.math.BigInteger.class,
073: new FieldTypeDefinition("NUMBER", 19));
074: fieldTypeMapping.put(java.math.BigDecimal.class,
075: new FieldTypeDefinition("NUMBER", 19).setLimits(19, 0,
076: 9));
077: fieldTypeMapping.put(Number.class, new FieldTypeDefinition(
078: "NUMBER", 19).setLimits(19, 0, 9));
079:
080: fieldTypeMapping.put(String.class, new FieldTypeDefinition(
081: "CHAR", 255));
082: fieldTypeMapping.put(Character.class, new FieldTypeDefinition(
083: "CHAR", 1));
084:
085: fieldTypeMapping.put(Byte[].class, new FieldTypeDefinition(
086: "BINARY"));
087: fieldTypeMapping.put(Character[].class,
088: new FieldTypeDefinition("MEMO"));
089: fieldTypeMapping.put(byte[].class, new FieldTypeDefinition(
090: "BINARY"));
091: fieldTypeMapping.put(char[].class, new FieldTypeDefinition(
092: "MEMO"));
093: fieldTypeMapping.put(java.sql.Blob.class,
094: new FieldTypeDefinition("BINARY"));
095: fieldTypeMapping.put(java.sql.Clob.class,
096: new FieldTypeDefinition("MEMO"));
097:
098: fieldTypeMapping.put(java.sql.Date.class,
099: new FieldTypeDefinition("DATE", false));
100: fieldTypeMapping.put(java.sql.Time.class,
101: new FieldTypeDefinition("CHAR", 15));
102: fieldTypeMapping.put(java.sql.Timestamp.class,
103: new FieldTypeDefinition("CHAR", 25));
104:
105: return fieldTypeMapping;
106: }
107:
108: /**
109: * INTERNAL:
110: * DBase does not support Time/Timestamp so we must map to strings.
111: * 2.0p22: protected->public INTERNAL
112: */
113: public Object convertToDatabaseType(Object value) {
114: Object dbValue = super .convertToDatabaseType(value);
115: if ((dbValue instanceof java.sql.Time)
116: || (dbValue instanceof java.sql.Timestamp)) {
117: return dbValue.toString();
118: }
119: return dbValue;
120: }
121:
122: /**
123: * INTERNAL:
124: * returns the maximum number of characters that can be used in a field
125: * name on this platform.
126: */
127: public int getMaxFieldNameSize() {
128: return 10;
129: }
130:
131: /**
132: * INTERNAL:
133: */
134: public String getSelectForUpdateString() {
135: return " FOR UPDATE OF *";
136: }
137:
138: public boolean isDBase() {
139: return true;
140: }
141:
142: /**
143: * INTERNAL:
144: * Builds a table of minimum numeric values keyed on java class. This is used for type testing but
145: * might also be useful to end users attempting to sanitize values.
146: * <p><b>NOTE</b>: BigInteger & BigDecimal minimums are dependent upon their precision & Scale
147: */
148: public Hashtable maximumNumericValues() {
149: Hashtable values = new Hashtable();
150:
151: values.put(Integer.class, new Integer(Integer.MAX_VALUE));
152: values.put(Long.class, Long.valueOf("922337203685478000"));
153: values.put(Double.class, new Double("99999999.999999999"));
154: values.put(Short.class, new Short(Short.MIN_VALUE));
155: values.put(Byte.class, new Byte(Byte.MIN_VALUE));
156: values.put(Float.class, new Float("99999999.999999999"));
157: values.put(java.math.BigInteger.class,
158: new java.math.BigInteger("922337203685478000"));
159: values.put(java.math.BigDecimal.class,
160: new java.math.BigDecimal("999999.999999999"));
161: return values;
162: }
163:
164: /**
165: * INTERNAL:
166: * Builds a table of minimum numeric values keyed on java class. This is used for type testing but
167: * might also be useful to end users attempting to sanitize values.
168: * <p><b>NOTE</b>: BigInteger & BigDecimal minimums are dependent upon their precision & Scale
169: */
170: public Hashtable minimumNumericValues() {
171: Hashtable values = new Hashtable();
172:
173: values.put(Integer.class, new Integer(Integer.MIN_VALUE));
174: values.put(Long.class, Long.valueOf("-922337203685478000"));
175: values.put(Double.class, new Double("-99999999.999999999"));
176: values.put(Short.class, new Short(Short.MIN_VALUE));
177: values.put(Byte.class, new Byte(Byte.MIN_VALUE));
178: values.put(Float.class, new Float("-99999999.999999999"));
179: values.put(java.math.BigInteger.class,
180: new java.math.BigInteger("-922337203685478000"));
181: values.put(java.math.BigDecimal.class,
182: new java.math.BigDecimal("-999999.999999999"));
183: return values;
184: }
185:
186: /**
187: * INTERNAL:
188: * Append the receiver's field 'NOT NULL' constraint clause to a writer.
189: */
190: public void printFieldNotNullClause(Writer writer) {
191: // Do nothing
192: }
193:
194: /**
195: * INTERNAL:
196: * JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
197: */
198: public boolean shouldUseJDBCOuterJoinSyntax() {
199: return false;
200: }
201:
202: /**
203: * INTERNAL:
204: */
205: public boolean supportsForeignKeyConstraints() {
206: return false;
207: }
208:
209: /**
210: * INTERNAL:
211: */
212: public boolean supportsPrimaryKeyConstraint() {
213: return false;
214: }
215: }
|