use of org.apache.geode.internal.cache.VMCachedDeserializable 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.internal.cache.VMCachedDeserializable in project geode by apache.
the class OrderByComparator method compare.
/**
* Compares its two arguments for order. Returns a negative integer, zero, or a positive integer
* as the first argument is less than, equal to, or greater than the second.
*
* @param obj1 the first object to be compared.
* @param obj2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the first argument is less than,
* equal to, or greater than the second.
* @throws ClassCastException if the arguments' types prevent them from being compared by this
* Comparator.
*/
public int compare(Object obj1, Object obj2) {
int result = -1;
if (obj1 == null && obj2 == null) {
return 0;
}
assert !(obj1 instanceof VMCachedDeserializable || obj2 instanceof VMCachedDeserializable);
if ((this.objType.isStructType() && obj1 instanceof Object[] && obj2 instanceof Object[]) || !this.objType.isStructType()) {
// instanceof Object){
if ((result = evaluateSortCriteria(obj1, obj2)) != 0) {
return result;
}
QueryObserver observer = QueryObserverHolder.getInstance();
if (observer != null) {
observer.orderByColumnsEqual();
}
// equal or not
if (this.objType.isStructType()) {
int i = 0;
for (Object o1 : (Object[]) obj1) {
Object o2 = ((Object[]) obj2)[i++];
// Check for null value.
if (o1 == null || o2 == null) {
if (o1 == null) {
if (o2 == null) {
continue;
}
return -1;
} else {
return 1;
}
} else if (o1 == QueryService.UNDEFINED || o2 == QueryService.UNDEFINED) {
if (o1 == QueryService.UNDEFINED) {
if (o2 == QueryService.UNDEFINED) {
continue;
}
return -1;
} else {
return 1;
}
}
if (o1 instanceof Comparable) {
final int rslt;
if (o1 instanceof Number && o2 instanceof Number) {
double diff = ((Number) o1).doubleValue() - ((Number) o2).doubleValue();
rslt = diff > 0 ? 1 : diff < 0 ? -1 : 0;
} else {
if (o1 instanceof PdxString && o2 instanceof String) {
o2 = new PdxString((String) o2);
} else if (o2 instanceof PdxString && o1 instanceof String) {
o1 = new PdxString((String) o1);
}
rslt = ((Comparable) o1).compareTo(o2);
}
if (rslt == 0) {
continue;
} else {
return rslt;
}
} else if (!o1.equals(o2)) {
return -1;
}
}
return 0;
} else {
if (obj1 instanceof PdxString && obj2 instanceof String) {
obj2 = new PdxString((String) obj2);
} else if (obj2 instanceof PdxString && obj1 instanceof String) {
obj1 = new PdxString((String) obj1);
}
if (obj1 instanceof Comparable) {
return ((Comparable) obj1).compareTo(obj2);
} else {
return obj1.equals(obj2) ? 0 : -1;
}
}
}
return -1;
}
use of org.apache.geode.internal.cache.VMCachedDeserializable in project geode by apache.
the class PRBucketSynchronizationDUnitTest method createEntry2.
private boolean createEntry2(VM vm, final InternalDistributedMember primary, final VersionSource primaryVersionID) {
return (Boolean) vm.invoke(new SerializableCallable("create entry2") {
public Object call() {
// create a fake event that looks like it came from the primary and apply it to
// this cache
PartitionedRegion pr = (PartitionedRegion) TestRegion;
BucketRegion bucket = pr.getDataStore().getLocalBucketById(0);
VersionTag tag = new VMVersionTag();
tag.setMemberID(primaryVersionID);
tag.setRegionVersion(2);
tag.setEntryVersion(1);
tag.setIsRemoteForTesting();
EntryEventImpl event = EntryEventImpl.create(bucket, Operation.CREATE, "Object3", true, primary, true, false);
LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
event.setNewValue(new VMCachedDeserializable("value3", 12));
event.setVersionTag(tag);
bucket.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
event.release();
// now create a tombstone so we can be sure these are transferred in delta-GII
tag = new VMVersionTag();
tag.setMemberID(primaryVersionID);
tag.setRegionVersion(3);
tag.setEntryVersion(1);
tag.setIsRemoteForTesting();
event = EntryEventImpl.create(bucket, Operation.CREATE, "Object5", true, primary, true, false);
event.setNewValue(Token.TOMBSTONE);
event.setVersionTag(tag);
LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
bucket.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
event.release();
bucket.dumpBackingMap();
LogWriterUtils.getLogWriter().info("bucket version vector is now " + bucket.getVersionVector().fullToString());
assertTrue("bucket should hold entry Object3 now", bucket.containsKey("Object3"));
return true;
}
});
}
Aggregations