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 java.io.IOException; 021import org.apache.hadoop.hbase.KeepDeletedCells; 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 final Scan scan; 042 043 public CustomizedScanInfoBuilder(ScanInfo scanInfo) { 044 this.scanInfo = scanInfo; 045 this.scan = new Scan(); 046 } 047 public CustomizedScanInfoBuilder(ScanInfo scanInfo, Scan scan) { 048 this.scanInfo = scanInfo; 049 //copy the scan so no coproc using this ScanOptions can alter the "real" scan 050 try { 051 this.scan = new Scan(scan); 052 } catch (IOException e) { 053 throw new AssertionError("Scan should not throw IOException", e); 054 } 055 } 056 057 @Override 058 public int getMaxVersions() { 059 return maxVersions != null ? maxVersions.intValue() : scanInfo.getMaxVersions(); 060 } 061 062 @Override 063 public void setMaxVersions(int maxVersions) { 064 this.maxVersions = maxVersions; 065 } 066 067 @Override 068 public long getTTL() { 069 return ttl != null ? ttl.longValue() : scanInfo.getTtl(); 070 } 071 072 @Override 073 public void setTTL(long ttl) { 074 this.ttl = ttl; 075 } 076 077 public ScanInfo build() { 078 if (maxVersions == null && ttl == null && keepDeletedCells == null) { 079 return scanInfo; 080 } 081 return scanInfo.customize(getMaxVersions(), getTTL(), getKeepDeletedCells(), getMinVersions()); 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 Scan getScan() { 112 try { 113 return new Scan(scan); 114 } catch(IOException e) { 115 throw new AssertionError("Scan should not throw IOException anymore", e); 116 } 117 } 118 119}