use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class PdxTypeExportDUnitTest method testPeer.
@Test
public void testPeer() throws Exception {
Region r = getCache().getRegion("pdxtest");
r.get(1);
TypeRegistry tr = ((GemFireCacheImpl) getCache()).getPdxRegistry();
Collection<PdxType> types = tr.typeMap().values();
assertEquals(MyObjectPdx.class.getName(), types.iterator().next().getClassName());
Collection<EnumInfo> enums = tr.enumMap().values();
assertEquals(MyEnumPdx.const1.name(), enums.iterator().next().getEnum().name());
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class JsonWriter method writeValueAsJson.
public static void writeValueAsJson(JsonGenerator generator, Object value, String pdxField) throws JsonGenerationException, IOException {
if (value == null) {
generator.writeNull();
} else if (value.getClass().equals(Boolean.class)) {
boolean b = (Boolean) value;
generator.writeBoolean(b);
} else if (value.getClass().equals(Byte.class)) {
Byte b = (Byte) value;
generator.writeNumber(b);
} else if (value.getClass().equals(Short.class)) {
Short b = (Short) value;
generator.writeNumber(b);
} else if (value.getClass().equals(Integer.class)) {
int i = (Integer) value;
generator.writeNumber(i);
} else if (value.getClass().equals(Long.class)) {
long i = (Long) value;
generator.writeNumber(i);
} else if (value.getClass().equals(BigInteger.class)) {
BigInteger i = (BigInteger) value;
generator.writeNumber(i);
} else if (value.getClass().equals(Float.class)) {
float i = (Float) value;
generator.writeNumber(i);
} else if (value.getClass().equals(BigDecimal.class)) {
BigDecimal i = (BigDecimal) value;
generator.writeNumber(i);
} else if (value.getClass().equals(Double.class)) {
double d = (Double) value;
generator.writeNumber(d);
} else if (value.getClass().equals(String.class)) {
String s = (String) value;
generator.writeString(s);
} else if (value.getClass().isArray()) {
writeArrayAsJson(generator, value, pdxField);
} else if (value.getClass().equals(Link.class)) {
writeLinkAsJson(generator, (Link) value, pdxField);
// } else if (value.getClass().equals(Date.class)) {
// generator.writeObject((Date) value);
} else if (value.getClass().equals(EnumInfo.class)) {
/*
* try { generator.writeString(((EnumInfo)value).getEnum().name()); } catch
* (ClassNotFoundException e) { throw new
* IllegalStateException("PdxInstance returns unknwon pdxfield " + pdxField + " for type " +
* value); }
*/
generator.writeString(value.toString());
} else if (value.getClass().equals(PdxInstanceEnumInfo.class)) {
generator.writeString(value.toString());
} else {
if (value instanceof Struct) {
writeStructAsJson(generator, (StructImpl) value);
} else if (value instanceof PdxInstance) {
writePdxInstanceAsJson(generator, (PdxInstance) value);
} else if (value instanceof Collection) {
writeCollectionAsJson(generator, (Collection<?>) value);
} else if (value instanceof Map) {
writeMapAsJson(generator, (Map) value, pdxField);
} else {
generator.writeObject(value);
}
}
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class GetPDXEnumById method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received get pdx enum by id request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
int enumId = clientMessage.getPart(0).getInt();
EnumInfo result;
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
result = registry.getEnumInfoById(enumId);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setMessageType(MessageType.RESPONSE);
responseMsg.setNumberOfParts(1);
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.addObjPart(result);
responseMsg.send(serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class GetPDXIdForEnum method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received get pdx id for enum request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
EnumInfo enumInfo = (EnumInfo) clientMessage.getPart(0).getObject();
int enumId;
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
enumId = registry.defineEnum(enumInfo);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setMessageType(MessageType.RESPONSE);
responseMsg.setNumberOfParts(1);
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.addIntPart(enumId);
responseMsg.send(serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.pdx.internal.EnumInfo in project geode by apache.
the class DiskStoreImpl method pdxDeleteField.
private Collection<PdxType> pdxDeleteField(String className, String fieldName) throws IOException {
// Since we are recovering a disk store, the cast from DiskRegionView -->
// PlaceHolderDiskRegion
// and from RegionEntry --> DiskEntry should be ok.
// In offline mode, we need to schedule the regions to be recovered
// explicitly.
DiskRegionView foundPdx = null;
for (DiskRegionView drv : getKnown()) {
if (drv.getName().equals(PeerTypeRegistration.REGION_FULL_PATH)) {
foundPdx = drv;
scheduleForRecovery((PlaceHolderDiskRegion) drv);
}
}
if (foundPdx == null) {
throw new IllegalStateException("The disk store does not contain any PDX types.");
}
recoverRegionsThatAreReady();
PersistentOplogSet oplogSet = (PersistentOplogSet) getOplogSet(foundPdx);
ArrayList<PdxType> result = new ArrayList<PdxType>();
for (RegionEntry re : foundPdx.getRecoveredEntryMap().regionEntries()) {
Object value = re._getValueRetain(foundPdx, true);
if (Token.isRemoved(value)) {
continue;
}
if (value instanceof CachedDeserializable) {
value = ((CachedDeserializable) value).getDeserializedForReading();
}
if (value instanceof EnumInfo) {
// nothing to delete in an enum
continue;
}
PdxType type = (PdxType) value;
if (type.getClassName().equals(className)) {
PdxField field = type.getPdxField(fieldName);
if (field != null) {
field.setDeleted(true);
type.setHasDeletedField(true);
result.add(type);
oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(type), true);
}
}
}
return result;
}
Aggregations