1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.platform.database;
import java.io.*;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
import org.eclipse.persistence.internal.sessions.AbstractSession;
/**
* <p><b>Purpose</b>: Provides DBase specific behavior.
* <p><b>Responsibilities</b>:<ul>
* <li> Writing Time {@literal &} Timestamp as strings since they are not supported.
* </ul>
*
* @since TOPLink/Java 1.0
*/
public class DBasePlatform extends org.eclipse.persistence.platform.database.DatabasePlatform {
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping;
fieldTypeMapping = new Hashtable();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("NUMBER", 1));
fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("NUMBER", 11));
fieldTypeMapping.put(Long.class, new FieldTypeDefinition("NUMBER", 19));
fieldTypeMapping.put(Float.class, new FieldTypeDefinition("NUMBER", 12, 5).setLimits(19, 0, 19));
fieldTypeMapping.put(Double.class, new FieldTypeDefinition("NUMBER", 10, 5).setLimits(19, 0, 19));
fieldTypeMapping.put(Short.class, new FieldTypeDefinition("NUMBER", 6));
fieldTypeMapping.put(Byte.class, new FieldTypeDefinition("NUMBER", 4));
fieldTypeMapping.put(java.math.BigInteger.class, new FieldTypeDefinition("NUMBER", 19));
fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("NUMBER", 19).setLimits(19, 0, 9));
fieldTypeMapping.put(Number.class, new FieldTypeDefinition("NUMBER", 19).setLimits(19, 0, 9));
fieldTypeMapping.put(String.class, new FieldTypeDefinition("CHAR", DEFAULT_VARCHAR_SIZE));
fieldTypeMapping.put(Character.class, new FieldTypeDefinition("CHAR", 1));
fieldTypeMapping.put(Byte[].class, new FieldTypeDefinition("BINARY"));
fieldTypeMapping.put(Character[].class, new FieldTypeDefinition("MEMO"));
fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BINARY"));
fieldTypeMapping.put(char[].class, new FieldTypeDefinition("MEMO"));
fieldTypeMapping.put(java.sql.Blob.class, new FieldTypeDefinition("BINARY"));
fieldTypeMapping.put(java.sql.Clob.class, new FieldTypeDefinition("MEMO"));
fieldTypeMapping.put(java.sql.Date.class, new FieldTypeDefinition("DATE", false));
fieldTypeMapping.put(java.sql.Time.class, new FieldTypeDefinition("CHAR", 15));
fieldTypeMapping.put(java.sql.Timestamp.class, new FieldTypeDefinition("CHAR", 25));
return fieldTypeMapping;
}
/**
* INTERNAL
* We support more primitive than JDBC does so we must do conversion before printing or binding.
*/
public Object convertToDatabaseType(Object value) {
Object databaseValue = super.convertToDatabaseType(value);
if ((databaseValue instanceof java.sql.Time) || (databaseValue instanceof java.sql.Timestamp)) {
databaseValue = databaseValue.toString();
}
return databaseValue;
}
/**
* INTERNAL:
* DBase does not support Time/Timestamp so we must map to strings.
*/
public void setParameterValueInDatabaseCall(Object parameter,
PreparedStatement statement, int index, AbstractSession session) throws SQLException {
Object databaseValue = super.convertToDatabaseType(parameter);
if ((databaseValue instanceof java.sql.Time) || (databaseValue instanceof java.sql.Timestamp)) {
databaseValue = databaseValue.toString();
}
super.setParameterValueInDatabaseCall(databaseValue, statement, index, session);
}
/**
* INTERNAL:
* DBase does not support Time/Timestamp so we must map to strings.
*/
@Override
public void setParameterValueInDatabaseCall(Object parameter,
CallableStatement statement, String name, AbstractSession session) throws SQLException {
Object databaseValue = super.convertToDatabaseType(parameter);
if ((databaseValue instanceof java.sql.Time) || (databaseValue instanceof java.sql.Timestamp)) {
databaseValue = databaseValue.toString();
}
super.setParameterValueInDatabaseCall(databaseValue, statement, name, session);
}
/**
* INTERNAL:
* returns the maximum number of characters that can be used in a field
* name on this platform.
*/
public int getMaxFieldNameSize() {
return 10;
}
public String getSelectForUpdateString() {
return " FOR UPDATE OF *";
}
public boolean isDBase() {
return true;
}
/**
* Builds a table of minimum numeric values keyed on java class. This is used for type testing but
* might also be useful to end users attempting to sanitize values.
* <p><b>NOTE</b>: BigInteger {@literal &} BigDecimal minimums are dependent upon their precision {@literal &} Scale
*/
public Hashtable maximumNumericValues() {
Hashtable values = new Hashtable();
values.put(Integer.class, Integer.valueOf(Integer.MAX_VALUE));
values.put(Long.class, Long.valueOf("922337203685478000"));
values.put(Double.class, Double.valueOf("99999999.999999999"));
values.put(Short.class, Short.valueOf(Short.MIN_VALUE));
values.put(Byte.class, Byte.valueOf(Byte.MIN_VALUE));
values.put(Float.class, Float.valueOf("99999999.999999999"));
values.put(java.math.BigInteger.class, new java.math.BigInteger("922337203685478000"));
values.put(java.math.BigDecimal.class, new java.math.BigDecimal("999999.999999999"));
return values;
}
/**
* Builds a table of minimum numeric values keyed on java class. This is used for type testing but
* might also be useful to end users attempting to sanitize values.
* <p><b>NOTE</b>: BigInteger {@literal &} BigDecimal minimums are dependent upon their precision {@literal &} Scale
*/
public Hashtable minimumNumericValues() {
Hashtable values = new Hashtable();
values.put(Integer.class, Integer.valueOf(Integer.MIN_VALUE));
values.put(Long.class, Long.valueOf("-922337203685478000"));
values.put(Double.class, Double.valueOf("-99999999.999999999"));
values.put(Short.class, Short.valueOf(Short.MIN_VALUE));
values.put(Byte.class, Byte.valueOf(Byte.MIN_VALUE));
values.put(Float.class, Float.valueOf("-99999999.999999999"));
values.put(java.math.BigInteger.class, new java.math.BigInteger("-922337203685478000"));
values.put(java.math.BigDecimal.class, new java.math.BigDecimal("-999999.999999999"));
return values;
}
/**
* Append the receiver's field 'NOT NULL' constraint clause to a writer.
*/
public void printFieldNotNullClause(Writer writer) {
// Do nothing
}
/**
* JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
*/
public boolean shouldUseJDBCOuterJoinSyntax() {
return false;
}
public boolean supportsForeignKeyConstraints() {
return false;
}
public boolean supportsPrimaryKeyConstraint() {
return false;
}
}
|