use of org.structr.api.index.Index in project structr by structr.
the class Property method index.
@Override
public void index(final GraphObject entity, final Object value) {
if (entity instanceof AbstractNode) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractNode node = (AbstractNode) entity;
final Node dbNode = node.getNode();
final Index<Node> index = nodeService.getNodeIndex();
if (index != null) {
try {
index.remove(dbNode, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbNode, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
logger.warn("", t);
}
}
} else if (entity instanceof AbstractRelationship) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractRelationship rel = (AbstractRelationship) entity;
final Relationship dbRel = rel.getRelationship();
final Index<Relationship> index = nodeService.getRelationshipIndex();
if (index != null) {
try {
index.remove(dbRel, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbRel, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
}
}
}
}
Aggregations