com.gemstone.gemfire.pdx.internal.PdxInstanceImpl Java Examples
The following examples show how to use
com.gemstone.gemfire.pdx.internal.PdxInstanceImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PredictionListener.java From StockInference-Spark with Apache License 2.0 | 6 votes |
public void addToQueue(PdxInstanceImpl instance) { try { Double prediction = (double)instance.readField("predicted"); Double ema = (double)instance.readField("ema"); if (prediction>FinanceUI.maxY) FinanceUI.maxY = prediction; if (prediction<FinanceUI.minY) FinanceUI.minY = prediction; if (ema>FinanceUI.maxY) FinanceUI.maxY = ema; if (ema<FinanceUI.minY) FinanceUI.minY = ema; if (FinanceUI.getInstance() != null) { FinanceUI.getInstance().getPredictionDataQueue().add((Number) prediction); FinanceUI.getInstance().getEmaDataQueue().add((Number) ema); FinanceUI.yAxis.setUpperBound(FinanceUI.maxY); FinanceUI.yAxis.setLowerBound(FinanceUI.minY); } } catch (Exception ex) { ex.printStackTrace(); logger.severe("Problems parsing event for chart update:" + ex.getMessage()); } logger.fine(String.format("Received afterCreate event for entry: %s", instance.toString())); }
Example #2
Source File: PdxInstanceFactoryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBasics() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("basics", false); c.writeInt("intField", 37); PdxInstance pi = c.create(); WritablePdxInstance wpi = pi.createWriter(); assertEquals(true, wpi.hasField("intField")); assertEquals(37, wpi.getField("intField")); assertEquals(false, wpi.isIdentityField("intField")); wpi.setField("intField", 38); assertEquals(38, wpi.getField("intField")); checkPdxInstance(wpi); PdxType t1 = ((PdxInstanceImpl)pi).getPdxType(); PdxInstanceFactory c2 = PdxInstanceFactoryImpl.newCreator("basics", false); c2.writeInt("intField", 46); PdxInstance pi2 = c2.create(); PdxType t2 = ((PdxInstanceImpl)pi2).getPdxType(); assertEquals(t1, t2); assertEquals(t1.getTypeId(), t2.getTypeId()); }
Example #3
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testHashCodeEquals() throws Exception{ PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); PdxString pdx1 = (PdxString) pi.getRawField("secId"); Map<PdxString,String> map = new HashMap<PdxString,String>(); map.put(pdx1,"abc"); PdxString pdx2 = new PdxString("abc"); assertEquals(map.get(pdx2),"abc"); map = new THashMap(); map.put(pdx1,"abc"); assertEquals(map.get(pdx2),"abc"); }
Example #4
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testHashCodeEquals() throws Exception{ PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); PdxString pdx1 = (PdxString) pi.getRawField("secId"); Map<PdxString,String> map = new HashMap<PdxString,String>(); map.put(pdx1,"abc"); PdxString pdx2 = new PdxString("abc"); assertEquals(map.get(pdx2),"abc"); map = new THashMap(); map.put(pdx1,"abc"); assertEquals(map.get(pdx2),"abc"); }
Example #5
Source File: PdxInstanceFactoryJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public void testBasics() throws IOException, ClassNotFoundException { PdxInstanceFactory c = PdxInstanceFactoryImpl.newCreator("basics", false); c.writeInt("intField", 37); PdxInstance pi = c.create(); WritablePdxInstance wpi = pi.createWriter(); assertEquals(true, wpi.hasField("intField")); assertEquals(37, wpi.getField("intField")); assertEquals(false, wpi.isIdentityField("intField")); wpi.setField("intField", 38); assertEquals(38, wpi.getField("intField")); checkPdxInstance(wpi); PdxType t1 = ((PdxInstanceImpl)pi).getPdxType(); PdxInstanceFactory c2 = PdxInstanceFactoryImpl.newCreator("basics", false); c2.writeInt("intField", 46); PdxInstance pi2 = c2.create(); PdxType t2 = ((PdxInstanceImpl)pi2).getPdxType(); assertEquals(t1, t2); assertEquals(t1.getTypeId(), t2.getTypeId()); }
Example #6
Source File: PredictionListener.java From StockPrediction with Apache License 2.0 | 6 votes |
public void addToQueue(PdxInstanceImpl instance) { try { Double prediction = (double)instance.readField("predictedPeak"); Double ema = (double)instance.readField("ema"); if (prediction>FinanceUI.maxY) FinanceUI.maxY = prediction; if (prediction<FinanceUI.minY) FinanceUI.minY = prediction; if (ema>FinanceUI.maxY) FinanceUI.maxY = ema; if (ema<FinanceUI.minY) FinanceUI.minY = ema; if (FinanceUI.getInstance() != null) { FinanceUI.getInstance().getPredictionDataQueue().add((Number) prediction); FinanceUI.getInstance().getEmaDataQueue().add((Number) ema); FinanceUI.yAxis.setUpperBound(FinanceUI.maxY); FinanceUI.yAxis.setLowerBound(FinanceUI.minY); } } catch (Exception ex) { logger.severe("Problems parsing event for chart update:" + ex.getMessage()); } logger.fine(String.format("Received afterCreate event for entry: %s", instance.toString())); }
Example #7
Source File: TransactionListener.java From geode-demo-application with Apache License 2.0 | 6 votes |
private void updateProductRegion(EntryEvent<String, Object> entryEvent) { Transaction transaction = null; if (entryEvent.getNewValue() instanceof PdxInstanceImpl) { transaction = ReferenceHelper.toObject(entryEvent.getNewValue(), Transaction.class); } else { transaction = (Transaction)entryEvent.getNewValue(); } if (transaction.getOrderStatus().equals(Transaction.ORDER_OPEN)) { //get the product Product product = resolveReference(productRepository.findOne(transaction.getProductId())); //update the stock - NOTE: risk of inconsistency here product.setStockOnHand(product.getStockOnHand() - transaction.getQuantity()); //save the product System.out.println("Updating product " + product.getId()); productRepository.save(product); } }
Example #8
Source File: ProductGroupCounter.java From geode-demo-application with Apache License 2.0 | 5 votes |
private Product resolveReference(Object obj) { if (obj instanceof PdxInstanceImpl) { return ReferenceHelper.toObject(obj, Product.class); } else { return (Product)obj; } }
Example #9
Source File: StockListener.java From StockInference-Spark with Apache License 2.0 | 5 votes |
public void addToQueue(PdxInstanceImpl instance) { try { List<String> names = instance.getFieldNames(); // reading fields from the event Double close = Double.parseDouble(instance.readField("LastTradePriceOnly").toString()); if (close>FinanceUI.maxY) FinanceUI.maxY = close; if (close<FinanceUI.minY) FinanceUI.minY = close; //Double close = (double) instance.readField("ema"); //Double prediction = (double)instance.readField("predictedPeak");; if (FinanceUI.getInstance() != null) { FinanceUI.getInstance().getStockDataQueue().add((Number) close); FinanceUI.yAxis.setUpperBound(FinanceUI.maxY); FinanceUI.yAxis.setLowerBound(FinanceUI.minY); // FinanceUI.getInstance().getPredictionDataQueue().add((Number) prediction); } } catch (Exception ex) { ex.printStackTrace(); logger.severe("Problems parsing event for chart update:" + ex.getMessage()); } logger.fine(String.format("Received afterCreate event for entry: %s", instance.toString())); }
Example #10
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testToString() throws Exception{ String s = "abc"; PdxString pdx = new PdxString(s); assertEquals(s, pdx.toString()); PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); pdx = (PdxString) pi.getRawField("secId"); assertEquals(s, pdx.toString()); }
Example #11
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testEquals() throws Exception{ PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); PdxString pdx1 = (PdxString) pi.getRawField("secId"); assertEquals(false, pdx1.equals(null)); assertEquals(false, pdx1.equals(new Date(37))); PdxString pdx2 = new PdxString("abc"); assertEquals(pdx1,pdx2); pdx2 = new PdxString("ABC"); assertEquals(false, pdx1.equals(pdx2)); }
Example #12
Source File: AttributeDescriptor.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private Object readFieldFromDeserializedObject(PdxInstanceImpl pdxInstance, Object target) throws NameNotFoundException, QueryInvocationTargetException { try { Object obj = pdxInstance.getCachedObject(); return read(obj, obj.getClass()); } catch (PdxSerializationException e) { throw new NameNotFoundException( // the domain object is not available LocalizedStrings.AttributeDescriptor_FIELD_0_IN_CLASS_1_IS_NOT_ACCESSIBLE_TO_THE_QUERY_PROCESSOR .toLocalizedString(new Object[] { _name, target.getClass().getName() })); } }
Example #13
Source File: JSON.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void setValue(String theValue) throws StandardException { // stream = null; rawLength = -1; // cKey = null; // value = theValue; if (theValue != null) { PdxInstance jsonPdxInstance1 = null; try { jsonPdxInstance1 = JSONFormatter.fromJSON(theValue); } catch (JSONFormatterException je) { //showing only first 255 chars of the input String s = theValue; if (theValue.length() > 255) { s = theValue.substring(0, 255); } throw StandardException.newException(SQLState.LANG_INVALID_JSON, je, s, 255); } jsonPdxInstanceBytes = ((PdxInstanceImpl) jsonPdxInstance1).toBytes(); } else { jsonPdxInstanceBytes = null; } this.rawData = null; }
Example #14
Source File: InternalDataSerializer.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private static final Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException { int len = in.readInt(); int typeId = in.readInt(); GemFireCacheImpl gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed."); PdxType pdxType = gfc.getPdxRegistry().getType(typeId); if (DEBUG) { gfc.getLogger().info("readPdxSerializable pdxType="+ pdxType); } if (pdxType == null) { throw new IllegalStateException("Unknown pdx type=" + typeId); } DMStats dmStats = getDMStats(gfc); dmStats.incPdxDeserialization(len+9); // check if PdxInstance needs to be returned. if (pdxType.getNoDomainClass() || gfc.getPdxReadSerializedByAnyGemFireServices()) { // if (DEBUG) { // gfc.getLogger().info("returning PdxInstance", new Exception("stack trace")); // } dmStats.incPdxInstanceCreations(); return new PdxInstanceImpl(pdxType, in, len); } else { // if (DEBUG) { // gfc.getLogger().info("returning domain object", new Exception("stack trace")); // } // return domain object. PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len); return pdxReader.getObject(); } }
Example #15
Source File: InternalDataSerializer.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Just like readObject but make sure and pdx deserialized is not * a PdxInstance. * @since 6.6.2 */ public static final <T> T readNonPdxInstanceObject(final DataInput in) throws IOException, ClassNotFoundException { boolean wouldReadSerialized = PdxInstanceImpl.getPdxReadSerialized(); if (!wouldReadSerialized) { return DataSerializer.<T>readObject(in); } else { PdxInstanceImpl.setPdxReadSerialized(false); try { return DataSerializer.<T>readObject(in); } finally { PdxInstanceImpl.setPdxReadSerialized(true); } } }
Example #16
Source File: JSON.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
@Override public void setValue(String theValue) throws StandardException { // stream = null; rawLength = -1; // cKey = null; // value = theValue; if (theValue != null) { PdxInstance jsonPdxInstance1 = null; try { jsonPdxInstance1 = JSONFormatter.fromJSON(theValue); } catch (JSONFormatterException je) { //showing only first 255 chars of the input String s = theValue; if (theValue.length() > 255) { s = theValue.substring(0, 255); } throw StandardException.newException(SQLState.LANG_INVALID_JSON, je, s, 255); } jsonPdxInstanceBytes = ((PdxInstanceImpl) jsonPdxInstance1).toBytes(); } else { jsonPdxInstanceBytes = null; } this.rawData = null; }
Example #17
Source File: OrderCounter.java From geode-demo-application with Apache License 2.0 | 5 votes |
private Customer resolveReferenceCust(Object obj) { if (obj instanceof PdxInstanceImpl) { return ReferenceHelper.toObject(obj, Customer.class); } else { return (Customer)obj; } }
Example #18
Source File: OrderCounter.java From geode-demo-application with Apache License 2.0 | 5 votes |
private Transaction resolveReferenceTxn(Object obj) { if (obj instanceof PdxInstanceImpl) { return ReferenceHelper.toObject(obj, Transaction.class); } else { return (Transaction)obj; } }
Example #19
Source File: TransactionListener.java From geode-demo-application with Apache License 2.0 | 5 votes |
private Product resolveReference(Object obj) { if (obj instanceof PdxInstanceImpl) { return ReferenceHelper.toObject(obj, Product.class); } else { return (Product)obj; } }
Example #20
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testToString() throws Exception{ String s = "abc"; PdxString pdx = new PdxString(s); assertEquals(s, pdx.toString()); PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); pdx = (PdxString) pi.getRawField("secId"); assertEquals(s, pdx.toString()); }
Example #21
Source File: PdxStringJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public void testEquals() throws Exception{ PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false); pf.writeString("secId", "abc"); PdxInstanceImpl pi = (PdxInstanceImpl) pf.create(); PdxString pdx1 = (PdxString) pi.getRawField("secId"); assertEquals(false, pdx1.equals(null)); assertEquals(false, pdx1.equals(new Date(37))); PdxString pdx2 = new PdxString("abc"); assertEquals(pdx1,pdx2); pdx2 = new PdxString("ABC"); assertEquals(false, pdx1.equals(pdx2)); }
Example #22
Source File: AttributeDescriptor.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private Object readFieldFromDeserializedObject(PdxInstanceImpl pdxInstance, Object target) throws NameNotFoundException, QueryInvocationTargetException { try { Object obj = pdxInstance.getCachedObject(); return read(obj, obj.getClass()); } catch (PdxSerializationException e) { throw new NameNotFoundException( // the domain object is not available LocalizedStrings.AttributeDescriptor_FIELD_0_IN_CLASS_1_IS_NOT_ACCESSIBLE_TO_THE_QUERY_PROCESSOR .toLocalizedString(new Object[] { _name, target.getClass().getName() })); } }
Example #23
Source File: InternalDataSerializer.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private static final Object readPdxSerializable(final DataInput in) throws IOException, ClassNotFoundException { int len = in.readInt(); int typeId = in.readInt(); GemFireCacheImpl gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed."); PdxType pdxType = gfc.getPdxRegistry().getType(typeId); if (DEBUG) { gfc.getLogger().info("readPdxSerializable pdxType="+ pdxType); } if (pdxType == null) { throw new IllegalStateException("Unknown pdx type=" + typeId); } DMStats dmStats = getDMStats(gfc); dmStats.incPdxDeserialization(len+9); // check if PdxInstance needs to be returned. if (pdxType.getNoDomainClass() || gfc.getPdxReadSerializedByAnyGemFireServices()) { // if (DEBUG) { // gfc.getLogger().info("returning PdxInstance", new Exception("stack trace")); // } dmStats.incPdxInstanceCreations(); return new PdxInstanceImpl(pdxType, in, len); } else { // if (DEBUG) { // gfc.getLogger().info("returning domain object", new Exception("stack trace")); // } // return domain object. PdxReaderImpl pdxReader = new PdxReaderImpl(pdxType, in, len); return pdxReader.getObject(); } }
Example #24
Source File: InternalDataSerializer.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Just like readObject but make sure and pdx deserialized is not * a PdxInstance. * @since 6.6.2 */ public static final <T> T readNonPdxInstanceObject(final DataInput in) throws IOException, ClassNotFoundException { boolean wouldReadSerialized = PdxInstanceImpl.getPdxReadSerialized(); if (!wouldReadSerialized) { return DataSerializer.<T>readObject(in); } else { PdxInstanceImpl.setPdxReadSerialized(false); try { return DataSerializer.<T>readObject(in); } finally { PdxInstanceImpl.setPdxReadSerialized(true); } } }
Example #25
Source File: CompiledOperation.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private Object eval0(Object receiver, Class resolutionType, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException { if (receiver == null || receiver == QueryService.UNDEFINED) return QueryService.UNDEFINED; List args = new ArrayList(); List argTypes = new ArrayList(); Iterator i = this.args.iterator(); while (i.hasNext()) { CompiledValue arg = (CompiledValue)i.next(); Object o = arg.evaluate(context); // undefined arg produces undefines method result if (o == QueryService.UNDEFINED) return QueryService.UNDEFINED; args.add(o); // pass in null for the type if the runtime value is null if (o == null) argTypes.add(null); // commented out because we currently always use the runtime type for args // else if (arg.getType() == Identifier) // { // CompiledValue resolved = context.resolve(((CompiledID)arg).getId()); // if (resolved != null && resolved.getType() == ITERATOR) // argTypes.add(((RuntimeIterator)resolved).getBaseCollection().getConstraint()); // else // argTypes.add(o.getClass()); // } else argTypes.add(o.getClass()); // otherwise use the runtime type } // see if in cache MethodDispatch methodDispatch; List key = Arrays.asList(new Object[] { resolutionType , this.methodName, argTypes }); methodDispatch = (MethodDispatch)CompiledOperation.cache.get(key); if (methodDispatch == null) { try { methodDispatch = new MethodDispatch(resolutionType, this.methodName, argTypes); } catch(NameResolutionException nre) { if (!com.gemstone.gemfire.cache.query.Struct.class.isAssignableFrom(resolutionType) && (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS || DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS)) { return QueryService.UNDEFINED; } else { throw nre; } } // cache CompiledOperation.cache.putIfAbsent(key, methodDispatch); } if (receiver instanceof PdxInstance) { try { if (receiver instanceof PdxInstanceImpl) { receiver = ((PdxInstanceImpl)receiver).getCachedObject(); } else { receiver = ((PdxInstance)receiver).getObject(); } } catch (PdxSerializationException ex) { throw new QueryInvocationTargetException(ex); } } return methodDispatch.invoke(receiver, args); }
Example #26
Source File: PredictionListener.java From StockPrediction with Apache License 2.0 | 4 votes |
@Override public void afterCreate(EntryEvent<K, V> event) { addToQueue((PdxInstanceImpl) event.getNewValue()); }
Example #27
Source File: StockListener.java From StockPrediction with Apache License 2.0 | 4 votes |
@Override public void afterUpdate(EntryEvent<K, V> event) { addToQueue((PdxInstanceImpl) event.getNewValue()); }
Example #28
Source File: StockListener.java From StockPrediction with Apache License 2.0 | 4 votes |
@Override public void afterCreate(EntryEvent<K, V> event) { addToQueue((PdxInstanceImpl) event.getNewValue()); }
Example #29
Source File: PredictionListener.java From StockPrediction with Apache License 2.0 | 4 votes |
@Override public void afterUpdate(EntryEvent<K, V> event) { addToQueue((PdxInstanceImpl) event.getNewValue()); }
Example #30
Source File: StockListener.java From StockInference-Spark with Apache License 2.0 | 4 votes |
@Override public void afterCreate(EntryEvent<K, V> event) { addToQueue((PdxInstanceImpl) event.getNewValue()); }