Search in sources :

Example 11 with EnumInfo

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());
}
Also used : MyObjectPdx(com.examples.snapshot.MyObjectPdx) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with EnumInfo

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);
        }
    }
}
Also used : PdxInstanceEnumInfo(org.apache.geode.pdx.internal.EnumInfo.PdxInstanceEnumInfo) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) BigDecimal(java.math.BigDecimal) Struct(org.apache.geode.cache.query.Struct) BigInteger(java.math.BigInteger) PdxInstance(org.apache.geode.pdx.PdxInstance) BigInteger(java.math.BigInteger) Collection(java.util.Collection) Map(java.util.Map)

Example 13 with EnumInfo

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);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 14 with EnumInfo

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);
}
Also used : Message(org.apache.geode.internal.cache.tier.sockets.Message) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 15 with EnumInfo

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;
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) ArrayList(java.util.ArrayList) PdxField(org.apache.geode.pdx.internal.PdxField) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView)

Aggregations

EnumInfo (org.apache.geode.pdx.internal.EnumInfo)21 PdxType (org.apache.geode.pdx.internal.PdxType)14 IOException (java.io.IOException)8 Test (org.junit.Test)8 Cache (org.apache.geode.cache.Cache)6 Region (org.apache.geode.cache.Region)6 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)6 CacheFactory (org.apache.geode.cache.CacheFactory)5 InternalCache (org.apache.geode.internal.cache.InternalCache)5 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)5 File (java.io.File)4 Map (java.util.Map)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Properties (java.util.Properties)3 Message (org.apache.geode.internal.cache.tier.sockets.Message)3 EnumId (org.apache.geode.pdx.internal.EnumId)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2