use of org.apache.geode.cache.query.internal.index.PrimaryKeyIndex in project geode by apache.
the class MultiIndexCreationJUnitTest method testBasicMultiIndexCreationDifferentTypes.
@Test
public void testBasicMultiIndexCreationDifferentTypes() throws Exception {
Region r = CacheUtils.getRegion(regionName);
for (int i = 0; i < 10; i++) {
r.put("" + i, new Portfolio(i));
}
QueryService qs = CacheUtils.getQueryService();
qs.defineIndex("statusIndex", "status", r.getFullPath());
qs.defineHashIndex("IDIndex", "ID", r.getFullPath());
qs.defineKeyIndex("keyIDIndex", "ID", r.getFullPath());
List<Index> indexes = qs.createDefinedIndexes();
assertEquals("Only 3 indexes should have been created. ", 3, indexes.size());
Index ind = qs.getIndex(r, "statusIndex");
assertTrue(ind instanceof CompactRangeIndex);
assertEquals(2, ind.getStatistics().getNumberOfKeys());
assertEquals(10, ind.getStatistics().getNumberOfValues());
ind = qs.getIndex(r, "IDIndex");
assertTrue(ind instanceof HashIndex);
assertEquals(10, ind.getStatistics().getNumberOfValues());
ind = qs.getIndex(r, "keyIDIndex");
assertTrue(ind instanceof PrimaryKeyIndex);
assertEquals(10, ind.getStatistics().getNumberOfKeys());
assertEquals(10, ind.getStatistics().getNumberOfValues());
QueryObserver old = QueryObserverHolder.setInstance(new QueryObserverAdapter() {
private boolean indexCalled = false;
public void afterIndexLookup(Collection results) {
indexCalled = true;
}
public void endQuery() {
assertTrue(indexCalled);
}
});
String[] queries = { "select * from " + r.getFullPath() + " where status = 'active'", "select * from " + r.getFullPath() + " where ID > 4" };
for (int i = 0; i < queries.length; i++) {
SelectResults sr = (SelectResults) qs.newQuery(queries[i]).execute();
assertEquals(5, sr.size());
}
QueryObserverHolder.setInstance(old);
}
use of org.apache.geode.cache.query.internal.index.PrimaryKeyIndex in project geode by apache.
the class PdxStringQueryJUnitTest method testQueriesWithPrimaryKeyIndex.
@Test
public void testQueriesWithPrimaryKeyIndex() throws Exception {
Index index = qs.createKeyIndex("index3", "secId", "/exampleRegion");
assertTrue(index instanceof PrimaryKeyIndex);
putPdxInstances();
executeQueriesValidateResults(INDEX_TYPE_PRIMARYKEY);
r.clear();
putHeterogeneousObjects();
executeQueriesValidateResults(INDEX_TYPE_PRIMARYKEY);
qs.removeIndex(index);
r.clear();
}
use of org.apache.geode.cache.query.internal.index.PrimaryKeyIndex in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for an index
*/
private void generate(Index index) throws SAXException {
if (index == null) {
return;
}
AttributesImpl atts = new AttributesImpl();
if (index instanceof IndexCreationData) {
IndexCreationData indexData = (IndexCreationData) index;
atts.addAttribute("", "", NAME, "", indexData.getIndexName());
String indexType = indexData.getIndexType();
if (indexType.equals("KEY")) {
atts.addAttribute("", "", KEY_INDEX, "", "true");
} else {
// convert the indexType to the xml indexType
if (indexType.equals("HASH")) {
indexType = HASH_INDEX_TYPE;
} else {
indexType = RANGE_INDEX_TYPE;
}
atts.addAttribute("", "", KEY_INDEX, "", "false");
atts.addAttribute("", "", INDEX_TYPE, "", "" + indexType);
}
atts.addAttribute("", "", FROM_CLAUSE, "", indexData.getIndexFromClause());
atts.addAttribute("", "", EXPRESSION, "", indexData.getIndexExpression());
} else {
atts.addAttribute("", "", NAME, "", index.getName());
if (index instanceof PrimaryKeyIndex) {
atts.addAttribute("", "", KEY_INDEX, "", "true");
} else {
atts.addAttribute("", "", KEY_INDEX, "", "false");
String indexType = "range";
if (index instanceof HashIndex) {
indexType = "hash";
}
atts.addAttribute("", "", INDEX_TYPE, "", "" + indexType);
}
atts.addAttribute("", "", FROM_CLAUSE, "", index.getFromClause());
atts.addAttribute("", "", EXPRESSION, "", index.getIndexedExpression());
}
handler.startElement("", INDEX, INDEX, atts);
handler.endElement("", INDEX, INDEX);
}
Aggregations