Search in sources :

Example 26 with Relationship

use of org.structr.api.graph.Relationship 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 });
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) NodeService(org.structr.core.graph.NodeService) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) AbstractCypherIndex(org.structr.bolt.index.AbstractCypherIndex) Index(org.structr.api.index.Index)

Aggregations

Relationship (org.structr.api.graph.Relationship)26 Node (org.structr.api.graph.Node)13 LinkedList (java.util.LinkedList)7 LinkedHashMap (java.util.LinkedHashMap)6 DatabaseService (org.structr.api.DatabaseService)6 GraphObject (org.structr.core.GraphObject)6 AbstractNode (org.structr.core.entity.AbstractNode)6 AbstractRelationship (org.structr.core.entity.AbstractRelationship)6 RelationshipFactory (org.structr.core.graph.RelationshipFactory)5 HashMap (java.util.HashMap)4 FrameworkException (org.structr.common.error.FrameworkException)4 List (java.util.List)3 Test (org.junit.Test)3 SessionTransaction (org.structr.bolt.SessionTransaction)3 RelationshipRelationshipMapper (org.structr.bolt.mapper.RelationshipRelationshipMapper)3 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 AbstractSchemaNode (org.structr.core.entity.AbstractSchemaNode)3 NodeFactory (org.structr.core.graph.NodeFactory)3 Tx (org.structr.core.graph.Tx)3