本文整理汇总了Java中org.hypergraphdb.indexing.ByPartIndexer类的典型用法代码示例。如果您正苦于以下问题:Java ByPartIndexer类的具体用法?Java ByPartIndexer怎么用?Java ByPartIndexer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByPartIndexer类属于org.hypergraphdb.indexing包,在下文中一共展示了ByPartIndexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnregister
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testUnregister()
{
cleanup();
HGIndexer indexer = new ByPartIndexer(graph.getTypeSystem().getTypeHandle(SimpleBean.class), "strProp");
graph.getIndexManager().register(indexer);
graph.runMaintenance();
SimpleBean x = new SimpleBean();
x.setStrProp("hypergraphdb");
graph.add(x);
x = new SimpleBean();
x.setStrProp("indexing");
graph.add(x);
HGIndex<?, ?> idx = graph.getIndexManager().getIndex(indexer);
Assert.assertNotNull(idx);
Assert.assertEquals(idx.count(), 2);
HGIndexer indexer2 = new ByPartIndexer(graph.getTypeSystem().getTypeHandle(SimpleBean.class), "strProp");
Assert.assertTrue(graph.getIndexManager().unregister(indexer2));
Assert.assertNull(graph.getIndexManager().getIndex(indexer));
this.reopenDb();
Assert.assertNull(graph.getIndexManager().getIndex(indexer));
Assert.assertEquals(graph.getIndexManager().getIndexersForType(graph.getTypeSystem().getTypeHandle(SimpleBean.class)),
null);
}
示例2: getAtomIndexedPartsConditions
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
private List<AtomPartCondition> getAtomIndexedPartsConditions(HyperGraph graph, HGHandle hType, Object value)
{
ArrayList<AtomPartCondition> L = new ArrayList<AtomPartCondition>();
List<HGIndexer<?,?>> indexers = graph.getIndexManager().getIndexersForType(hType);
if (indexers == null)
return L;
for (HGIndexer<?,?> idx : indexers)
{
if (idx instanceof ByPartIndexer)
{
String [] dimPath = ((ByPartIndexer)idx).getDimensionPath();
Object partValue = TypeUtils.project(graph, hType, value, dimPath, true).getValue();
L.add(new AtomPartCondition(dimPath, partValue));
}
}
return L;
}
示例3: guessUniquenessCondition
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
/**
* <p>
* Construct a {@link HGQueryCondition} that uniquely identifies an atom based on
* the passed in <code>Object</code> instance.
* </p>
*
* @param graph The {@link HyperGraph} database instance.
* @param instance The object for which an unique atom condition must be constructed.
* @return <code>null</code> if <code>instance == null</code>, otherwise a query condition
* identifying <code>instance</code> in the database.
*/
public static HGQueryCondition guessUniquenessCondition(final HyperGraph graph, final Object instance)
{
if (instance == null)
return null;
HGHandle type = graph.getTypeSystem().getTypeHandle(instance.getClass());
And and = new And();
and.add(type(type));
and.add(eq(instance));
if (instance instanceof HGLink)
and.add(orderedLink(HGUtils.toHandleArray((HGLink)instance)));
List<HGIndexer<?,?>> indexers = graph.getIndexManager().getIndexersForType(type);
if (indexers != null) for (HGIndexer<?,?> idx : indexers)
{
if (idx instanceof ByPartIndexer)
{
ByPartIndexer<?> byPart = (ByPartIndexer<?>)idx;
Object prop = TypeUtils.project(graph, type, instance, byPart.getDimensionPath(), true);
and.add(new AtomPartCondition(byPart.getDimensionPath(), prop));
}
}
return and;
}
示例4: getAtomIndexedPartsConditions
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
private List<AtomPartCondition> getAtomIndexedPartsConditions(HyperGraph graph, HGHandle hType, Object value)
{
ArrayList<AtomPartCondition> L = new ArrayList<AtomPartCondition>();
List<HGIndexer> indexers = graph.getIndexManager().getIndexersForType(hType);
if (indexers == null)
return L;
for (HGIndexer idx : indexers)
{
if (idx instanceof ByPartIndexer)
{
String [] dimPath = ((ByPartIndexer)idx).getDimensionPath();
Object partValue = TypeUtils.project(graph, hType, value, dimPath, true).getValue();
L.add(new AtomPartCondition(dimPath, partValue));
}
}
return L;
}
示例5: guessUniquenessCondition
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
/**
* <p>
* Construct a {@link HGQueryCondition} that uniquely identifies an atom based on
* the passed in <code>Object</code> instance.
* </p>
*
* @param graph The {@link HyperGraph} database instance.
* @param instance The object for which an unique atom condition must be constructed.
* @return <code>null</code> if <code>instance == null</code>, otherwise a query condition
* identifying <code>instance</code> in the database.
*/
public static HGQueryCondition guessUniquenessCondition(final HyperGraph graph, final Object instance)
{
if (instance == null)
return null;
HGHandle type = graph.getTypeSystem().getTypeHandle(instance.getClass());
And and = new And();
and.add(type(type));
and.add(eq(instance));
if (instance instanceof HGLink)
and.add(orderedLink(HGUtils.toHandleArray((HGLink)instance)));
List<HGIndexer> indexers = graph.getIndexManager().getIndexersForType(type);
if (indexers != null) for (HGIndexer idx : indexers)
{
if (idx instanceof ByPartIndexer)
{
ByPartIndexer byPart = (ByPartIndexer)idx;
Object prop = TypeUtils.project(graph, type, instance, byPart.getDimensionPath(), true);
and.add(new AtomPartCondition(byPart.getDimensionPath(), prop));
}
}
return and;
}
示例6: lookup
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
public static HGHandle lookup(HyperGraph hg, String typeAlias,
String keyProperty, Object keyValue)
{
HGHandle typeHandle = hg.getTypeSystem().getTypeHandle(typeAlias);
ByPartIndexer byProperty = new ByPartIndexer(typeHandle, new String[] { keyProperty });
HGIndex<String, HGHandle> index = hg.getIndexManager().register(byProperty);
return index.findFirst((String)keyValue);
}
示例7: lookup
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
private static HGHandle lookup(HyperGraph hg, String typeAlias,
String keyProperty, Object keyValue)
{
HGHandle typeHandle = hg.getTypeSystem().getTypeHandle(typeAlias);
ByPartIndexer byProperty = new ByPartIndexer(typeHandle, new String[] { keyProperty });
HGIndex<String, HGHandle> index = hg.getIndexManager().register(byProperty);
return index.findFirst((String)keyValue);
}
示例8: testConcurrentLinkCreation
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testConcurrentLinkCreation()
{
graph.getIndexManager().register(new ByPartIndexer(graph.getTypeSystem().getTypeHandle(LinkType.class), "idx"));
graph.runMaintenance();
for (int i = 0; i < atomsCount; i++)
hg.assertAtom(graph, makeAtom(i));
ExecutorService pool = Executors.newFixedThreadPool(10);
for (int i = 0; i < threadCount; i++)
{
final int j = i;
pool.execute(new Runnable() {
public void run()
{
try
{
populateLinks(j);
}
catch (Throwable t)
{
t.printStackTrace(System.err);
errors.add(t);
}
}
});
}
try
{
pool.shutdown();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
catch (InterruptedException ex)
{
System.out.println("testTxMap interrupted.");
return;
}
assertEquals(errors.size(), 0);
this.reopenDb();
verifyData();
}
示例9: testEnumIndex
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testEnumIndex()
{
HGIndexer indexer = new ByPartIndexer(graph.getTypeSystem().getTypeHandle(BeanWithEnum.class), "which");
graph.getIndexManager().register(indexer);
BeanWithEnum x1 = new BeanWithEnum();
BeanWithEnum x2 = new BeanWithEnum();
x2.setWhich(AnEnum.third);
BeanWithEnum x3 = new BeanWithEnum();
x3.setWhich(AnEnum.first);
BeanWithEnum x4 = new BeanWithEnum();
x4.setWhich(AnEnum.second);
graph.add(x1);
graph.add(x2);
graph.add(x3);
HGHandle h4 = graph.add(x4);
HGQueryCondition condition = hg.and(hg.type(BeanWithEnum.class), hg.eq("which", AnEnum.second));
HGQuery query = HGQuery.make(graph, condition);
// System.out.println(query.getClass().toString());
// System.out.println(((ExpressionBasedQuery)query).getCompiledQuery().getClass().toString());
Assert.assertTrue(query instanceof IndexBasedQuery ||
(query instanceof ExpressionBasedQuery &&
((ExpressionBasedQuery)query).getCompiledQuery() instanceof IndexBasedQuery));
Assert.assertEquals(hg.findOne(graph, condition), h4);
this.reopenDb();
}
示例10: prepare
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
void prepare()
{
HGHandle th = graph.getTypeSystem().getTypeHandle(IntTuple.class);
graph.getIndexManager().register(new ByPartIndexer(th, "x"));
graph.getIndexManager().register(new ByPartIndexer(th, "y"));
graph.getIndexManager().register(new ByPartIndexer(th, "z"));
graph.getIndexManager().register(new ByPartIndexer(th, "w"));
}
示例11: setUp
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@BeforeClass
public static void setUp()
{
HGTestBase.setUp();
HGTypeSystem ts = graph.getTypeSystem();
HGHandle typeH = ts.getTypeHandle(NestedBean.InnerBean.class);
for (int i = 0; i < ALIAS_COUNT; i++)
ts.addAlias(typeH, ALIAS_PREFIX + i);
index = (HGSortIndex<Integer, HGHandle>) graph.getIndexManager()
.<Integer, HGHandle> register(
new ByPartIndexer(typeH, "number"));
graph.getIndexManager().register(new ByPartIndexer<String>(
ts.getTypeHandle(Transport.class),
"owner.email"
));
ArrayList<HGHandle> nbeans = new ArrayList<HGHandle>();
for (int i = 0; i < COUNT - 1; i++)
{
HGHandle h = graph.add(NestedBean.create(i));
nbeans.add(h);
}
SimpleBean sbean = new SimpleBean();
sbean.setStrProp("nestbeansLink");
graph.add(new HGValueLink(sbean, nbeans.toArray(new HGHandle[0])));
// duplicated value
graph.add(NestedBean.create(DUPLICATED_NUM));
create_simple_subgraph();
}
示例12: testUpdateLiveAtom
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testUpdateLiveAtom()
{
HGHandle typeHandle = graph.getTypeSystem().getTypeHandle(SimpleBean.class);
ByPartIndexer<Long> byPartIndexer = new ByPartIndexer<Long>("id_indexer", typeHandle, "longProp");
graph.getIndexManager().register(byPartIndexer);
graph.runMaintenance();
SimpleBean x = new SimpleBean();
x.setLongProp(1l);
graph.add(x);
x.setLongProp(3l);
graph.update(x);
Assert.assertEquals(graph.count(hg.and(hg.type(SimpleBean.class), hg.gt("longProp", 0l))), 1);
}
示例13: testNumberOrder
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testNumberOrder()
{
HGHandle typeHandle = graph.getTypeSystem().getTypeHandle(SimpleBean.class);
ByPartIndexer<Long> byPartIndexer = new ByPartIndexer<Long>("id_indexer", typeHandle, "longProp");
graph.getIndexManager().register(byPartIndexer);
for (long i = 1l; i < 2000l; i++)
{
graph.add(new Id(i));
}
HGIndex index = graph.getIndexManager().getIndex(byPartIndexer);
HGRandomAccessResult result = index.scanValues();
result.goBeforeFirst();
try
{
ArrayList<Long> numbers = new ArrayList<Long>();
while (result.hasNext())
{
SimpleBean b = graph.get((HGHandle) result.next());
numbers.add(b.getLongProp());
}
for (int i = 0; i < numbers.size() - 1; i++)
Assert.assertTrue(numbers.get(i) < numbers.get(i+1));
}
finally
{
result.close();
}
}
示例14: testNewIndexWithExistingData
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testNewIndexWithExistingData()
{
cleanup();
SimpleBean x = new SimpleBean();
x.setStrProp("hypergraphdb");
graph.add(x);
HGIndexer indexer = new ByPartIndexer(graph.getTypeSystem().getTypeHandle(SimpleBean.class), "strProp");
HGIndex<?, ?> theIndex = graph.getIndexManager().register(indexer);
x = new SimpleBean();
x.setStrProp("indexing");
graph.add(x);
// The index should be empty here
Assert.assertEquals(theIndex.count(), 0);
}
示例15: testNewIndexWithoutExistingData
import org.hypergraphdb.indexing.ByPartIndexer; //导入依赖的package包/类
@Test
public void testNewIndexWithoutExistingData()
{
cleanup();
HGIndexer indexer = new ByPartIndexer(graph.getTypeSystem().getTypeHandle(SimpleBean.class), "strProp");
HGIndex<?, ?> theIndex = graph.getIndexManager().register(indexer);
SimpleBean x = new SimpleBean();
x.setStrProp("indexing");
graph.add(x);
// The index should contain exactly one element here:
Assert.assertEquals(theIndex.count(), 1);
}