com.facebook.presto.jdbc.internal.spi.constraints.UniqueConstraint Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.jdbc.internal.spi.constraints;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonCreator;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonProperty;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class UniqueConstraint
extends TableConstraint
{
public UniqueConstraint(Set columnNames, boolean enabled, boolean rely)
{
this(Optional.empty(), columnNames, enabled, rely);
}
@JsonCreator
public UniqueConstraint(
@JsonProperty("name") String name,
@JsonProperty("columns") Set columnNames,
@JsonProperty("enforced") boolean enabled,
@JsonProperty("rely") boolean rely)
{
super(Optional.of(name), columnNames, enabled, rely);
}
protected UniqueConstraint(Optional name, Set columnNames, boolean enabled, boolean rely)
{
super(name, columnNames, enabled, rely);
}
@Override
public Optional> rebaseConstraint(Map assignments)
{
if (this.getColumns().stream().allMatch(assignments::containsKey)) {
return Optional.of(new UniqueConstraint(getName(),
this.getColumns().stream().map(assignments::get).collect(Collectors.toSet()),
this.isEnforced(),
this.isRely()));
}
else {
return Optional.empty();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy