HBASE-24456 : Create ImmutableScan and use it for CustomizedScanInfoBuilder (#1818)
[hbase.git] / hbase-server / src / main / java / org / apache / hadoop / hbase / regionserver / CustomizedScanInfoBuilder.java
blobac9980b01a01b3c07e984d2db15e7dcd32a9b010
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import java.io.IOException;
21 import org.apache.hadoop.hbase.KeepDeletedCells;
22 import org.apache.hadoop.hbase.client.ImmutableScan;
23 import org.apache.hadoop.hbase.client.Scan;
24 import org.apache.yetus.audience.InterfaceAudience;
26 /**
27 * Helper class for CP hooks to change max versions and TTL.
29 @InterfaceAudience.Private
30 public class CustomizedScanInfoBuilder implements ScanOptions {
32 private final ScanInfo scanInfo;
34 private Integer maxVersions;
36 private Long ttl;
38 private KeepDeletedCells keepDeletedCells = null;
40 private Integer minVersions;
42 private final Scan scan;
44 public CustomizedScanInfoBuilder(ScanInfo scanInfo) {
45 this.scanInfo = scanInfo;
46 this.scan = new ImmutableScan(new Scan());
49 public CustomizedScanInfoBuilder(ScanInfo scanInfo, Scan scan) {
50 this.scanInfo = scanInfo;
51 //copy the scan so no coproc using this ScanOptions can alter the "real" scan
52 this.scan = new ImmutableScan(scan);
55 @Override
56 public int getMaxVersions() {
57 return maxVersions != null ? maxVersions.intValue() : scanInfo.getMaxVersions();
60 @Override
61 public void setMaxVersions(int maxVersions) {
62 this.maxVersions = maxVersions;
65 @Override
66 public long getTTL() {
67 return ttl != null ? ttl.longValue() : scanInfo.getTtl();
70 @Override
71 public void setTTL(long ttl) {
72 this.ttl = ttl;
75 public ScanInfo build() {
76 if (maxVersions == null && ttl == null && keepDeletedCells == null) {
77 return scanInfo;
79 return scanInfo.customize(getMaxVersions(), getTTL(), getKeepDeletedCells(), getMinVersions());
82 @Override
83 public String toString() {
84 return "ScanOptions [maxVersions=" + getMaxVersions() + ", TTL=" + getTTL() +
85 ", KeepDeletedCells=" + getKeepDeletedCells() + ", MinVersions=" + getMinVersions() + "]";
88 @Override
89 public void setKeepDeletedCells(KeepDeletedCells keepDeletedCells) {
90 this.keepDeletedCells = keepDeletedCells;
93 @Override
94 public KeepDeletedCells getKeepDeletedCells() {
95 return keepDeletedCells != null ? keepDeletedCells : scanInfo.getKeepDeletedCells();
98 @Override
99 public int getMinVersions() {
100 return minVersions != null ? minVersions : scanInfo.getMinVersions();
103 @Override
104 public void setMinVersions(int minVersions) {
105 this.minVersions = minVersions;
108 @Override
109 public Scan getScan() {
110 return scan;