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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008 Markus KARG(markus-karg@users.sourceforge.net).
*
* 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:
// Markus Karg and Oracle - initial API and implementation from Oracle TopLink and TopLink Essentials
// 05/16/2008-1.0 Markus Karg
// - 237843: CONCAT must be translated into || instead of +
// 02/23/2015-2.6 Dalia Abo Sheasha
// - 460607: Change DatabasePlatform StoredProcedureTerminationToken to be configurable
package org.eclipse.persistence.platform.database;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Hashtable;
import org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.expressions.ExpressionOperator;
import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.queries.ValueReadQuery;
/**
* Provides SQL Anywhere specific behaviour.
*
* @author Markus KARG (markus-karg@users.sourceforge.net)
*/
public class SQLAnywherePlatform extends SybasePlatform {
public SQLAnywherePlatform() {
super();
this.storedProcedureTerminationToken = ";";
}
// TODO: can't use these field types: none of them has sizes.
// That results is using defaults, that seem to be 9 for VARCHAR
// and neither FeatureTestModel nor AggregateTestModel would setup because of that.
// Untill this is fixed have to use the field types inherited from SybasePlatform.
/* protected Hashtable buildFieldTypes() {
Hashtable<Class, FieldTypeDefinition> fieldTypeMapping = new Hashtable<Class, FieldTypeDefinition>();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("BIT", false));
fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("INTEGER", false));
fieldTypeMapping.put(Long.class, new FieldTypeDefinition("BIGINT", false));
fieldTypeMapping.put(Float.class, new FieldTypeDefinition("REAL", false));
fieldTypeMapping.put(Double.class, new FieldTypeDefinition("DOUBLE", false));
fieldTypeMapping.put(Short.class, new FieldTypeDefinition("SMALLINT", false));
fieldTypeMapping.put(Byte.class, new FieldTypeDefinition("SMALLINT", false));
fieldTypeMapping.put(BigInteger.class, new FieldTypeDefinition("BIGINT", false));
fieldTypeMapping.put(BigDecimal.class, new FieldTypeDefinition("DOUBLE", false));
fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DOUBLE", false));
fieldTypeMapping.put(String.class, new FieldTypeDefinition("VARCHAR"));
fieldTypeMapping.put(Character.class, new FieldTypeDefinition("CHAR"));
fieldTypeMapping.put(Byte[].class, new FieldTypeDefinition("LONG BINARY", false));
fieldTypeMapping.put(Character[].class, new FieldTypeDefinition("LONG VARCHAR", false));
fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("LONG BINARY", false));
fieldTypeMapping.put(char[].class, new FieldTypeDefinition("LONG VARCHAR", false));
fieldTypeMapping.put(Blob.class, new FieldTypeDefinition("LONG BINARY", false));
fieldTypeMapping.put(Clob.class, new FieldTypeDefinition("LONG VARCHAR", false));
fieldTypeMapping.put(Date.class, new FieldTypeDefinition("DATE", false));
fieldTypeMapping.put(Time.class, new FieldTypeDefinition("TIME", false));
fieldTypeMapping.put(Timestamp.class, new FieldTypeDefinition("TIMESTAMP", false));
return fieldTypeMapping;
}*/
@Override
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping = super.buildFieldTypes();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("BIT", false));
return fieldTypeMapping;
}
/**
* INTERNAL:
* Build the identity query for native sequencing.
*/
@Override
public ValueReadQuery buildSelectQueryForIdentity() {
ValueReadQuery selectQuery = new ValueReadQuery();
StringWriter writer = new StringWriter();
writer.write("SELECT @@IDENTITY");
selectQuery.setSQLString(writer.toString());
return selectQuery;
}
public static ExpressionOperator createCurrentDateOperator() {
return ExpressionOperator.simpleFunctionNoParentheses(ExpressionOperator.CurrentDate, "CURRENT DATE");
}
public static ExpressionOperator createCurrentTimeOperator() {
return ExpressionOperator.simpleFunctionNoParentheses(ExpressionOperator.CurrentTime, "CURRENT TIME");
}
public static ExpressionOperator createLocate2Operator() {
return ExpressionOperator.simpleThreeArgumentFunction(ExpressionOperator.Locate2, "LOCATE");
}
public static ExpressionOperator createConcatOperator() {
return ExpressionOperator.simpleLogicalNoParens(ExpressionOperator.Concat, "||");
}
public static ExpressionOperator createLocateOperator() {
return ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Locate, "LOCATE");
}
@Override
protected String getCreateTempTableSqlPrefix() {
return "DECLARE LOCAL TEMPORARY TABLE ";
}
/**
* Used for stored procedure creation: Prefix for INPUT parameters.
* Not required on most platforms.
*/
@Override
public String getInputProcedureToken() {
return "IN";
}
@Override
public String getInOutputProcedureToken() {
return "";
}
/* This method is used to print the output parameter token when stored
* procedures is created
*/
@Override
public String getCreationOutputProcedureToken() {
return "OUT";
}
/* This method is used to print the output parameter token when stored
* procedures are called
*/
@Override
public String getOutputProcedureToken() {
return "";
}
@Override
public int getMaxFieldNameSize() {
return 128;
}
/**
* Used for sp defs.
*/
@Override
public String getProcedureArgumentString() {
return "";
}
@Override
public String getStoredProcedureParameterPrefix() {
return "";
}
@Override
public String getProcedureAsString() {
return "";
}
@Override
public String getProcedureBeginString() {
return "BEGIN";
}
@Override
public String getProcedureEndString() {
return "END";
}
/**
* Used for batch writing and sp defs.
*/
@Override
public String getBatchBeginString() {
return "BEGIN ";
}
/**
* Used for batch writing and sp defs.
*/
@Override
public String getBatchEndString() {
return "END;";
}
/**
* Used for batch writing and sp defs.
*/
@Override
public String getBatchDelimiterString() {
return "; ";
}
/**
* Used for sp calls.
*/
@Override
public String getProcedureCallHeader() {
return "CALL ";
}
/**
* Used for sp calls.
*/
@Override
public DatabaseTable getTempTableForTable(DatabaseTable table) {
return new DatabaseTable("$" + table.getName(), table.getTableQualifier(), table.shouldUseDelimiters(), getStartDelimiter(), getEndDelimiter());
}
@Override
protected void initializePlatformOperators() {
super.initializePlatformOperators();
this.addOperator(createConcatOperator());
this.addOperator(createLocateOperator());
this.addOperator(createLocate2Operator());
// this.addOperator(createCurrentDateOperator());
// this.addOperator(createCurrentTimeOperator());
this.addOperator(ExpressionOperator.charLength());
this.addOperator(ExpressionOperator.mod());
}
@Override
public boolean isSQLAnywhere() {
return true;
}
@Override
public boolean isSybase() {
return false;
}
@Override
public boolean requiresProcedureBrackets() {
return true;
}
@Override
public boolean requiresProcedureCallBrackets() {
return true;
}
/**
* INTERNAL:
* Indicates whether the version of CallableStatement.registerOutputParameter method
* that takes type name should be used.
*/
@Override
public boolean requiresTypeNameToRegisterOutputParameter() {
return false;
}
@Override
public void printFieldIdentityClause(Writer writer) throws ValidationException {
try {
writer.write(" DEFAULT AUTOINCREMENT");
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
}
@Override
public void printFieldNullClause(Writer writer) throws ValidationException {
try {
writer.write(" NULL");
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
}
@Override
public boolean shouldPrintInputTokenAtStart() {
return true;
}
@Override
public boolean shouldPrintInOutputTokenBeforeType() {
return false;
}
@Override
public boolean shouldPrintOutputTokenAtStart() {
return true;
}
@Override
public boolean shouldPrintOutputTokenBeforeType() {
return false;
}
//**temp
@Override
public boolean shouldPrintStoredProcedureArgumentNameInCall() {
return false;
}
@Override
public boolean shouldPrintStoredProcedureVariablesAfterBeginString() {
return true;
}
@Override
public boolean supportsIdentity() {
return true;
}
@Override
public boolean supportsLocalTempTables() {
return true;
}
@Override
public boolean supportsStoredFunctions() {
return true;
}
/**
* SQL Anywhere does support cascade on delete, unlike Sybase.
*/
@Override
public boolean supportsDeleteOnCascade() {
return true;
}
}
|