private static ResultsBag readResultsBag(DataInput in) throws IOException, ClassNotFoundException { ResultsBag o = new ResultsBag(true); InternalDataSerializer.invokeFromData(o, in); return o; }
/** * Returns an appropriate, empty {@code SelectResults} * * @param objectType The {@code ObjectType} of the query results * @return an appropriate, empty {@code SelectResults} */ public static SelectResults getEmptySelectResults(ObjectType objectType, CachePerfStats statsOrNull) { SelectResults emptyResults = null; if (objectType instanceof StructType) { emptyResults = new StructBag((StructTypeImpl) objectType, statsOrNull); } else { emptyResults = new ResultsBag(objectType, statsOrNull); } return emptyResults; }
public static SelectResults createResultCollection(boolean distinct, ObjectType elementType, ExecutionContext context) { return distinct ? new ResultsSet(elementType) : new ResultsBag(elementType, context.getCachePerfStats()); }
public static SelectResults createResultCollection(ExecutionContext context, ObjectType elementType) { return context.isDistinct() ? new ResultsSet(elementType) : new ResultsBag(elementType, context.getCachePerfStats()); }
private ResultsBag getBagObject(Class clazz) { ObjectType type = new ObjectTypeImpl(clazz); return new ResultsBag(type, null); }
if (contextOrNull != null) { rs = contextOrNull.isDistinct() ? new ResultsSet(small) : new ResultsBag(small, contextOrNull.getCachePerfStats()); } else { rs = new ResultsBag(small, null);
@Test public void testIteration() { ResultsBag bag = new ResultsBag(); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); int numOnes = 0; int numTwos = 0; Integer one = new Integer(1); Integer two = new Integer(2); for (Iterator itr = bag.iterator(); itr.hasNext();) { Object n = itr.next(); if (one.equals(n)) { numOnes++; } else if (two.equals(n)) { numTwos++; } else { fail(n + " did not equal 1 or 2"); } } assertEquals(1, numOnes); assertEquals(2, numTwos); }
@Test public void queryIsPostProcessedWithListOfObjectValues() throws Exception { authorize(DATA, READ, REGION, ALL); when(security.postProcess(any(), any(), any())).thenReturn("spam"); DefaultQuery query = mockQuery(); String queryString = "select * from /region"; Object[] bindParameters = {"a"}; SelectResults results = new ResultsBag(); results.setElementType(new ObjectTypeImpl(Object.class)); results.add("value1"); results.add("value2"); when(query.execute((Object[]) any())).thenReturn(results); SelectResults<String> result = (SelectResults<String>) authorizingCache.query(queryString, bindParameters); assertEquals(Arrays.asList("spam", "spam"), result.asList()); }
@Test public void queryForMultipleObjects() throws ConnectionStateException, DecodingException, InvalidExecutionContextException, EncodingException, NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { Query query = mock(DefaultQuery.class); when(queryService.newQuery(eq(SELECT_STAR_QUERY))).thenReturn(query); SelectResults results = new ResultsBag(); results.setElementType(new ObjectTypeImpl()); results.add(STRING_RESULT_1); results.add(STRING_RESULT_2); when(query.execute((Object[]) any())).thenReturn(results); final OQLQueryRequest request = OQLQueryRequest.newBuilder().setQuery(SELECT_STAR_QUERY).build(); final Result<OQLQueryResponse> result = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertEquals(Arrays.asList(STRING_RESULT_1, STRING_RESULT_2), result.getMessage().getListResult().getElementList().stream() .map(serializationService::decode).collect(Collectors.toList())); }
if (contextOrNull != null) { rs = contextOrNull.isDistinct() ? new ResultsSet(large) : new ResultsBag(large, contextOrNull.getCachePerfStats()); } else { rs = new ResultsBag(large, null);
@Test public void testIterationRemoval() { ResultsBag bag = new ResultsBag(); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); bag.add(new Integer(3)); bag.add(new Integer(3)); bag.add(new Integer(4)); assertEquals(6, bag.size()); Iterator itr = bag.iterator(); for (int i = 0; i < 3; i++) { itr.next(); itr.remove(); } assertEquals(3, bag.size()); for (int i = 0; i < 3; i++) { itr.next(); itr.remove(); } assertTrue(bag.isEmpty()); assertEquals(0, bag.size()); }
@Test public void testIterationNullRemoval() { ResultsBag bag = new ResultsBag(); bag.add(null); bag.add(null); bag.add(new Integer(1)); bag.add(new Integer(2)); bag.add(new Integer(2)); assertEquals(5, bag.size()); for (Iterator itr = bag.iterator(); itr.hasNext();) { Object n = itr.next(); if (n == null) { itr.remove(); } } assertEquals(3, bag.size()); assertEquals(0, bag.occurrences(null)); }
ResultsBag rbWithoutData = new ResultsBag(); ResultsBag rbWithData = new ResultsBag(data, (CachePerfStats) null);
@Test public void testNoSuchElementException() { ResultsBag bag = new ResultsBag(); bag = new ResultsBag();
public DummyQRegion(Region region) { super(region, false); Class constraint = region.getAttributes().getValueConstraint(); if (constraint != null) valueType = TypeUtils.getObjectType(constraint); constraint = region.getAttributes().getKeyConstraint(); if (constraint != null) keyType = TypeUtils.getObjectType(constraint); values = new ResultsBag(((HasCachePerfStats) region.getCache()).getCachePerfStats()); values.setElementType(valueType); keys = new ResultsSet(); keys.setElementType(keyType); entries = new ResultsSet(); // gets key and value types from region entries.setElementType(TypeUtils.getRegionEntryType(region)); }
@Test public void testSerializingSetViewWithNulls() throws Exception { ResultsBag bag = new ResultsBag(); bag.add(new Integer(4)); bag.add(new Integer(2)); bag.add(new Integer(42)); bag.add(null); bag.add(null); bag.add(null); assertEquals(6, bag.size()); assertEquals(1, bag.occurrences(new Integer(4))); assertEquals(3, bag.occurrences(null)); Set set = bag.asSet(); assertEquals(4, set.size()); assertTrue(set.contains(new Integer(4))); assertTrue(set.contains(null)); ResultsCollectionWrapper w = new ResultsCollectionWrapper(new ObjectTypeImpl(Integer.class), set); HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(w, hdos); DataInputStream in = new DataInputStream(hdos.getInputStream()); SelectResults setCopy = (SelectResults) DataSerializer.readObject(in); assertEquals(4, setCopy.size()); assertTrue(setCopy.contains(new Integer(4))); assertTrue(setCopy.contains(null)); }
@Override public SelectResults getValues() { if (values == null) { values = new ResultsBag(((HasCachePerfStats) getRegion().getCache()).getCachePerfStats()); values.setElementType(valueType); } values.clear(); Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion()); if (val instanceof StoredObject) { @Retained @Released StoredObject ohval = (StoredObject) val; try { val = ohval.getDeserializedValue(getRegion(), this.entry); } finally { ohval.release(); } } else if (val instanceof CachedDeserializable) { val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry); } values.add(val); return values; }
results = new ResultsBag(new ObjectTypeImpl(Integer.class), 1, context.getCachePerfStats()); countStartQueryResult = 0; return results; return new StructBag((StructType) elementType, context.getCachePerfStats()); case UNORDERED_INDISTINCT_RESULTS: return new ResultsBag(elementType, context.getCachePerfStats());
@Test public void testNulls() { ResultsBag bag = new ResultsBag(); assertTrue(bag.isEmpty()); bag.add(null);
@Test public void testDuplicates() { ResultsBag bag = new ResultsBag(); bag.add("one"); bag.add("two"); assertEquals(2, bag.size()); bag.add("two"); assertEquals(3, bag.size()); assertEquals(1, bag.occurrences("one")); assertEquals(2, bag.occurrences("two")); assertTrue(bag.remove("two")); assertEquals(1, bag.occurrences("two")); assertTrue(bag.remove("one")); assertEquals(0, bag.occurrences("one")); assertTrue(!bag.remove("one")); assertEquals(0, bag.occurrences("one")); }