本文整理匯總了Java中org.apache.geode.cache.query.Struct類的典型用法代碼示例。如果您正苦於以下問題:Java Struct類的具體用法?Java Struct怎麽用?Java Struct使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Struct類屬於org.apache.geode.cache.query包,在下文中一共展示了Struct類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: evaluateAttribute
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
public static Object evaluateAttribute(Object target, String attribute)
throws NameNotFoundException, QueryInvocationTargetException {
if (target instanceof Struct) {
Struct struct = (Struct) target;
try {
return struct.get(attribute);
} catch (Exception e) {
throw new NameNotFoundException(attribute);
}
}
try {
return new AttributeDescriptor(attribute).read(target);
} catch (NameNotFoundException nfe) {
if (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS
|| DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS) {
return QueryService.UNDEFINED;
} else {
throw nfe;
}
}
}
示例2: toData
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Override
public void toData(DataOutput out) throws IOException {
boolean isStruct = this.collectionType.getElementType().isStructType();
DataSerializer.writeObject(this.collectionType.getElementType(), out);
HeapDataOutputStream hdos = new HeapDataOutputStream(1024, null);
LongUpdater lu = hdos.reserveLong();
Iterator<E> iter = this.iterator();
int numElements = 0;
while (iter.hasNext()) {
E data = iter.next();
if (isStruct) {
Object[] fields = ((Struct) data).getFieldValues();
DataSerializer.writeObjectArray(fields, out);
} else {
DataSerializer.writeObject(data, hdos);
}
++numElements;
}
lu.update(numElements);
hdos.sendTo(out);
}
示例3: toData
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Override
public void toData(DataOutput out) throws IOException {
boolean isStruct = this.collectionType.getElementType().isStructType();
DataSerializer.writeObject(this.collectionType.getElementType(), out);
DataSerializer.writePrimitiveBoolean(this.isDistinct, out);
HeapDataOutputStream hdos = new HeapDataOutputStream(1024, null);
LongUpdater lu = hdos.reserveLong();
Iterator<E> iter = this.iterator();
int numElements = 0;
while (iter.hasNext()) {
E data = iter.next();
if (isStruct) {
Object[] fields = ((Struct) data).getFieldValues();
DataSerializer.writeObjectArray(fields, out);
} else {
DataSerializer.writeObject(data, hdos);
}
++numElements;
}
lu.update(numElements);
hdos.sendTo(out);
}
示例4: accumulate
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
private void accumulate(boolean isStruct, Aggregator[] aggregators, Object current,
boolean[] objectChangedMarker) {
int bitstart = 0;
for (Aggregator aggregator : aggregators) {
if (isStruct) {
int pos = this.aggregateColsPos.nextSetBit(bitstart);
bitstart = pos + 1;
Struct struct = (Struct) current;
Object scalar = PDXUtils.convertPDX(struct.getFieldValues()[pos], false, true, true, true,
objectChangedMarker, isStruct);
aggregator.accumulate(scalar);
} else {
current =
PDXUtils.convertPDX(current, false, true, true, true, objectChangedMarker, isStruct);
aggregator.accumulate(current);
}
}
}
示例5: add
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
/** Add a Struct */
@Override
public boolean add(Struct obj) {
if (!(obj instanceof StructImpl)) {
throw new IllegalArgumentException(
LocalizedStrings.SortedStructSet_THIS_SET_ONLY_ACCEPTS_STRUCTIMPL.toLocalizedString());
}
StructImpl s = (StructImpl) obj;
if (!s.getStructType().equals(this.structType)) {
throw new IllegalArgumentException(
LocalizedStrings.SortedStructSet_OBJ_DOES_NOT_HAVE_THE_SAME_STRUCTTYPE
.toLocalizedString());
}
// return addFieldValues(s.getFieldValues());
return super.add(s);
}
示例6: testConvertibleGroupByQuery_refer_column_alias_Bug520141
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Override
@Test
public void testConvertibleGroupByQuery_refer_column_alias_Bug520141() throws Exception {
Region region = this.createRegion("portfolio", PortfolioPdx.class);
for (int i = 1; i < 200; ++i) {
PortfolioPdx pf = new PortfolioPdx(i);
pf.shortID = (short) ((short) i / 5);
region.put("key-" + i, pf);
}
String queryStr =
"select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id ";
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery(queryStr);
SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
Iterator<Struct> iter = results.asList().iterator();
int counter = 0;
while (iter.hasNext()) {
Struct str = iter.next();
assertEquals(counter++, ((Short) str.get("short_id")).intValue());
}
assertEquals(39, counter - 1);
}
示例7: testConvertibleGroupByQuery_refer_column_alias_Bug520141
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Test
public void testConvertibleGroupByQuery_refer_column_alias_Bug520141() throws Exception {
Region region = this.createRegion("portfolio", Portfolio.class);
for (int i = 1; i < 200; ++i) {
Portfolio pf = new Portfolio(i);
pf.shortID = (short) ((short) i / 5);
region.put("" + i, pf);
}
String queryStr =
"select p.shortID as short_id from /portfolio p where p.ID >= 0 group by short_id ";
QueryService qs = CacheUtils.getQueryService();
Query query = qs.newQuery(queryStr);
SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
Iterator<Struct> iter = results.asList().iterator();
int counter = 0;
while (iter.hasNext()) {
Struct str = iter.next();
assertEquals(counter++, ((Short) str.get("short_id")).intValue());
}
assertEquals(39, counter - 1);
}
示例8: objectsEqual
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
private boolean objectsEqual(Object o1, Object o2) {
// Assumed that o1 and o2 are the same object type as both are from collections created by
// executing the same query
if (o1 instanceof Struct) {
// if o2 is null, an NPE will be thrown.
Object[] values1 = ((Struct) o1).getFieldValues();
Object[] values2 = ((Struct) o2).getFieldValues();
assertEquals(values1.length, values2.length);
boolean elementEqual = true;
for (int i = 0; i < values1.length; ++i) {
elementEqual =
elementEqual && ((values1[i] == values2[i]) || values1[i].equals(values2[i]));
}
if (elementEqual) {
return true;
}
} else {
// if o1 is null and o2 is not, an NPE will be thrown
if (o1 == o2 || o1.equals(o2)) {
return true;
}
}
return false;
}
示例9: testBug32763
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Ignore("TODO: test is disabled")
@Test
public void testBug32763() throws Exception {
Region region = CacheUtils.createRegion("pos", Portfolio.class);
region.put("0", new Portfolio(0));
region.put("1", new Portfolio(1));
region.put("2", new Portfolio(2));
region.put("3", new Portfolio(3));
QueryService qs = CacheUtils.getQueryService();
String qStr =
"SELECT DISTINCT key: key, iD: entry.value.iD, secId: posnVal.secId FROM /pos.entries entry, entry.value.positions.values posnVal WHERE entry.value.\"type\" = 'type0' AND posnVal.secId = 'YHOO'";
Query q = qs.newQuery(qStr);
SelectResults result = (SelectResults) q.execute();
StructType type = (StructType) result.getCollectionType().getElementType();
String names[] = type.getFieldNames();
List list = result.asList();
if (list.size() < 1)
fail("Test failed as the resultset's size is zero");
for (int i = 0; i < list.size(); ++i) {
Struct stc = (Struct) list.get(i);
if (!stc.get(names[2]).equals("YHOO")) {
fail("Test failed as the SecID value is not YHOO");
}
}
}
示例10: checkForPdxString
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
private void checkForPdxString(List results, String query) {
for (Object o : results) {
if (o instanceof Struct) {
Object o1 = ((Struct) o).getFieldValues()[0];
Object o2 = ((Struct) o).getFieldValues()[1];
if (!(o1 instanceof String)) {
fail("Returned instance of " + o1.getClass() + " instead of String for query: " + query);
}
if (!(o2 instanceof String)) {
fail("Returned instance of " + o2.getClass() + " instead of String for query: " + query);
}
} else {
if (!(o instanceof String)) {
fail("Returned instance of " + o.getClass() + " instead of String for query: " + query);
}
}
}
}
示例11: testAddAndGetOccurence
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Test
public void testAddAndGetOccurence() {
ResultsBag bag = getBagObject(String.class);
bag = getBagObject(String.class);
ObjectType elementType = bag.getCollectionType().getElementType();
assertEquals(1, bag.addAndGetOccurence(elementType instanceof StructType
? ((Struct) wrap("one", elementType)).getFieldValues() : wrap("one", elementType)));
bag.add(wrap("two", elementType));
assertEquals(2,
bag.addAndGetOccurence(
elementType instanceof StructType ? ((Struct) wrap("two", elementType)).getFieldValues()
: wrap("two", bag.getCollectionType().getElementType())));
bag.add(wrap("three", bag.getCollectionType().getElementType()));
bag.add(wrap("three", bag.getCollectionType().getElementType()));
assertEquals(3, bag.addAndGetOccurence(elementType instanceof StructType
? ((Struct) wrap("three", elementType)).getFieldValues() : wrap("three", elementType)));
bag.add(wrap(null, bag.getCollectionType().getElementType()));
bag.add(wrap(null, bag.getCollectionType().getElementType()));
assertEquals(3, bag.addAndGetOccurence(elementType instanceof StructType
? ((Struct) wrap(null, elementType)).getFieldValues() : wrap(null, elementType)));
}
示例12: createStructFieldMergedResult
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
private NWayMergeResults<Struct> createStructFieldMergedResult(
Collection<? extends Collection<Struct>> sortedResults, boolean isDistinct, int limit,
StructTypeImpl structType) throws Exception {
CompiledSortCriterion csc1 = new CompiledSortCriterion(false,
CompiledSortCriterion.ProjectionField.getProjectionField());
CompiledSortCriterion csc2 =
new CompiledSortCriterion(true, CompiledSortCriterion.ProjectionField.getProjectionField());
Method method = CompiledSortCriterion.class
.getDeclaredMethod("substituteExpressionWithProjectionField", Integer.TYPE);
method.setAccessible(true);
method.invoke(csc1, 0);
method.invoke(csc2, 1);
List<CompiledSortCriterion> orderByAttribs = new ArrayList<CompiledSortCriterion>();
orderByAttribs.add(csc1);
orderByAttribs.add(csc2);
ExecutionContext context = new ExecutionContext(null, null);
return new NWayMergeResults<Struct>(sortedResults, false, -1, orderByAttribs, context,
structType);
}
示例13: isSpecialObject
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
static boolean isSpecialObject(Object object) {
Class type = object.getClass();
if (type.isArray() || type.isEnum()) {
return true;
}
if ((object instanceof Collection) || (object instanceof Map) || (object instanceof PdxInstance)
|| (object instanceof Struct) || (object instanceof Region.Entry)) {
return true;
}
return false;
}
示例14: contains
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
/** Does this set contain specified struct? */
@Override
public boolean contains(Object obj) {
if (!(obj instanceof Struct)) {
return false;
}
Struct s = (Struct) obj;
if (!this.elementType.equals(StructTypeImpl.typeFromStruct(s))) {
return false;
}
return containsFieldValues(s.getFieldValues());
}
示例15: occurrences
import org.apache.geode.cache.query.Struct; //導入依賴的package包/類
@Override
public int occurrences(Object element) {
if (!(element instanceof Struct)) {
return 0;
}
Struct s = (Struct) element;
if (!this.elementType.equals(StructTypeImpl.typeFromStruct(s))) {
return 0;
}
if (this.hasLimitIterator) {
int count = 0;
boolean encounteredObject = false;
Object[] fields = s.getFieldValues();
for (Iterator itr = this.fieldValuesIterator(); itr.hasNext();) {
Object[] structFields = (Object[]) itr.next();
if (Arrays.equals(fields, structFields)) {
count++;
encounteredObject = true;
} else if (encounteredObject) {
// Asif: No possibility of its occurence again
break;
}
}
return count;
} else {
return this.map.get(s.getFieldValues()); // returns 0 if not found
}
}