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

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

      
    
Rootfs path

      
    
Size
4919 (4.8 KB)
MD5
596aa80e7f5e7d53a2b24ce62be646be
SHA1
a989d1410803125bf5d548074c10089692774a05
SHA256
e1cd8cdb43e694dced2ddb64b1c528d636d991343a92ad028cafb942d6488b6a
SHA512

      
    
SHA1_git
fbb51998b57d428fcf54132b888cbf557e07de0d
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ConstraintUnique.java | 4.8 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.ArrayList; import java.util.HashSet; import org.h2.engine.SessionLocal; import org.h2.engine.NullsDistinct; import org.h2.index.Index; import org.h2.result.Row; import org.h2.schema.Schema; import org.h2.table.Column; import org.h2.table.IndexColumn; import org.h2.table.Table; import org.h2.util.StringUtils; /** * A unique constraint. This object always backed by a unique index. */ public class ConstraintUnique extends Constraint { private Index index; private boolean indexOwner; private IndexColumn[] columns; private final boolean primaryKey; private NullsDistinct nullsDistinct; public ConstraintUnique(Schema schema, int id, String name, Table table, boolean primaryKey, NullsDistinct nullsDistinct) { super(schema, id, name, table); this.primaryKey = primaryKey; this.nullsDistinct = nullsDistinct; } @Override public Type getConstraintType() { return primaryKey ? Constraint.Type.PRIMARY_KEY : Constraint.Type.UNIQUE; } @Override public String getCreateSQLForCopy(Table forTable, String quotedName) { return getCreateSQLForCopy(forTable, quotedName, true); } private String getCreateSQLForCopy(Table forTable, String quotedName, boolean internalIndex) { StringBuilder builder = new StringBuilder("ALTER TABLE "); forTable.getSQL(builder, DEFAULT_SQL_FLAGS).append(" ADD CONSTRAINT "); if (forTable.isHidden()) { builder.append("IF NOT EXISTS "); } builder.append(quotedName); if (comment != null) { builder.append(" COMMENT "); StringUtils.quoteStringSQL(builder, comment); } builder.append(' ').append(getConstraintType().getSqlName()).append('('); IndexColumn.writeColumns(builder, columns, DEFAULT_SQL_FLAGS).append(')'); if (internalIndex && indexOwner && forTable == this.table) { builder.append(" INDEX "); index.getSQL(builder, DEFAULT_SQL_FLAGS); } return builder.toString(); } @Override public String getCreateSQLWithoutIndexes() { return getCreateSQLForCopy(table, getSQL(DEFAULT_SQL_FLAGS), false); } @Override public String getCreateSQL() { return getCreateSQLForCopy(table, getSQL(DEFAULT_SQL_FLAGS)); } public void setColumns(IndexColumn[] columns) { this.columns = columns; } public IndexColumn[] getColumns() { return columns; } /** * Set the index to use for this unique constraint. * * @param index the index * @param isOwner true if the index is generated by the system and belongs * to this constraint */ public void setIndex(Index index, boolean isOwner) { this.index = index; this.indexOwner = isOwner; } @Override public void removeChildrenAndResources(SessionLocal session) { ArrayList<Constraint> constraints = table.getConstraints(); if (constraints != null) { constraints = new ArrayList<>(table.getConstraints()); for (Constraint c : constraints) { if (c.getReferencedConstraint() == this) { database.removeSchemaObject(session, c); } } } table.removeConstraint(this); if (indexOwner) { table.removeIndexOrTransferOwnership(session, index); } database.removeMeta(session, getId()); index = null; columns = null; table = null; invalidate(); } @Override public void checkRow(SessionLocal session, Table t, Row oldRow, Row newRow) { // unique index check is enough } @Override public boolean usesIndex(Index idx) { return idx == index; } @Override public void setIndexOwner(Index index) { indexOwner = true; } @Override public HashSet<Column> getReferencedColumns(Table table) { HashSet<Column> result = new HashSet<>(); for (IndexColumn c : columns) { result.add(c.column); } return result; } @Override public boolean isBefore() { return true; } @Override public void checkExistingData(SessionLocal session) { // no need to check: when creating the unique index any problems are // found } @Override public Index getIndex() { return index; } @Override public void rebuild() { // nothing to do } /** * @return are nulls distinct */ public NullsDistinct getNullsDistinct() { return nullsDistinct; } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
2.39
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