Biblioteca Java - Rev 18
Subversion Repositories:
(root)/Frameworks and Technologies/Neo4J Samples/Neo4JTutorial/src/main/java/com/linkscreens/graphsin/repository/CommentNode.java @ 21
package com.linkscreens.graphsin.repository;
import java.util.Date;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.helpers.collection.IteratorUtil;
/**
* A comment added to a social object.
* @author evo2
*
*/
public class CommentNode {
static final String TEXT = "TEXT";
static final String DATE = "DATE";
private final Node underlyingNode;
public CommentNode( Node underlyingNode )
{
this.underlyingNode = underlyingNode;
}
public Node getUnderlyingNode()
{
return underlyingNode;
}
public MediaItemNode getSocialObject()
{
return new MediaItemNode( getSocialObjectNode() );
}
private Node getSocialObjectNode()
{
TraversalDescription traversalDescription = underlyingNode.getGraphDatabase()
.traversalDescription()
.depthFirst()
.relationships( RelTypes.NEXT_COMMENT, Direction.INCOMING )
.relationships( RelTypes.COMMENT, Direction.INCOMING )
.evaluator( Evaluators.includeWhereLastRelationshipTypeIs( RelTypes.COMMENT ) );
Traverser traverser = traversalDescription.traverse( getUnderlyingNode() );
return IteratorUtil.singleOrNull( traverser.iterator() ).endNode();
}
public String getCommentText()
{
return (String) underlyingNode.getProperty( TEXT );
}
public Date getDate()
{
Long l = (Long) underlyingNode.getProperty( DATE );
return new Date( l );
}
}
import java.util.Date;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.traversal.Evaluators;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.graphdb.traversal.Traverser;
import org.neo4j.helpers.collection.IteratorUtil;
/**
* A comment added to a social object.
* @author evo2
*
*/
public class CommentNode {
static final String TEXT = "TEXT";
static final String DATE = "DATE";
private final Node underlyingNode;
public CommentNode( Node underlyingNode )
{
this.underlyingNode = underlyingNode;
}
public Node getUnderlyingNode()
{
return underlyingNode;
}
public MediaItemNode getSocialObject()
{
return new MediaItemNode( getSocialObjectNode() );
}
private Node getSocialObjectNode()
{
TraversalDescription traversalDescription = underlyingNode.getGraphDatabase()
.traversalDescription()
.depthFirst()
.relationships( RelTypes.NEXT_COMMENT, Direction.INCOMING )
.relationships( RelTypes.COMMENT, Direction.INCOMING )
.evaluator( Evaluators.includeWhereLastRelationshipTypeIs( RelTypes.COMMENT ) );
Traverser traverser = traversalDescription.traverse( getUnderlyingNode() );
return IteratorUtil.singleOrNull( traverser.iterator() ).endNode();
}
public String getCommentText()
{
return (String) underlyingNode.getProperty( TEXT );
}
public Date getDate()
{
Long l = (Long) underlyingNode.getProperty( DATE );
return new Date( l );
}
}