ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/constraint/ConstraintDomain.java

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

      
    
Rootfs path

      
    
Size
6614 (6.5 KB)
MD5
00224c65cca649adf42db9abdc007bda
SHA1
8d4e01e2a2b6ef4e3c3665d64d411466019fba6c
SHA256
b6e8bf55ba0504bbd1368b1d8e70dd9f5ee8846a04a70ea1aee381153d3b5974
SHA512

      
    
SHA1_git
a6eedc1be95ef3e50d4230c270216a8fed75aa2b
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ConstraintDomain.java | 6.5 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.constraint; import java.util.HashSet; import org.h2.api.ErrorCode; import org.h2.command.Parser; import org.h2.command.ddl.AlterDomain; import org.h2.command.query.AllColumnsForPlan; import org.h2.engine.SessionLocal; import org.h2.expression.Expression; import org.h2.expression.ExpressionVisitor; import org.h2.index.Index; import org.h2.message.DbException; import org.h2.result.Row; import org.h2.schema.Domain; import org.h2.schema.Schema; import org.h2.table.Column; import org.h2.table.PlanItem; import org.h2.table.Table; import org.h2.table.TableFilter; import org.h2.util.StringUtils; import org.h2.value.Value; import org.h2.value.ValueNull; /** * A domain constraint. */ public class ConstraintDomain extends Constraint { private Domain domain; private Expression expr; private DomainColumnResolver resolver; public ConstraintDomain(Schema schema, int id, String name, Domain domain) { super(schema, id, name, null); this.domain = domain; resolver = new DomainColumnResolver(domain.getDataType()); } @Override public Type getConstraintType() { return Constraint.Type.DOMAIN; } /** * Returns the domain of this constraint. * * @return the domain */ public Domain getDomain() { return domain; } /** * Set the expression. * * @param session the session * @param expr the expression */ public void setExpression(SessionLocal session, Expression expr) { expr.mapColumns(resolver, 0, Expression.MAP_INITIAL); expr = expr.optimize(session); // check if the column is mapped synchronized (this) { resolver.setValue(ValueNull.INSTANCE); expr.getValue(session); } this.expr = expr; } @Override public String getCreateSQLWithoutIndexes() { return getCreateSQL(); } @Override public String getCreateSQL() { StringBuilder builder = new StringBuilder("ALTER DOMAIN "); domain.getSQL(builder, DEFAULT_SQL_FLAGS).append(" ADD CONSTRAINT "); getSQL(builder, DEFAULT_SQL_FLAGS); if (comment != null) { builder.append(" COMMENT "); StringUtils.quoteStringSQL(builder, comment); } builder.append(" CHECK"); expr.getEnclosedSQL(builder, DEFAULT_SQL_FLAGS).append(" NOCHECK"); return builder.toString(); } @Override public void removeChildrenAndResources(SessionLocal session) { domain.removeConstraint(this); database.removeMeta(session, getId()); domain = null; expr = null; invalidate(); } @Override public void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow) { throw DbException.getInternalError(toString()); } /** * Check the specified value. * * @param session * the session * @param value * the value to check */ public void check(SessionLocal session, Value value) { Value v; synchronized (this) { resolver.setValue(value); v = expr.getValue(session); } // Both TRUE and NULL are OK if (v.isFalse()) { throw DbException.get(ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, expr.getTraceSQL()); } } /** * Get the check constraint expression for this column. * * @param session the session * @param columnName the column name * @return the expression */ public Expression getCheckConstraint(SessionLocal session, String columnName) { String sql; if (columnName != null) { synchronized (this) { try { resolver.setColumnName(columnName); sql = expr.getSQL(DEFAULT_SQL_FLAGS); } finally { resolver.resetColumnName(); } } return new Parser(session).parseExpression(sql); } else { synchronized (this) { sql = expr.getSQL(DEFAULT_SQL_FLAGS); } return new Parser(session).parseDomainConstraintExpression(sql); } } @Override public boolean usesIndex(Index index) { return false; } @Override public void setIndexOwner(Index index) { throw DbException.getInternalError(toString()); } @Override public HashSet<Column> getReferencedColumns(Table table) { HashSet<Column> columns = new HashSet<>(); expr.isEverything(ExpressionVisitor.getColumnsVisitor(columns, table)); return columns; } @Override public Expression getExpression() { return expr; } @Override public boolean isBefore() { return true; } @Override public void checkExistingData(SessionLocal session) { if (session.getDatabase().isStarting()) { // don't check at startup return; } new CheckExistingData(session, domain); } @Override public void rebuild() { // nothing to do } @Override public boolean isEverything(ExpressionVisitor visitor) { return expr.isEverything(visitor); } private class CheckExistingData { private final SessionLocal session; CheckExistingData(SessionLocal session, Domain domain) { this.session = session; checkDomain(null, domain); } private boolean checkColumn(Domain domain, Column targetColumn) { Table table = targetColumn.getTable(); TableFilter filter = new TableFilter(session, table, null, true, null, 0, null); TableFilter[] filters = { filter }; PlanItem item = filter.getBestPlanItem(session, filters, 0, new AllColumnsForPlan(filters)); filter.setPlanItem(item); filter.prepare(); filter.startQuery(session); filter.reset(); while (filter.next()) { check(session, filter.getValue(targetColumn)); } return false; } private boolean checkDomain(Domain domain, Domain targetDomain) { AlterDomain.forAllDependencies(session, targetDomain, this::checkColumn, this::checkDomain, false); return false; } } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
2.16
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'}
public-domain {'score': 70.0, 'matcher': '2-aho', 'end_line': 57, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/public-domain_bare_words.RULE', 'from_file': None, 'start_line': 57, 'matched_text': ' public Domain getDomain() {', 'match_coverage': 100.0, 'matched_length': 2, 'rule_relevance': 70, 'rule_identifier': 'public-domain_bare_words.RULE', 'license_expression': 'public-domain', 'license_expression_spdx': 'LicenseRef-scancode-public-domain'}
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