@Override public Info<EGraphType> GetObject(String name, Object value) { ReadableIndex<Node> node_auto_index = graph.GetInnerIndex() .getNodeAutoIndexer().getAutoIndex(); IndexHits<Node> iterator = node_auto_index.get(name, value); if(!iterator.hasNext()) throw new ExceptionModelFail ("element not found " + name + " with value " + value); Info<EGraphType> obj_uid = new Info<>(iterator.next().getId(), EGraphType.OBJECT); if(iterator.hasNext()) throw new ExceptionModelFail ("more than one element match the criteria: " + name + " " + value.toString()); return obj_uid; }
@Override public Info<EGraphType> GetLink(String name, Object value) { ReadableIndex<Relationship> rel_auto_index = graph.GetInnerIndex() .getRelationshipAutoIndexer().getAutoIndex(); IndexHits<Relationship> iterator = rel_auto_index.get(name, value); if(!iterator.hasNext()) throw new ExceptionModelFail ("element not found" + name); Info<EGraphType> link_uid = new Info<>(iterator.next().getId(), EGraphType.LINK); if(iterator.hasNext()) throw new ExceptionModelFail ("more than one element match the criteria: " + name + " " + value.toString()); return link_uid; }
/** * Search an identifier in the database using the hash of the given identifier * * @param id */ @Override public InternalIdentifier findIdentifier(InternalIdentifier id) { ReadableIndex<Node> ri = mConnection.getConnection().index().getNodeAutoIndexer().getAutoIndex(); String hash = calcHash(id); log.trace("Looking for Identifier with hash " +hash+ " in the database ..."); Node n = ri.get(KEY_HASH, hash).getSingle(); if (n == null) { log.trace("Identifier is not in the database"); return null; } else { log.trace("Found Identifier in the database"); Neo4JIdentifier neoId = new Neo4JIdentifier(n, this); return neoId; } }
@Test public void testChangesAreVisibleInTransaction() { AutoIndexer<Node> autoIndexer = graphDb.index().getNodeAutoIndexer(); autoIndexer.startAutoIndexingProperty( "nodeProp" ); autoIndexer.setEnabled( true ); newTransaction(); Node node1 = graphDb.createNode(); node1.setProperty( "nodeProp", "nodePropValue" ); node1.setProperty( "nodePropNonIndexable", "valueWhatever" ); ReadableIndex<Node> nodeIndex = autoIndexer.getAutoIndex(); assertEquals( node1, nodeIndex.get( "nodeProp", "nodePropValue" ).getSingle() ); newTransaction(); Node node2 = graphDb.createNode(); node2.setProperty( "nodeProp", "nodePropValue2" ); assertEquals( node2, nodeIndex.get( "nodeProp", "nodePropValue2" ).getSingle() ); node2.setProperty( "nodeProp", "nodePropValue3" ); assertEquals( node2, nodeIndex.get( "nodeProp", "nodePropValue3" ).getSingle() ); node2.removeProperty( "nodeProp" ); assertFalse( nodeIndex.get( "nodeProp", "nodePropValue2" ).hasNext() ); assertFalse( nodeIndex.get( "nodeProp", "nodePropValue3" ).hasNext() ); newTransaction(); assertEquals( node1, nodeIndex.get( "nodeProp", "nodePropValue" ).getSingle() ); assertFalse( nodeIndex.get( "nodeProp", "nodePropValue2" ).hasNext() ); assertFalse( nodeIndex.get( "nodeProp", "nodePropValue3" ).hasNext() ); }
@Test public void testDefaultsAreSeparateForNodesAndRelationships() throws Exception { stopDb(); config = new HashMap<>(); config.put( GraphDatabaseSettings.node_keys_indexable.name(), "propName" ); config.put( GraphDatabaseSettings.node_auto_indexing.name(), "true" ); // Now only node properties named propName should be indexed. startDb(); newTransaction(); Node node1 = graphDb.createNode(); Node node2 = graphDb.createNode(); node1.setProperty( "propName", "node1" ); node2.setProperty( "propName", "node2" ); node2.setProperty( "propName_", "node2" ); Relationship rel = node1.createRelationshipTo( node2, DynamicRelationshipType.withName( "DYNAMIC" ) ); rel.setProperty( "propName", "rel1" ); newTransaction(); ReadableIndex<Node> autoIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); assertEquals( node1, autoIndex.get( "propName", "node1" ).getSingle() ); assertEquals( node2, autoIndex.get( "propName", "node2" ).getSingle() ); assertFalse( graphDb.index().getRelationshipAutoIndexer().getAutoIndex().get( "propName", "rel1" ).hasNext() ); }
@Override public List<Info<EGraphType>> GetObjects(String name, Object value) { ReadableIndex<Node> node_auto_index = graph.GetInnerIndex() .getNodeAutoIndexer().getAutoIndex(); return Neo4jIndex.FromNodeIndex(node_auto_index.get(name, value)); }
@Override public List<Info<EGraphType>> GetLinks(String name, Object value) { ReadableIndex<Relationship> rel_auto_index = graph.GetInnerIndex() .getRelationshipAutoIndexer().getAutoIndex(); return Neo4jIndex.FromRelIndex(rel_auto_index.get(name, value)); }
@Override public List<Info<EGraphType>> QueryObjects(String name, String pattern) { ReadableIndex<Node> node_auto_index = graph.GetInnerIndex() .getNodeAutoIndexer().getAutoIndex(); return Neo4jIndex.FromNodeIndex(node_auto_index.query(name, pattern)); }
@Override public List<Info<EGraphType>> QueryLinks(String name, String pattern) { ReadableIndex<Relationship> rel_auto_index = graph.GetInnerIndex() .getRelationshipAutoIndexer().getAutoIndex(); return Neo4jIndex.FromRelIndex(rel_auto_index.query(name, pattern)); }
private ResultIterator<Map<String, Object>> execute(final String lucene, final Class<?> type, final Map<String, Object> parameters) { final IndexHits<Node> hits; if (!graphDb.index().getNodeAutoIndexer().isEnabled() && type != null) { final Index<Node> nodeIndex = graphDb.index().forNodes(type.getName()); hits = nodeIndex.query(lucene); } else { final ReadableIndex<Node> autoNodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); hits = autoNodeIndex.query(lucene); } return new ResultIterator<Map<String, Object>>() { @Override public boolean hasNext() { return hits.hasNext(); } @Override public Map<String, Object> next() { final Map<String, Object> result = new HashMap<String, Object>(); result.put("result", hits.next()); return result; } @Override public void remove() { throw new XOException("Remove operation is not supported for query results."); } @Override public void close() { hits.close(); } }; }
/** * * @param map * Containing test data. Looks like: type rawData properties * (properties map) * @param db * The Graphdatabase which should be filled with test data. * @return Node of the identifier. */ @SuppressWarnings("unchecked") private static Node searchOrCreateIdentifier(HashMap<String, Object> map, GraphDatabaseService db) { Node id = null; ReadableIndex<Node> ri = db.index().getNodeAutoIndexer().getAutoIndex(); id = ri.get(KEY_HASH, map.get("rawData")).getSingle(); if (id == null) { try (Transaction tx = db.beginTx()) { id = db.createNode(); id.addLabel(Neo4JTypeLabels.IDENTIFIER); id.setProperty(KEY_TYPE_NAME, map.get("type")); id.setProperty(KEY_RAW_DATA, map.get("rawData")); HashMap<String, Object> properties = (HashMap<String, Object>) map .get("properties"); for (String key : properties.keySet()) { id.setProperty(key, properties.get(key)); } id.setProperty(KEY_HASH, map.get("rawData")); tx.success(); } } return id; }
@Override public ReadableIndex<T> getAutoIndex() { return new IndexWrapper<T>( getIndexInternal() ); }
public ReadOnlyIndexToIndexAdapter( ReadableIndex<T> delegate ) { this.delegate = delegate; }