2

我目前正在使用 Neo4j TimeTree REST API,有没有办法导航到给定时间戳之前和之后的时间?我的决议是秒,我只是意识到如果分钟发生了变化,那么没有“下一个”关系将前一分钟的前一秒与当前的秒连接起来。这使得密码查询变得非常复杂,如果它已经可用,我只是不想再次重新发明轮子。在此先感谢您的回复,我们将不胜感激!

编辑

我必须再次重现丢失的 NEXT 关系问题,如下图所示。这从我第三次添加新的第二时间瞬间开始发生。

在此处输入图像描述

我实际上创建了一个 NodeEntity 来操作第二个节点。课程如下。

@NodeEntity(label = "Second")
public class TimeTreeSecond {
    @GraphId
    private Long id;

    private Integer value;

    @Relationship(type = "CREATED_ON", direction = Relationship.INCOMING)
    private FilterVersionChange relatedFilterVersionChange;

    @Relationship(type = "NEXT", direction = Relationship.OUTGOING)
    private TimeTreeSecond nextTimeTreeSecond;

    @Relationship(type = "NEXT", direction = Relationship.INCOMING)
    private TimeTreeSecond prevTimeTreeSecond;

    public TimeTreeSecond() {
    }

    public Long getId() {
        return id;
    }

    public void next(TimeTreeSecond nextTimeTreeSecond) {
        this.nextTimeTreeSecond = nextTimeTreeSecond;
    }

    public FilterVersionChange getRelatedFilterVersionChange() {
        return relatedFilterVersionChange;
    }
}

这里的问题是 Incoming NEXT 关系。当我省略它时,一切正常。有时,当我以短暂的延迟重复创建时间瞬间时,我什至会在控制台中遇到这种异常。

Exception in thread "main" org.neo4j.ogm.session.result.ResultProcessingException: Could not initialise response
    at org.neo4j.ogm.session.response.GraphModelResponse.<init>(GraphModelResponse.java:38)
    at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRequestHandler.java:55)
    at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:108)
    at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:100)
    at org.springframework.data.neo4j.repository.GraphRepositoryImpl.findOne(GraphRepositoryImpl.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:452)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:437)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:409)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy32.findOne(Unknown Source)
    at de.rwthaachen.service.core.FilterDefinitionServiceImpl.createNewFilterVersionChange(FilterDefinitionServiceImpl.java:100)
    at sampleapp.FilterLauncher.main(FilterLauncher.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.neo4j.ogm.session.result.ResultProcessingException: "errors":[{"code":"Neo.ClientError.Statement.InvalidType","message":"Expected a numeric value for empty iterator, but got null"}]}
    at org.neo4j.ogm.session.response.JsonResponse.parseErrors(JsonResponse.java:128)
    at org.neo4j.ogm.session.response.JsonResponse.parseColumns(JsonResponse.java:102)
    at org.neo4j.ogm.session.response.JsonResponse.initialiseScan(JsonResponse.java:46)
    at org.neo4j.ogm.session.response.GraphModelResponse.initialiseScan(GraphModelResponse.java:66)
    at org.neo4j.ogm.session.response.GraphModelResponse.<init>(GraphModelResponse.java:36)
    ... 27 more
2015-05-23 01:30:46,204  INFO ork.data.neo4j.config.Neo4jConfiguration:  62 - Intercepted exception

下面是我用来创建时间即时节点的一个 REST 调用示例: http://localhost:7474/graphaware/timetree/1202/single/1432337658713?resolution=Second&timezone=Europe/Amsterdam

我用来创建数据的方法:

public FilterVersionChange createNewFilterVersionChange(String projectName,
                                                            String filterVersionName,
                                                            String filterVersionChangeDescription,
                                                            Set<FilterState> filterStates)
    {
        Long filterVersionNodeId = filterVersionRepository.findFilterVersionByName(projectName, filterVersionName);
        FilterVersion newFilterVersion = filterVersionRepository.findOne(filterVersionNodeId, 2);

        // Populate all the existing filters in the current project
        Map<String, Filter> existingFilters = new HashMap<String, Filter>();
        try
        {
            for(Filter filter : newFilterVersion.getProject().getFilters())
            {
                existingFilters.put(filter.getMatchingString(), filter);
            }
        }
        catch(Exception e) {}

        // Map the filter states to the populated filters, if any. Otherwise, create new filter for it.
        for(FilterState filterState : filterStates)
        {
            Filter filter = existingFilters.get(filterState.getMatchingString());
            if(filter == null)
            {
                filter = new Filter(filterState.getMatchingString(), filterState.getMatchingType(), newFilterVersion.getProject());
            }
            filterState.stateOf(filter);
        }

        Long now = System.currentTimeMillis();
        TimeTreeSecond timeInstantNode = timeTreeSecondRepository.findOne(timeTreeService.getFilterTimeInstantNodeId(projectName, now));
        FilterVersionChange filterVersionChange = new FilterVersionChange(filterVersionChangeDescription, now, filterStates, filterStates, newFilterVersion, timeInstantNode);
        FilterVersionChange addedFilterVersionChange = filterVersionChangeRepository.save(filterVersionChange);

        return addedFilterVersionChange;
    }
4

2 回答 2

4

秒通过 NEXT 关系相互链接,甚至跨分钟。

希望这就是你的意思 在此处输入图像描述

于 2015-05-22T13:36:54.477 回答
4

暂且不谈 TimeTree 的具体用途,我想描述一下如何使用 SDN 4 来管理双向链表,特别是针对底层图在节点之间使用单一关系类型的情况,例如

(post:Post)-[:NEXT]->(post:Post)

你不能做什么

由于映射框架的限制,不可能在对象模型的两个不同方向上可靠地声明相同的关系类型两次,即(目前)这不起作用:

class Post {
   @Relationship(type="NEXT", direction=Relationship.OUTGOING)
   Post next;

   @Relationship(type="NEXT", direction=Relationship.INCOMING)
   Post previous;
}

你可以做什么

相反,我们可以将 @Transient 注释与使用带注释的 setter 方法结合起来以获得所需的结果:

class Post {
   Post next;

   @Transient Post previous;

   @Relationship(type="NEXT", direction=Relationship.OUTGOING)
   public void setNext(Post next) {
      this.next = next;
      if (next != null) {
          next.previous = this;
      }
   }
}

最后一点,如果您希望能够从任何起始帖子中前后导航整个帖子列表,而不必不断从数据库中重新获取它们,您可以在加载时将提取深度设置为 -1帖子,例如:

findOne(post.getId(), -1);

请记住,无限深度查询将从匹配的对象中获取图中的每个可到达对象,因此请谨慎使用!

希望这会有所帮助

于 2015-05-24T08:17:29.820 回答