@Test public void applyCqOrProjectionWhenContextNotForCqShouldAddValueToResults() throws Exception { when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); List results = new LinkedList(); String value = "value"; index.applyCqOrProjection(null, context, results, value, null, false, "key"); assertEquals(value, results.get(0)); }
@Test public void lockQueryWithoutProjectionWithMatchingResultShouldReturnCorrectValue() throws Exception { String value = "value"; when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); Region.Entry entry = mock(Region.Entry.class); when(entry.getValue()).thenReturn(value); when(region.accessEntry(eq("key"), anyBoolean())).thenReturn(entry); List results = new LinkedList(); index.lockedQuery("key", OQLLexerTokenTypes.TOK_EQ, results, null, context); assertEquals(value, results.get(0)); }
@Test public void applyCqOrProjectionWhenContextIsCqShouldAddCqEntryToResults() throws Exception { when(context.isCqQueryContext()).thenReturn(true); when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); List results = new LinkedList(); String value = "value"; index.applyCqOrProjection(null, context, results, value, null, false, "key"); assertTrue(results.get(0) instanceof CqEntry); }
/** * For local queries with distinct, deserialize all PdxInstances as we do not have a way to * compare Pdx and non Pdx objects in case the cache has a mix of pdx and non pdx objects. We * still have to honor the cache level readSerialized flag in case of all Pdx objects in cache. * Also always convert PdxString to String before adding to resultSet for remote queries */ private Object deserializePdxForLocalDistinctQuery(ExecutionContext context, Object value) throws QueryInvocationTargetException { if (!((DefaultQuery) context.getQuery()).isRemoteQuery()) { if (context.isDistinct() && value instanceof PdxInstance && !this.region.getCache().getPdxReadSerialized()) { try { value = ((PdxInstance) value).getObject(); } catch (Exception ex) { throw new QueryInvocationTargetException( "Unable to retrieve domain object from PdxInstance while building the ResultSet. " + ex.getMessage()); } } else if (value instanceof PdxString) { value = value.toString(); } } return value; }
@Test public void lockQueryWithoutProjectionWithMatchingResultForCqShouldReturnCorrectCqEvent() throws Exception { String value = "value"; when(context.isCqQueryContext()).thenReturn(true); when(context.getQuery()).thenReturn(mock(DefaultQuery.class)); Region.Entry entry = mock(Region.Entry.class); when(entry.getValue()).thenReturn(value); when(region.accessEntry(eq("key"), anyBoolean())).thenReturn(entry); List results = new LinkedList(); index.lockedQuery("key", OQLLexerTokenTypes.TOK_EQ, results, null, context); assertTrue(results.get(0) instanceof CqEntry); }
if (this.distinct && !((DefaultQuery) context.getQuery()).isRemoteQuery() && !context.getCache().getPdxReadSerialized() && (values[i] instanceof PdxInstance)) { values[i] = ((PdxInstance) values[i]).getObject(); if (!((DefaultQuery) context.getQuery()).isRemoteQuery()) { if (this.distinct && values[i] instanceof PdxInstance && !context.getCache().getPdxReadSerialized()) {