Spring Data Neo4J和GraphAware TimeTree

时间:2015-07-23 18:49:44

标签: neo4j spring-data-neo4j graphaware

有没有人使用他们的Java API使用GraphAware TimeTree和Spring Data Neo4J一起使用,可以提供一个简单的例子吗?

2 个答案:

答案 0 :(得分:1)

GraphAware扩展是服务器端代码,Spring Data Neo4j是客户端。请记住,您可以使用与herehere相同的行来注释使用SDN的Java类(假设v4),以使映射与TimeTree结构匹配。

也就是说,SDN(v4)还没有明确支持非托管扩展和事务事件处理程序(GraphAware Framework都是这些),因此您需要自己处理。例如,如果您使用TimeTree自动附件功能并从SDN保留事件,则需要重新加载它才能获取TimeTree节点。

答案 1 :(得分:1)

这是我的第一个存储库类。似乎工作,但迈克尔或Luanne(或某人)可能能够显着改善这一点。我还没有在范围内包含对事件的查询,但它们即将到来。

关于这里的内容的几点说明:

timeType参数是域节点和时间树之间关系的名称。

package myproject.core.repository.timeline;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import myproject.BaseNode;

@Repository
public interface TimelineRepository extends Neo4jRepository<BaseNode> {

// Attaches a node to the time tree
    @Query("match (e:Event {domainId: {domainId}}) with e call ga.timetree.events.attach({node: e, time: {timestamp}, resolution: 'MILLISECOND', relationshipType: {timeType}}) yield node return node;")
    public void setTime(@Param("domainId") String domainId, @Param("timeType") String typeType, @Param("timestamp") Long timestamp);

// Detaches a node from the timetree
    @Query("match (e:Event {domainId: {domainId}})-[s]-() where type(s) = {timeType} delete s;")
    public void unsetTime(@Param("domainId") String domainId, @Param("timeType") String timeType);
}

以下是我在neo4j.conf中的配置。我正在使用neo4j 3.0.6。我在这里写的几乎所有内容都直接来自https://github.com/graphaware/neo4j-timetree的文档。

#For the framework to work at all, you need this
dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware

# Runtime must be enabled like this
com.graphaware.runtime.enabled=true

# A Runtime module that takes care of attaching the events like this (TT is the ID of the module)
com.graphaware.module.TT.1=com.graphaware.module.timetree.module.TimeTreeModuleBootstrapper

# autoAttach must be set to true
com.graphaware.module.TT.autoAttach=true

#Uncommenting this prevents properties of our Event class from persisting
# Optionally, nodes which represent events and should be attached automatically have to be defined (defaults to nodes with label Event)
#com.graphaware.module.TT.event=hasLabel('Message')

# Optionally, a property on the event nodes that represents the the time (long) at which the event took place must be specified (defaults to "timestamp")
#com.graphaware.module.TT.timestamp=time

# Optionally, a property on the event nodes that represents the node ID (long) of the root node for the tree, to which the event should be attached (defaults to "timeTreeRootId")
#com.graphaware.module.TT.customTimeTreeRootProperty=rootId

# Optionally, a resolution can be specified (defaults to DAY)
#com.graphaware.module.TT.resolution=MILLISECOND

# Optionally, a time zone can be specified (defaults to UTC)
#com.graphaware.module.TT.timezone=GMT+1

# Optionally, a relationship type with which the events will be attached to the tree can be specified (defaults to AT_TIME)
#com.graphaware.module.TT.relationship=SENT_ON

# Optionally, a relationship direction (from the tree's point of view), with which the events will be attached to the tree can be specified (defaults to INCOMING)
#com.graphaware.module.TT.direction=INCOMING

你应该能够创建看起来像这样的东西(以最简单的形式)..

Event example