ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/schema/UserAggregate.java

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

      
    
Rootfs path

      
    
Size
3528 (3.4 KB)
MD5
169d0da063da7a6dc60c9a1b1b45f1ee
SHA1
6db4e04f57d312a690aed9335e2c545351189390
SHA256
dcdfc41adc1122094a2eefe184f8ab3814eb8d7330aec93943c5aa2530af8f88
SHA512

      
    
SHA1_git
da3d958113b2e9d5a560142b128ca351428df927
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
UserAggregate.java | 3.4 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.schema; import java.sql.Connection; import java.sql.SQLException; import org.h2.api.Aggregate; import org.h2.api.AggregateFunction; import org.h2.engine.DbObject; import org.h2.engine.SessionLocal; import org.h2.message.DbException; import org.h2.message.Trace; import org.h2.util.JdbcUtils; import org.h2.util.StringUtils; import org.h2.value.DataType; import org.h2.value.TypeInfo; /** * Represents a user-defined aggregate function. */ public final class UserAggregate extends UserDefinedFunction { private Class<?> javaClass; public UserAggregate(Schema schema, int id, String name, String className, boolean force) { super(schema, id, name, Trace.FUNCTION); this.className = className; if (!force) { getInstance(); } } public Aggregate getInstance() { if (javaClass == null) { javaClass = JdbcUtils.loadUserClass(className); } Object obj; try { obj = javaClass.getDeclaredConstructor().newInstance(); Aggregate agg; if (obj instanceof Aggregate) { agg = (Aggregate) obj; } else { agg = new AggregateWrapper((AggregateFunction) obj); } return agg; } catch (Exception e) { throw DbException.convert(e); } } @Override public String getDropSQL() { StringBuilder builder = new StringBuilder("DROP AGGREGATE IF EXISTS "); return getSQL(builder, DEFAULT_SQL_FLAGS).toString(); } @Override public String getCreateSQL() { StringBuilder builder = new StringBuilder("CREATE FORCE AGGREGATE "); getSQL(builder, DEFAULT_SQL_FLAGS).append(" FOR "); return StringUtils.quoteStringSQL(builder, className).toString(); } @Override public int getType() { return DbObject.AGGREGATE; } @Override public synchronized void removeChildrenAndResources(SessionLocal session) { database.removeMeta(session, getId()); className = null; javaClass = null; invalidate(); } /** * Wrap {@link AggregateFunction} in order to behave as * {@link org.h2.api.Aggregate} **/ private static class AggregateWrapper implements Aggregate { private final AggregateFunction aggregateFunction; AggregateWrapper(AggregateFunction aggregateFunction) { this.aggregateFunction = aggregateFunction; } @Override public void init(Connection conn) throws SQLException { aggregateFunction.init(conn); } @Override public int getInternalType(int[] inputTypes) throws SQLException { int[] sqlTypes = new int[inputTypes.length]; for (int i = 0; i < inputTypes.length; i++) { sqlTypes[i] = DataType.convertTypeToSQLType(TypeInfo.getTypeInfo(inputTypes[i])); } return DataType.convertSQLTypeToValueType(aggregateFunction.getType(sqlTypes)); } @Override public void add(Object value) throws SQLException { aggregateFunction.add(value); } @Override public Object getResult() throws SQLException { return aggregateFunction.getResult(); } } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
2.88
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 detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
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