ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/mode/FunctionsMSSQLServer.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/mode/FunctionsMSSQLServer.java
Status
scanned
Type
file
Name
FunctionsMSSQLServer.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
5142 (5.0 KB)
MD5
b0c224385ed3cca33affd96b990715c0
SHA1
dc53ee1a7133c9119971a2a4907761c3f73b73d0
SHA256
f05f05346de3253de700d424c42baf17b0013d6df178984c6468a3111ca2d195
SHA512

      
    
SHA1_git
dc80d0c70dbaac06b017dff78668132e9dc0c088
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
FunctionsMSSQLServer.java | 5.0 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.mode; import java.util.HashMap; import org.h2.api.ErrorCode; import org.h2.engine.SessionLocal; import org.h2.expression.Expression; import org.h2.expression.TypedValueExpression; import org.h2.expression.function.CoalesceFunction; import org.h2.expression.function.CurrentDateTimeValueFunction; import org.h2.expression.function.RandFunction; import org.h2.expression.function.StringFunction; import org.h2.message.DbException; import org.h2.value.TypeInfo; import org.h2.value.Value; import org.h2.value.ValueBigint; import org.h2.value.ValueNull; /** * Functions for {@link org.h2.engine.Mode.ModeEnum#MSSQLServer} compatibility * mode. */ public final class FunctionsMSSQLServer extends ModeFunction { private static final HashMap<String, FunctionInfo> FUNCTIONS = new HashMap<>(); private static final int CHARINDEX = 4001; private static final int GETDATE = CHARINDEX + 1; private static final int ISNULL = GETDATE + 1; private static final int LEN = ISNULL + 1; private static final int NEWID = LEN + 1; private static final int NEWSEQUENTIALID = NEWID + 1; private static final int SCOPE_IDENTITY = NEWSEQUENTIALID + 1; private static final TypeInfo SCOPE_IDENTITY_TYPE = TypeInfo.getTypeInfo(Value.NUMERIC, 38, 0, null); static { FUNCTIONS.put("CHARINDEX", new FunctionInfo("CHARINDEX", CHARINDEX, VAR_ARGS, Value.INTEGER, true, true)); FUNCTIONS.put("GETDATE", new FunctionInfo("GETDATE", GETDATE, 0, Value.TIMESTAMP, false, true)); FUNCTIONS.put("LEN", new FunctionInfo("LEN", LEN, 1, Value.INTEGER, true, true)); FUNCTIONS.put("NEWID", new FunctionInfo("NEWID", NEWID, 0, Value.UUID, true, false)); FUNCTIONS.put("NEWSEQUENTIALID", new FunctionInfo("NEWSEQUENTIALID", NEWSEQUENTIALID, 0, Value.UUID, true, false)); FUNCTIONS.put("ISNULL", new FunctionInfo("ISNULL", ISNULL, 2, Value.NULL, false, true)); FUNCTIONS.put("SCOPE_IDENTITY", new FunctionInfo("SCOPE_IDENTITY", SCOPE_IDENTITY, 0, Value.NUMERIC, true, false)); } /** * Returns mode-specific function for a given name, or {@code null}. * * @param upperName * the upper-case name of a function * @return the function with specified name or {@code null} */ public static FunctionsMSSQLServer getFunction(String upperName) { FunctionInfo info = FUNCTIONS.get(upperName); if (info != null) { return new FunctionsMSSQLServer(info); } return null; } private FunctionsMSSQLServer(FunctionInfo info) { super(info); } @Override protected void checkParameterCount(int len) { int min, max; switch (info.type) { case CHARINDEX: min = 2; max = 3; break; default: throw DbException.getInternalError("type=" + info.type); } if (len < min || len > max) { throw DbException.get(ErrorCode.INVALID_PARAMETER_COUNT_2, info.name, min + ".." + max); } } @Override public Value getValue(SessionLocal session) { Value[] values = getArgumentsValues(session, args); if (values == null) { return ValueNull.INSTANCE; } Value v0 = getNullOrValue(session, args, values, 0); switch (info.type) { case LEN: { long len; if (v0.getValueType() == Value.CHAR) { String s = v0.getString(); int l = s.length(); while (l > 0 && s.charAt(l - 1) == ' ') { l--; } len = l; } else { len = v0.charLength(); } return ValueBigint.get(len); } case SCOPE_IDENTITY: return session.getLastIdentity().convertTo(type); default: throw DbException.getInternalError("type=" + info.type); } } @Override public Expression optimize(SessionLocal session) { switch (info.type) { case CHARINDEX: return new StringFunction(args, StringFunction.LOCATE).optimize(session); case GETDATE: return new CurrentDateTimeValueFunction(CurrentDateTimeValueFunction.LOCALTIMESTAMP, 3).optimize(session); case ISNULL: return new CoalesceFunction(CoalesceFunction.COALESCE, args).optimize(session); case NEWID: case NEWSEQUENTIALID: return new RandFunction(null, RandFunction.RANDOM_UUID).optimize(session); case SCOPE_IDENTITY: type = SCOPE_IDENTITY_TYPE; break; default: type = TypeInfo.getTypeInfo(info.returnDataType); if (optimizeArguments(session)) { return TypedValueExpression.getTypedIfNull(getValue(session), type); } } return this; } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
2.14
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220