use of org.neo4j.graphdb.PropertyContainer in project blueprints by tinkerpop.
the class Neo4jGraph method dropInternalIndexKey.
private <T extends Element> void dropInternalIndexKey(final String key, final Class<T> elementClass) {
final String propertyName = elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX;
if (rawGraph instanceof GraphDatabaseAPI) {
final PropertyContainer pc = ((GraphDatabaseAPI) this.rawGraph).getNodeManager().getGraphProperties();
try {
final String[] keys = (String[]) pc.getProperty(propertyName);
final Set<String> temp = new HashSet<String>(Arrays.asList(keys));
temp.remove(key);
pc.setProperty(propertyName, temp.toArray(new String[temp.size()]));
} catch (Exception e) {
// no indexed_keys kernel data property
}
} else {
logNotGraphDatabaseAPI();
}
}
use of org.neo4j.graphdb.PropertyContainer in project blueprints by tinkerpop.
the class Neo4jGraph method createInternalIndexKey.
private <T extends Element> void createInternalIndexKey(final String key, final Class<T> elementClass) {
final String propertyName = elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX;
if (rawGraph instanceof GraphDatabaseAPI) {
final PropertyContainer pc = ((GraphDatabaseAPI) this.rawGraph).getNodeManager().getGraphProperties();
try {
final String[] keys = (String[]) pc.getProperty(propertyName);
final Set<String> temp = new HashSet<String>(Arrays.asList(keys));
temp.add(key);
pc.setProperty(propertyName, temp.toArray(new String[temp.size()]));
} catch (Exception e) {
// no indexed_keys kernel data property
pc.setProperty(propertyName, new String[] { key });
}
} else {
throw new UnsupportedOperationException("Unable to create an index on a non-GraphDatabaseAPI graph");
}
}
use of org.neo4j.graphdb.PropertyContainer in project blueprints by tinkerpop.
the class Neo4jBatchGraph method populateKeyIndices.
private static <T extends PropertyContainer> void populateKeyIndices(final GraphDatabaseService rawGraphDB, final AutoIndexer<T> rawAutoIndexer, final Iterable<T> rawElements, final Class elementClass) {
if (!rawAutoIndexer.isEnabled())
return;
final Set<String> properties = rawAutoIndexer.getAutoIndexedProperties();
Transaction tx = rawGraphDB.beginTx();
final PropertyContainer kernel = ((GraphDatabaseAPI) rawGraphDB).getNodeManager().getGraphProperties();
kernel.setProperty(elementClass.getSimpleName() + INDEXED_KEYS_POSTFIX, properties.toArray(new String[properties.size()]));
int count = 0;
for (final PropertyContainer pc : rawElements) {
for (final String property : properties) {
if (!pc.hasProperty(property))
continue;
pc.setProperty(property, pc.getProperty(property));
count++;
if (count >= 10000) {
count = 0;
tx.success();
tx.finish();
tx = rawGraphDB.beginTx();
}
}
}
tx.success();
tx.finish();
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j-mobile-android by neo4j-contrib.
the class Util method constructAllPathsToNodeAsLinkedLists.
/**
* Same as constructAllPathsToNode, but different return type
*/
protected static List<LinkedList<PropertyContainer>> constructAllPathsToNodeAsLinkedLists(Node node, Map<Node, List<Relationship>> predecessors, boolean includeNode, boolean backwards) {
List<LinkedList<PropertyContainer>> paths = new LinkedList<LinkedList<PropertyContainer>>();
List<Relationship> current = predecessors.get(node);
// First build all paths to this node's predecessors
if (current != null) {
for (Relationship r : current) {
Node n = r.getOtherNode(node);
List<LinkedList<PropertyContainer>> newPaths = constructAllPathsToNodeAsLinkedLists(n, predecessors, true, backwards);
paths.addAll(newPaths);
// Add the relationship
for (LinkedList<PropertyContainer> path : newPaths) {
if (backwards) {
path.addFirst(r);
} else {
path.addLast(r);
}
}
}
}
// have this node added to it)
if (paths.isEmpty()) {
paths.add(new LinkedList<PropertyContainer>());
}
// Then add this node to all those paths
if (includeNode) {
for (LinkedList<PropertyContainer> path : paths) {
if (backwards) {
path.addFirst(node);
} else {
path.addLast(node);
}
}
}
return paths;
}
use of org.neo4j.graphdb.PropertyContainer in project neo4j-mobile-android by neo4j-contrib.
the class Util method constructSinglePathToNode.
/**
* Constructs a path to a given node, for a given set of predecessors. The
* result is a list of alternating Node/Relationship.
* @param node
* The start node
* @param predecessors
* The predecessors set
* @param includeNode
* Boolean which determines if the start node should be included
* in the paths
* @param backwards
* Boolean, if true the order of the nodes in the paths will be
* reversed
* @return A path as a list of alternating Node/Relationship.
*/
public static List<PropertyContainer> constructSinglePathToNode(Node node, Map<Node, List<Relationship>> predecessors, boolean includeNode, boolean backwards) {
LinkedList<PropertyContainer> path = new LinkedList<PropertyContainer>();
if (includeNode) {
if (backwards) {
path.addLast(node);
} else {
path.addFirst(node);
}
}
Node currentNode = node;
List<Relationship> currentPreds = predecessors.get(currentNode);
// Traverse predecessors until we have added a node without predecessors
while (currentPreds != null && currentPreds.size() != 0) {
// Get next node
Relationship currentRelationship = currentPreds.get(0);
currentNode = currentRelationship.getOtherNode(currentNode);
// Add current
if (backwards) {
path.addLast(currentRelationship);
path.addLast(currentNode);
} else {
path.addFirst(currentRelationship);
path.addFirst(currentNode);
}
// Continue with the next node
currentPreds = predecessors.get(currentNode);
}
return path;
}
Aggregations