Giter Site home page Giter Site logo

gremlin-plus's Introduction

Gremlin plus

AUR license GitHub Repo stars GitHub forks

主要解决以下问题

  • 释放对Vertex/Edge/Property标签MAGIC_CODE管理.
  • 简化Vertex/Edge对应实体类的Convert/Mapping逻辑.
  • 提供Vertex/Edge对应非序列化字段的对象缓存机制, 减少客户端显式声明多个缓存管理的开发成本开销, 并提供KeyGenerator/UnSerializedPropertyCache扩展插件接口.

参见相关的ogm(ferma、mybatis-plus、spring-data-xx)源码.

个人倾向mybatis-plus的api, jpa方面声明式的api对于图数据库的遍历不够灵活.

mybatis-plus的serializedLambda内部resolve方法不支持evaluate expression调试, 该问题在gremlin-plus中已提供解决方案.

@VertexLabel("<USER>")
public class User {
  @VertexProperty("[NAME]")
  private String name;
  @VertexProperty("[AGE]")
  private Long age;
}

public class Solution {

  public static void main(String[] args) {
    Graph graph = null;
    try (final GraphPlusTraversalSource g = graph.traversal(GraphPlusTraversalSource.class)) {
        g.addV(new User("bofa1ex", 23L));
        // or g.addV(User.class).property(User::getName, "bofa1ex").property(User::getAge, 23L).property(TheOther::Sth, "sth else");
        final Vertex vertex = g.V().hasLabel(User.class).has(User::getName, "bofa1ex").next();
        // or u wanna convert vertex/edge to bean directly.
        final User user = g.V().hasLabel(User.class).has(User::getName, "bofa1ex").toBean();
        // maybe need optional object which wrapper the destinition obj.
        final Optional<User> userOpt = g.V().hasLabel(User.class).has(User::getName, "bofa1ex").tryToBean();
        // maybe need beans collection/stream in normal.
        final List<User> users = g.V().hasLabel(User.class).has(User::getName, "bofa1ex").toBeanList();
        // maybe when u query the bean which is not exists, and u should try add it like that in below.
        final Optional<User> anonymousUserOpt = g.V().hasLabel(User.class).has(User::getName, "anonymous").tryToBean();
        if(!anonymousUserOpt.isPresent()){
            g.addV(User.builder().name("anonymous").build());
        }
        // but `gremlin-plus` supported `#getIfAbsent` api, u just need try it in the same situation in below.
        Pair<User,Vertex> userVertexPair = g.V().hasLabel(User.class).has(User::getName, "anonymous").getIfAbsent(
            User.builder().name("anonymous").build()
        );
        // u might be confused by this return value, why use tuple with bean and vertex, talk is cheap, see the code in below.
        g.addE(Follow.class).from(g.V().hasLabel(User.class).has(User::getName, "bofa1ex")).to(
            // when u wanna add edge from the vertex to the other vertex which maybe not exists.
            userVertexPair.getRight()
        ).tryNext();
        // i thought the update operation should follow the query operation in strictly, so that why i did not open the getIfPresent api.
    } catch (Exception ignored) {
    }
  }
}

更多samples参见example模块, 若有更多需求, 欢迎提issue/pr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.