001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver;
019
020import org.apache.hadoop.hbase.KeepDeletedCells;
021import org.apache.yetus.audience.InterfaceAudience;
022
023/**
024 * Helper class for CP hooks to change max versions and TTL.
025 */
026@InterfaceAudience.Private
027public class CustomizedScanInfoBuilder implements ScanOptions {
028
029  private final ScanInfo scanInfo;
030
031  private Integer maxVersions;
032
033  private Long ttl;
034
035  private KeepDeletedCells keepDeletedCells = null;
036
037  public CustomizedScanInfoBuilder(ScanInfo scanInfo) {
038    this.scanInfo = scanInfo;
039  }
040
041  @Override
042  public int getMaxVersions() {
043    return maxVersions != null ? maxVersions.intValue() : scanInfo.getMaxVersions();
044  }
045
046  @Override
047  public void setMaxVersions(int maxVersions) {
048    this.maxVersions = maxVersions;
049  }
050
051  @Override
052  public long getTTL() {
053    return ttl != null ? ttl.longValue() : scanInfo.getTtl();
054  }
055
056  @Override
057  public void setTTL(long ttl) {
058    this.ttl = ttl;
059  }
060
061  public ScanInfo build() {
062    if (maxVersions == null && ttl == null && keepDeletedCells == null) {
063      return scanInfo;
064    }
065    return scanInfo.customize(getMaxVersions(), getTTL(), getKeepDeletedCells());
066  }
067
068  @Override
069  public String toString() {
070    return "ScanOptions [maxVersions=" + getMaxVersions() + ", TTL=" + getTTL() + "]";
071  }
072
073  @Override
074  public void setKeepDeletedCells(KeepDeletedCells keepDeletedCells) {
075    this.keepDeletedCells = keepDeletedCells;
076  }
077
078  @Override
079  public KeepDeletedCells getKeepDeletedCells() {
080    return keepDeletedCells != null ? keepDeletedCells : scanInfo.getKeepDeletedCells();
081  }
082
083}