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.hadoop.hbase.client.ImmutableScan; 022import org.apache.hadoop.hbase.client.Scan; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * Helper class for CP hooks to change max versions and TTL. 027 */ 028@InterfaceAudience.Private 029public class CustomizedScanInfoBuilder implements ScanOptions { 030 031 private final ScanInfo scanInfo; 032 033 private Integer maxVersions; 034 035 private Long ttl; 036 037 private KeepDeletedCells keepDeletedCells = null; 038 039 private Integer minVersions; 040 041 private long timeToPurgeDeletes; 042 043 private final Scan scan; 044 045 public CustomizedScanInfoBuilder(ScanInfo scanInfo) { 046 this.scanInfo = scanInfo; 047 this.scan = new ImmutableScan(new Scan()); 048 } 049 050 public CustomizedScanInfoBuilder(ScanInfo scanInfo, Scan scan) { 051 this.scanInfo = scanInfo; 052 // copy the scan so no coproc using this ScanOptions can alter the "real" scan 053 this.scan = new ImmutableScan(scan); 054 } 055 056 @Override 057 public int getMaxVersions() { 058 return maxVersions != null ? maxVersions.intValue() : scanInfo.getMaxVersions(); 059 } 060 061 @Override 062 public void setMaxVersions(int maxVersions) { 063 this.maxVersions = maxVersions; 064 } 065 066 @Override 067 public long getTTL() { 068 return ttl != null ? ttl.longValue() : scanInfo.getTtl(); 069 } 070 071 @Override 072 public void setTTL(long ttl) { 073 this.ttl = ttl; 074 } 075 076 public ScanInfo build() { 077 if (maxVersions == null && ttl == null && keepDeletedCells == null) { 078 return scanInfo; 079 } 080 return scanInfo.customize(getMaxVersions(), getTTL(), getKeepDeletedCells(), getMinVersions(), 081 getTimeToPurgeDeletes()); 082 } 083 084 @Override 085 public String toString() { 086 return "ScanOptions [maxVersions=" + getMaxVersions() + ", TTL=" + getTTL() 087 + ", KeepDeletedCells=" + getKeepDeletedCells() + ", MinVersions=" + getMinVersions() + "]"; 088 } 089 090 @Override 091 public void setKeepDeletedCells(KeepDeletedCells keepDeletedCells) { 092 this.keepDeletedCells = keepDeletedCells; 093 } 094 095 @Override 096 public KeepDeletedCells getKeepDeletedCells() { 097 return keepDeletedCells != null ? keepDeletedCells : scanInfo.getKeepDeletedCells(); 098 } 099 100 @Override 101 public int getMinVersions() { 102 return minVersions != null ? minVersions : scanInfo.getMinVersions(); 103 } 104 105 @Override 106 public void setMinVersions(int minVersions) { 107 this.minVersions = minVersions; 108 } 109 110 @Override 111 public long getTimeToPurgeDeletes() { 112 return timeToPurgeDeletes; 113 } 114 115 @Override 116 public void setTimeToPurgeDeletes(long ttl) { 117 this.timeToPurgeDeletes = ttl; 118 } 119 120 @Override 121 public Scan getScan() { 122 return scan; 123 } 124 125}