com.gemstone.gemfire.management.internal.cli.domain.DataCommandResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.management.internal.cli.domain;
import static com.gemstone.gemfire.management.internal.cli.multistep.CLIMultiStepHelper.createBannerResult;
import static com.gemstone.gemfire.management.internal.cli.multistep.CLIMultiStepHelper.createPageResult;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.internal.ClassPathLoader;
import com.gemstone.gemfire.management.cli.Result;
import com.gemstone.gemfire.management.internal.cli.GfshParser;
import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
import com.gemstone.gemfire.management.internal.cli.json.GfJsonArray;
import com.gemstone.gemfire.management.internal.cli.json.GfJsonException;
import com.gemstone.gemfire.management.internal.cli.json.GfJsonObject;
import com.gemstone.gemfire.management.internal.cli.result.CompositeResultData;
import com.gemstone.gemfire.management.internal.cli.result.CompositeResultData.SectionResultData;
import com.gemstone.gemfire.management.internal.cli.result.ResultBuilder;
import com.gemstone.gemfire.management.internal.cli.result.TabularResultData;
import com.gemstone.gemfire.management.internal.cli.util.JsonUtil;
/**
* Domain object used for Data Commands Functions
* @author tushark
*
* TODO : Implement DataSerializable
*
*/
public class DataCommandResult implements /*Data*/ Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String command;
private Object putResult;
private Object getResult;
private List selectResult;
private String queryTraceString;
public static final String QUERY_PAGE_START ="startCount";
public static final String QUERY_PAGE_END ="endCount";
public static final String QUERY_TRACE ="Query Trace";
public static final String RESULT_FLAG = "Result";
public static final String NUM_ROWS = "Rows";
//Aggreagated Data.
private List locateEntryLocations;
private KeyInfo locateEntryResult;
private boolean hasResultForAggregation;
private Object removeResult;
private Object inputKey;
private Object inputValue;
private Object inputQuery;
private Throwable error;
private String errorString;
private String infoString;
private String keyClass;
private String valueClass;
private int limit;
private boolean operationCompletedSuccessfully; //used for validation purposes.
public static final String NEW_LINE = GfshParser.LINE_SEPARATOR;
public String toString(){
StringBuilder sb = new StringBuilder();
if(isGet()){
sb.append(" Type : Get").append(NEW_LINE);
sb.append(" Key : ").append(inputKey).append(NEW_LINE);
if(getResult!=null)
sb.append(" ReturnValue Class : ").append(getResult.getClass()).append(NEW_LINE);
sb.append(" ReturnValue : ").append(getResult).append(NEW_LINE);
}else if(isPut()){
sb.append(" Type : Put");
sb.append(" Key : ").append(inputKey).append(NEW_LINE);
if(putResult!=null)
sb.append(" ReturnValue Class : ").append(putResult.getClass()).append(NEW_LINE);
sb.append(" ReturnValue : ").append(putResult).append(NEW_LINE);
sb.append(" Value : ").append(inputValue).append(NEW_LINE);
}else if(isRemove()){
sb.append(" Type : Remove");
sb.append(" Key : ").append(inputKey).append(NEW_LINE);
if(removeResult!=null)
sb.append(" ReturnValue Class : ").append(removeResult.getClass()).append(NEW_LINE);
sb.append(" ReturnValue : ").append(removeResult).append(NEW_LINE);
}else if(isLocateEntry()){
sb.append(" Type : Locate Entry" );
sb.append(" Key : ").append(inputKey).append(NEW_LINE);
//Assume here that this is aggregated result
sb.append(" Results : ").append(locateEntryResult).append(NEW_LINE);
sb.append(" Locations : ").append(locateEntryLocations).append(NEW_LINE);
}
if(errorString!=null)
sb.append(" ERROR ").append(errorString);
return sb.toString();
}
public boolean isGet(){
if(CliStrings.GET.equals(command))
return true;
else return false;
}
public boolean isPut(){
if(CliStrings.PUT.equals(command))
return true;
else return false;
}
public boolean isRemove(){
if(CliStrings.REMOVE.equals(command))
return true;
else return false;
}
public boolean isLocateEntry(){
if(CliStrings.LOCATE_ENTRY.equals(command))
return true;
else return false;
}
public boolean isSelect(){
if(CliStrings.QUERY.equals(command))
return true;
else return false;
}
public List getSelectResult() {
return selectResult;
}
public static DataCommandResult createGetResult(Object inputKey, Object value, Throwable error, String errorString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.GET;
result.inputKey = inputKey;
result.getResult = value;
result.error = error;
result.errorString = errorString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createGetInfoResult(Object inputKey, Object value, Throwable error, String infoString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.GET;
result.inputKey = inputKey;
result.getResult = value;
result.error = error;
result.infoString = infoString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createLocateEntryResult(Object inputKey, KeyInfo locationResult, Throwable error, String errorString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.LOCATE_ENTRY;
result.inputKey = inputKey;
if(flag){
result.hasResultForAggregation = true;
}
result.locateEntryResult = locationResult;
result.error = error;
result.errorString = errorString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createLocateEntryInfoResult(Object inputKey, KeyInfo locationResult, Throwable error, String infoString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.LOCATE_ENTRY;
result.inputKey = inputKey;
if(flag){
result.hasResultForAggregation = true;
}
result.locateEntryResult = locationResult;
result.error = error;
result.infoString = infoString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createPutResult(Object inputKey, Object value, Throwable error, String errorString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.PUT;
result.inputKey = inputKey;
result.putResult = value;
result.error = error;
result.errorString = errorString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createPutInfoResult(Object inputKey, Object value, Throwable error, String infoString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.PUT;
result.inputKey = inputKey;
result.putResult = value;
result.error = error;
result.infoString = infoString;
return result;
}
public static DataCommandResult createRemoveResult(Object inputKey, Object value, Throwable error, String errorString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.REMOVE;
result.inputKey = inputKey;
result.removeResult = value;
result.error = error;
result.errorString = errorString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createRemoveInfoResult(Object inputKey, Object value, Throwable error, String infoString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.REMOVE;
result.inputKey = inputKey;
result.removeResult = value;
result.error = error;
result.infoString = infoString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createSelectResult(Object inputQuery, List value,String queryTraceString, Throwable error, String errorString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.QUERY;
result.inputQuery = inputQuery;
//result.limit = limit;
result.queryTraceString = queryTraceString;
result.selectResult = value;
result.error = error;
result.errorString = errorString;
result.operationCompletedSuccessfully = flag;
return result;
}
public static DataCommandResult createSelectInfoResult(Object inputQuery, List value,int limit, Throwable error, String infoString, boolean flag){
DataCommandResult result = new DataCommandResult();
result.command = CliStrings.QUERY;
result.inputQuery = inputQuery;
result.limit = limit;
result.selectResult = value;
result.error = error;
result.infoString = infoString;
result.operationCompletedSuccessfully = flag;
return result;
}
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public Object getPutResult() {
return putResult;
}
public void setPutResult(Object putResult) {
this.putResult = putResult;
}
public Object getGetResult() {
return getResult;
}
public void setGetResult(Object getResult) {
this.getResult = getResult;
}
public Object getRemoveResult() {
return removeResult;
}
public void setRemoveResult(Object removeResult) {
this.removeResult = removeResult;
}
public Object getInputKey() {
return inputKey;
}
public void setInputKey(Object inputKey) {
this.inputKey = inputKey;
}
public Object getInputValue() {
return inputValue;
}
public void setInputValue(Object inputValue) {
this.inputValue = inputValue;
}
public Throwable getErorr() {
return error;
}
public void setErorr(Throwable erorr) {
this.error = erorr;
}
public String getErrorString() {
return errorString;
}
public void setErrorString(String errorString) {
this.errorString = errorString;
}
public String getInfoString() {
return infoString;
}
public void setInfoString(String infoString) {
this.infoString = infoString;
}
public String getKeyClass() {
return keyClass;
}
public void setKeyClass(String keyClass) {
this.keyClass = keyClass;
}
public String getValueClass() {
return valueClass;
}
public void setValueClass(String valueClass) {
this.valueClass = valueClass;
}
public List getLocateEntryLocations() {
return locateEntryLocations;
}
public void setLocateEntryLocations(List locateEntryLocations) {
this.locateEntryLocations = locateEntryLocations;
}
public Result toCommandResult() {
if(keyClass==null || keyClass.isEmpty())
keyClass = "java.lang.String";
if(valueClass==null || valueClass.isEmpty())
valueClass = "java.lang.String";
if(errorString!=null){
//return ResultBuilder.createGemFireErrorResult(errorString);
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
section.addData("Message", errorString);
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
return ResultBuilder.buildResult(data);
}
else{
CompositeResultData data = ResultBuilder.createCompositeResultData();
SectionResultData section = data.addSection();
TabularResultData table = section.addTable();
section.addData(RESULT_FLAG, operationCompletedSuccessfully);
if(infoString!=null)
section.addData("Message", infoString);
if(isGet()){
section.addData("Key Class", getKeyClass());
if(!isDeclaredPrimitive(keyClass))
addJSONStringToTable(table,inputKey);
else
section.addData("Key", inputKey);
section.addData("Value Class", getValueClass());
if(!isDeclaredPrimitive(valueClass))
addJSONStringToTable(table,getResult);
else
section.addData("Value", getResult);
}else if(isLocateEntry()){
section.addData("Key Class", getKeyClass());
if(!isDeclaredPrimitive(keyClass))
addJSONStringToTable(table,inputKey);
else
section.addData("Key", inputKey);
if(locateEntryLocations!=null){
TabularResultData locationTable = section.addTable();
int totalLocations = 0;
for(KeyInfo info : locateEntryLocations){
List