3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.client
;
21 import java
.io
.IOException
;
24 import org
.apache
.hadoop
.hbase
.classification
.InterfaceAudience
;
25 import org
.apache
.hadoop
.hbase
.util
.JsonMapper
;
28 * Superclass for any type that maps to a potentially application-level query.
29 * (e.g. Put, Get, Delete, Scan, Next, etc.)
30 * Contains methods for exposure to logging and debugging tools.
32 @InterfaceAudience.Public
33 public abstract class Operation
{
34 // TODO make this configurable
35 // TODO Do we need this anymore now we have protobuffed it all?
36 private static final int DEFAULT_MAX_COLS
= 5;
39 * Produces a Map containing a fingerprint which identifies the type and
40 * the static schema components of a query (i.e. column families)
41 * @return a map containing fingerprint information (i.e. column families)
43 public abstract Map
<String
, Object
> getFingerprint();
46 * Produces a Map containing a summary of the details of a query
47 * beyond the scope of the fingerprint (i.e. columns, rows...)
48 * @param maxCols a limit on the number of columns output prior to truncation
49 * @return a map containing parameters of a query (i.e. rows, columns...)
51 public abstract Map
<String
, Object
> toMap(int maxCols
);
54 * Produces a Map containing a full summary of a query.
55 * @return a map containing parameters of a query (i.e. rows, columns...)
57 public Map
<String
, Object
> toMap() {
58 return toMap(DEFAULT_MAX_COLS
);
62 * Produces a JSON object for fingerprint and details exposure in a
64 * @param maxCols a limit on the number of columns to include in the JSON
65 * @return a JSONObject containing this Operation's information, as a string
67 public String
toJSON(int maxCols
) throws IOException
{
68 return JsonMapper
.writeMapAsString(toMap(maxCols
));
72 * Produces a JSON object sufficient for description of a query
73 * in a debugging or logging context.
74 * @return the produced JSON object, as a string
76 public String
toJSON() throws IOException
{
77 return toJSON(DEFAULT_MAX_COLS
);
81 * Produces a string representation of this Operation. It defaults to a JSON
82 * representation, but falls back to a string representation of the
83 * fingerprint and details in the case of a JSON encoding failure.
84 * @param maxCols a limit on the number of columns output in the summary
86 * @return a JSON-parseable String
88 public String
toString(int maxCols
) {
89 /* for now this is merely a wrapper from producing a JSON string, but
90 * toJSON is kept separate in case this is changed to be a less parsable
91 * pretty printed representation.
94 return toJSON(maxCols
);
95 } catch (IOException ioe
) {
96 return toMap(maxCols
).toString();
101 * Produces a string representation of this Operation. It defaults to a JSON
102 * representation, but falls back to a string representation of the
103 * fingerprint and details in the case of a JSON encoding failure.
107 public String
toString() {
108 return toString(DEFAULT_MAX_COLS
);