1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: StatsConfig.java,v 12.7 2008/01/17 05:04:53 mjc Exp $ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbConstants; 12 13/** 14Specifies the attributes of a statistics retrieval operation. 15*/ 16public class StatsConfig { 17 /* 18 * For internal use, to allow null as a valid value for 19 * the config parameter. 20 */ 21 public static final StatsConfig DEFAULT = new StatsConfig(); 22 23 /* package */ 24 static StatsConfig checkNull(StatsConfig config) { 25 return (config == null) ? DEFAULT : config; 26 } 27 28 private boolean clear = false; 29 private boolean fast = false; 30 31 /** 32 An instance created using the default constructor is initialized 33 with the system's default settings. 34 */ 35 public StatsConfig() { 36 } 37 38 /** 39 Configure the statistics operation to reset statistics after they 40 are returned. The default value is false. 41 <p> 42 @param clear 43 If set to true, configure the statistics operation to reset 44 statistics after they are returned. 45 */ 46 public void setClear(boolean clear) { 47 this.clear = clear; 48 } 49 50 /** 51 Return if the statistics operation is configured to reset 52 statistics after they are returned. 53 <p> 54 @return 55 If the statistics operation is configured to reset statistics after 56 they are returned. 57 */ 58 public boolean getClear() { 59 return clear; 60 } 61 62 /** 63 Configure the statistics operation to return only the values which 64 do not incur some performance penalty. 65 <p> 66 The default value is false. 67 <p> 68 For example, skip stats that require a traversal of the database or 69 in-memory tree, or which lock down the lock table for a period of 70 time. 71 <p> 72 Among other things, this flag makes it possible for applications to 73 request key and record counts without incurring the performance 74 penalty of traversing the entire database. If the underlying 75 database is of type Recno, or of type Btree and the database was 76 configured to support retrieval by record number, the count of keys 77 will be exact. Otherwise, the count of keys will be the value saved 78 the last time the database was traversed, or 0 if no count of keys 79 has ever been made. If the underlying database is of type Recno, 80 the count of data items will be exact, otherwise, the count of data 81 items will be the value saved the last time the database was 82 traversed, or 0 if no count of data items has ever been done. 83 <p> 84 @param fast 85 If set to true, configure the statistics operation to return only 86 the values which do not incur some performance penalty. 87 */ 88 public void setFast(boolean fast) { 89 this.fast = fast; 90 } 91 92 /** 93 Return if the statistics operation is configured to return only the 94 values which do not require expensive actions. 95 <p> 96 @return 97 If the statistics operation is configured to return only the values 98 which do not require expensive actions. 99 */ 100 public boolean getFast() { 101 return fast; 102 } 103 104 int getFlags() { 105 int flags = 0; 106 if (fast) 107 flags |= DbConstants.DB_FAST_STAT; 108 if (clear) 109 flags |= DbConstants.DB_STAT_CLEAR; 110 return flags; 111 } 112} 113