use of org.apache.geode.cache.CacheException in project geode by apache.
the class CompiledSortCriterion method evaluate.
/**
* evaluates sort criteria in order by clause
*/
public Object evaluate(Object data, ExecutionContext context) {
Object value = null;
if (this.columnIndex > 0) {
value = ((Object[]) data)[this.columnIndex];
} else if (this.columnIndex == 0) {
if (data instanceof Object[]) {
value = ((Object[]) data)[this.columnIndex];
} else {
value = data;
}
} else {
throw new IllegalStateException(" Order By Column attribute unmapped");
}
context.setCurrentProjectionField(value);
try {
return this.expr.evaluate(context);
} catch (Exception e) {
// TODO: never throw an anonymous inner class
throw new CacheException(e) {
};
}
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class PDXUtils method convertPDX.
public static Object convertPDX(Object obj, boolean isStruct, boolean getDomainObjectForPdx, boolean getDeserializedObject, boolean localResults, boolean[] objectChangedMarker, boolean isDistinct) {
objectChangedMarker[0] = false;
if (isStruct) {
StructImpl simpl = (StructImpl) obj;
if (getDomainObjectForPdx) {
try {
if (simpl.isHasPdx()) {
obj = simpl.getPdxFieldValues();
objectChangedMarker[0] = true;
} else {
obj = simpl.getFieldValues();
}
} catch (Exception ex) {
throw new CacheException("Unable to retrieve domain object from PdxInstance while building the ResultSet. " + ex.getMessage()) {
};
}
} else {
Object[] values = simpl.getFieldValues();
if (getDeserializedObject) {
for (int i = 0; i < values.length; i++) {
if (values[i] instanceof VMCachedDeserializable) {
values[i] = ((VMCachedDeserializable) values[i]).getDeserializedForReading();
}
}
}
/* This is to convert PdxString to String */
if (simpl.isHasPdx() && isDistinct && localResults) {
for (int i = 0; i < values.length; i++) {
if (values[i] instanceof PdxString) {
values[i] = ((PdxString) values[i]).toString();
}
}
}
obj = values;
}
} else {
if (getDomainObjectForPdx) {
if (obj instanceof PdxInstance) {
try {
obj = ((PdxInstance) obj).getObject();
objectChangedMarker[0] = true;
} catch (Exception ex) {
throw new CacheException("Unable to retrieve domain object from PdxInstance while building the ResultSet. " + ex.getMessage()) {
};
}
} else if (obj instanceof PdxString) {
obj = ((PdxString) obj).toString();
}
} else if (isDistinct && localResults && obj instanceof PdxString) {
/* This is to convert PdxString to String */
obj = ((PdxString) obj).toString();
}
if (getDeserializedObject && obj instanceof VMCachedDeserializable) {
obj = ((VMCachedDeserializable) obj).getDeserializedForReading();
objectChangedMarker[0] = true;
}
}
return obj;
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class IndexCreationMsg method operateOnPartitionedRegion.
/**
* This method actually operates on the partitioned region and creates given list of indexes from
* a index creation message.
*
* @param dm distribution manager.
* @param pr partitioned region on which to create an index.
* @throws CacheException indicating a cache level error
* @throws ForceReattemptException if the peer is no longer available
*/
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, ForceReattemptException {
// region exists
ReplyException replyEx = null;
boolean result = false;
List<Index> indexes = null;
List<String> failedIndexNames = new ArrayList<String>();
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
for (IndexCreationData icd : indexDefinitions) {
sb.append(icd.getIndexName()).append(" ");
}
logger.debug("Processing index creation message on this remote partitioned region vm for indexes: {}", sb);
}
try {
indexes = pr.createIndexes(true, indexDefinitions);
} catch (IndexCreationException e1) {
replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), e1);
} catch (MultiIndexCreationException exx) {
failedIndexNames.addAll(exx.getExceptionsMap().keySet());
if (logger.isDebugEnabled()) {
StringBuffer exceptionMsgs = new StringBuffer();
for (Exception ex : exx.getExceptionsMap().values()) {
exceptionMsgs.append(ex.getMessage()).append("\n");
}
logger.debug("Got an MultiIndexCreationException with \n: {}", exceptionMsgs);
logger.debug("{} indexes were created succesfully", failedIndexNames.size());
}
replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), exx);
}
if (null == replyEx) {
result = true;
}
if (result) {
Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
for (Index index : indexes) {
PartitionedIndex prIndex = (PartitionedIndex) index;
indexBucketsMap.put(prIndex.getName(), prIndex.getNumberOfIndexedBuckets());
}
sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
} else {
// add the indexes that were successfully created to the map
Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
for (IndexCreationData icd : indexDefinitions) {
// if the index was successfully created
if (!failedIndexNames.contains(icd.getIndexName())) {
PartitionedIndex prIndex = (PartitionedIndex) pr.getIndex(icd.getIndexName());
indexBucketsMap.put(icd.getIndexName(), prIndex.getNumberOfIndexedBuckets());
}
}
sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
}
if (logger.isDebugEnabled()) {
logger.debug("Multi Index creation completed on remote host and has sent the reply to the originating vm.");
}
return false;
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class PRFunctionStreamingResultCollector method getResult.
@Override
public Object getResult() throws FunctionException {
if (this.resultCollected) {
throw new FunctionException("Result already collected");
}
this.resultCollected = true;
if (this.hasResult) {
try {
this.waitForCacheOrFunctionException(0);
if (!this.execution.getFailedNodes().isEmpty() && !this.execution.isClientServerMode()) {
// end the rc and clear it
endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
// the function.
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (BucketMovedException e) {
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (CacheClosedException e) {
if (!execution.getWaitOnExceptionFlag()) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
} catch (CacheException e) {
// endResults();
throw new FunctionException(e);
} catch (ForceReattemptException e) {
// the function.
if (!this.fn.isHA()) {
throw new FunctionException(e);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
}
return this.userRC.getResult();
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class DistributedTXRegionStub method destroyExistingEntry.
public void destroyExistingEntry(EntryEventImpl event, boolean cacheWrite, Object expectedOldValue) {
// this.prStats.incPartitionMessagesSent();
try {
RemoteOperationResponse response = RemoteDestroyMessage.send(state.getTarget(), event.getLocalRegion(), event, expectedOldValue, DistributionManager.PARTITIONED_REGION_EXECUTOR, true, false);
response.waitForCacheException();
} catch (EntryNotFoundException enfe) {
throw enfe;
} catch (TransactionDataNotColocatedException enfe) {
throw enfe;
} catch (CacheException ce) {
throw new PartitionedRegionException(LocalizedStrings.PartitionedRegion_DESTROY_OF_ENTRY_ON_0_FAILED.toLocalizedString(state.getTarget()), ce);
} catch (RegionDestroyedException rde) {
throw new TransactionDataNotColocatedException(LocalizedStrings.RemoteMessage_REGION_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(rde.getRegionFullPath()), rde);
} catch (RemoteOperationException roe) {
throw new TransactionDataNodeHasDepartedException(roe);
}
}
Aggregations