use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommands method put.
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_DATA, CliStrings.TOPIC_GEODE_REGION })
@CliCommand(value = { CliStrings.PUT }, help = CliStrings.PUT__HELP)
public Result put(@CliOption(key = { CliStrings.PUT__KEY }, mandatory = true, help = CliStrings.PUT__KEY__HELP) String key, @CliOption(key = { CliStrings.PUT__VALUE }, mandatory = true, help = CliStrings.PUT__VALUE__HELP) String value, @CliOption(key = { CliStrings.PUT__REGIONNAME }, mandatory = true, help = CliStrings.PUT__REGIONNAME__HELP, optionContext = ConverterHint.REGION_PATH) String regionPath, @CliOption(key = { CliStrings.PUT__KEYCLASS }, help = CliStrings.PUT__KEYCLASS__HELP) String keyClass, @CliOption(key = { CliStrings.PUT__VALUEKLASS }, help = CliStrings.PUT__VALUEKLASS__HELP) String valueClass, @CliOption(key = { CliStrings.PUT__PUTIFABSENT }, help = CliStrings.PUT__PUTIFABSENT__HELP, unspecifiedDefaultValue = "false") boolean putIfAbsent) {
this.securityService.authorizeRegionWrite(regionPath);
InternalCache cache = getCache();
DataCommandResult dataResult;
if (StringUtils.isEmpty(regionPath)) {
return makePresentationResult(DataCommandResult.createPutResult(key, null, null, CliStrings.PUT__MSG__REGIONNAME_EMPTY, false));
}
if (StringUtils.isEmpty(key)) {
return makePresentationResult(DataCommandResult.createPutResult(key, null, null, CliStrings.PUT__MSG__KEY_EMPTY, false));
}
if (StringUtils.isEmpty(value)) {
return makePresentationResult(DataCommandResult.createPutResult(value, null, null, CliStrings.PUT__MSG__VALUE_EMPTY, false));
}
@SuppressWarnings("rawtypes") Region region = cache.getRegion(regionPath);
DataCommandFunction putfn = new DataCommandFunction();
if (region == null) {
Set<DistributedMember> memberList = getRegionAssociatedMembers(regionPath, getCache(), false);
if (CollectionUtils.isNotEmpty(memberList)) {
DataCommandRequest request = new DataCommandRequest();
request.setCommand(CliStrings.PUT);
request.setValue(value);
request.setKey(key);
request.setKeyClass(keyClass);
request.setRegionName(regionPath);
request.setValueClass(valueClass);
request.setPutIfAbsent(putIfAbsent);
dataResult = callFunctionForRegion(request, putfn, memberList);
} else {
dataResult = DataCommandResult.createPutInfoResult(key, value, null, CliStrings.format(CliStrings.PUT__MSG__REGION_NOT_FOUND_ON_ALL_MEMBERS, regionPath), false);
}
} else {
dataResult = putfn.put(key, value, putIfAbsent, keyClass, valueClass, regionPath);
}
dataResult.setKeyClass(keyClass);
if (valueClass != null) {
dataResult.setValueClass(valueClass);
}
return makePresentationResult(dataResult);
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommandFunctionJUnitTest method testLocateKeyIsObject.
/*
* This test addresses GEODE-184
*/
@Test
public void testLocateKeyIsObject() throws Exception {
DataCommandFunction dataCmdFn = new DataCommandFunction();
DataCommandResult result = dataCmdFn.locateEntry("{'cheese': 'key_1'}", StringCheese.class.getName(), String.class.getName(), PARTITIONED_REGION, false);
assertNotNull(result);
result.aggregate(null);
List<DataCommandResult.KeyInfo> keyInfos = result.getLocateEntryLocations();
assertEquals(1, keyInfos.size());
}
use of org.apache.geode.management.internal.cli.domain.DataCommandResult in project geode by apache.
the class DataCommandFunctionWithPDXJUnitTest method getTableFromQuery.
private TabularResultData getTableFromQuery(String query) {
DataCommandRequest request = new DataCommandRequest();
request.setQuery(query);
DataCommandResult result = new DataCommandFunction().select(request);
CompositeResultData r = result.toSelectCommandResult();
return r.retrieveSectionByIndex(0).retrieveTableByIndex(0);
}
Aggregations