Comments (19)
不是的,比如说:
-
dao方法
ResultSet relationshipExpansionSubGraph( @Param("paramListWithSpace") List<Map<String, ?>> paramWithSpace );
-
beetl.properties 追加一行
# 之前的就不写了 # 声明你所需的函数 FN.my.fnName =your.domain.project.**.DynamicSpace
-
自定义方法体
@Component public class DynamicSpace extends AbstractFunction<Map<String, ?>, Void, Void, Void, Void, Void> { public DynamicSpace() { } public String call(Map<String, ?> paramWithSpace ) { // getter 表示:通过 paramWithSpace 获取到 space,需要自己根据情况实现 String spaceName = paramWithSpace.get( "spaceNameKey" ); return spaceName; } }
-
xml
<select id="relationshipExpansionSubGraph" resultType="com.vesoft.nebula.client.graph.data.ResultSet"> @for ( item in paramListWithSpace) { USE @my.fnName( item ); <!-- 遍写其他 gql --> @} </select>
通过现有的参数,把 spaceName 携带进来。
这样不光可以实现调用同一个接口方法使用不同的 space,
还可以实现调用一次接口方法,多次切换 space.
from ngbatis.
我是不知道是用哪个实体去接受的所以还是得用 List,因为我的业务都是动态查询,anyway,Thanks♪(・ω・)ノ
from ngbatis.
方便在下面的方法内断点看看入参吗?
所在类: MapperProxy
public static String getSpace(ClassModel cm, MethodModel mm) {
return mm != null && mm.getSpace() != null ? mm.getSpace()
: cm != null && cm.getSpace() != null ? cm.getSpace()
: ENV.getSpace();
}
from ngbatis.
是我的问题,idea缓存还是原来的beta版本。我重刷缓存就好了
请问可以动态的设置space吗?相当于 space="${spaceName}" 这样的
from ngbatis.
请问可以动态的设置space吗?相当于 space="${spaceName}" 这样的
是调用同一个 select 指定不同的 space 吗?
如果是 这个意思,你的 relationshipExpansionSubGraph 方法需要把 spaceName 做为方法参数传进来
然后在 xml 中使用,首行加一句:use `${spaceName}`;
但是这种方式可能会运行两次 use 语句,虽然会有一定的额外开销,但也是可以实现。
目前框架暂不支持根据实体自动获取 spaceName
from ngbatis.
好的
from ngbatis.
这边看到 relationshipExpansionSubGraph 使用 ResultSet 返回
如果对项目内特定的数据结构做处理又想把这个处理方式固化下来,可以声明一个类继承 AbstractResultHandler<T, Z>
。
只要 T,Z 跟现有的类型不冲突,并给上@ Component就行。
- T 是 接口的返回值类型(不包括泛型)
- Z 是 xml 中声明的 resultType(如果 resultType 与接口返回值类型一致,xml 中可以不用写)
from ngbatis.
请问可以动态的设置space吗?相当于 space="${spaceName}" 这样的
仔细想了下,现在的版本如果你想在运行时在同一个方法中使用不同的 space,又不想在方法上加 spaceName 的参数,可以使用自定义函数,从已有的入参中获取
新加自定义函数的方法:
-
在 resources 下建一个 beetl.properties 文件
-
文件内容为:
# Copyright (c) 2022 All project authors and nebula-contrib. All rights reserved. # # This source code is licensed under Apache 2.0 License. FN.ng.valueFmt =org.nebula.contrib.ngbatis.binding.beetl.functions.ValueFmtFn FN.ng.schemaFmt =org.nebula.contrib.ngbatis.binding.beetl.functions.SchemaFmtFn FN.ng.tagName =org.nebula.contrib.ngbatis.binding.beetl.functions.TagNameFn FN.ng.pkField =org.nebula.contrib.ngbatis.binding.beetl.functions.PkFieldFn FN.ng.pkName =org.nebula.contrib.ngbatis.binding.beetl.functions.PkNameFn FN.ng.entityType =org.nebula.contrib.ngbatis.binding.beetl.functions.EntityTypeFn FN.ng.fieldNames =org.nebula.contrib.ngbatis.binding.beetl.functions.FieldNamesFn FN.ng.id =org.nebula.contrib.ngbatis.binding.beetl.functions.IdFn FN.ng.kv =org.nebula.contrib.ngbatis.binding.beetl.functions.KvFn FN.ng.join = org.nebula.contrib.ngbatis.binding.beetl.functions.JoinFn FN.ng.ifStringLike = org.nebula.contrib.ngbatis.binding.beetl.functions.IfStringLike # 声明你所需的函数 FN.your.fnName =your.domain.project.**.YourCustomFunction
-
自建的类继承 AbstractFunction<A, B, C, D, E, F>
泛型为调用这个方法入参的类型
-
如果只有一个入参,则
public Object call(A param) { // A 需要写成实际的类型 // 从入参中获取到 spaceName return null; }
-
在xml中使用:@your.fnName( 参数a )
from ngbatis.
public class DynamicSpace extends AbstractFunction<Object, Void, Void, Void, Void, Void> {
public DynamicSpace() {
}
public String call(String param) {
return param;
}
}
<select id="relationshipExpansionSubGraph" space="@my.fnName(${spaceName})" resultType="com.vesoft.nebula.client.graph.data.ResultSet">
- 是这样吗?
from ngbatis.
感谢大佬提供示例和思路!这对我很有帮助
from ngbatis.
上面的例子不是很恰当
多次切换 space 的用法,更多的适用于 insert 或者 update 这样不需要返回值的操作。
但对 select 的操作,也相当于一次动态space。 因为 nebula 本身不支持多返回,只会返回最后一个 return 或 yeild
from ngbatis.
这边看到 relationshipExpansionSubGraph 使用 ResultSet 返回 如果对项目内特定的数据结构做处理又想把这个处理方式固化下来,可以声明一个类继承
AbstractResultHandler<T, Z>
。 只要 T,Z 跟现有的类型不冲突,并给上@ Component就行。
- T 是 接口的返回值类型(不包括泛型)
- Z 是 xml 中声明的 resultType(如果 resultType 与接口返回值类型一致,xml 中可以不用写)
想询问下对于这种返回的结构,我应该用什么 resultType去接受比较好?
from ngbatis.
你这边是想获取类似于
player101 - follow -> player102
这样的关系是吗
from ngbatis.
这个getSubgraph是 nodes:List edge:List,按照ResultSet的类型的话我是这样做才能取到值
for (int i = 0; i < resultSet.rowsSize(); i++) {
ResultSet.Record record = resultSet.rowValues(i);
ArrayList<ValueWrapper> nodes = record.get("nodes").asList();
ArrayList<ValueWrapper> relationships = record.get("relationships").asList();
System.out.println("nodes---------------------------");
for (ValueWrapper node : nodes) {
Node n = node.asNode();
System.out.println("n.tagNames() = " + n.tagNames());
for (String tagName : n.tagNames()) {
System.out.println("n.properties(tagName) = " + n.properties(tagName));
}
}
System.out.println("edges---------------------------");
for (ValueWrapper relationship : relationships) {
Relationship r = relationship.asRelationship();
System.out.println("r.properties() = " + r.properties());
}
}
- 我是想有没有其他的类型接受可以更好的直接解析出来
from ngbatis.
如果不知道字段的是什么类型的话,每次都还要 nodes.isList 和 relationship.isList 的判断,还要 as的转换,感觉很不方便,如果可以做到已经转好类型就好了
from ngbatis.
如果不知道字段的是什么类型的话,每次都还要 nodes.isList 和 relationship.isList 的判断,还要 as的转换,感觉很不方便,如果可以做到已经转好类型就好了
关于这个问题,你可以试试 ResultSetUtil.getValue
from ngbatis.
我自己也写了个转换类,你的工具类写的比我好哈哈我还是用你的
from ngbatis.
- 我是想有没有其他的类型接受可以更好的直接解析出来
关于这个问题,你可以试试下面的数据结构,自己新建一个类:
@Data
public class SubgraphResult {
private List<Player> nodes; // 与 xml 变量名相对应
private List<Relationship> relationships; // 与 xml 变量名相对应
// 我这边试了下 List<Follow> 没有成功... 可惜了
}
- xml 中
- resultType 使用 SubgraphResult
- dao 中
- List relationshipExpansionSubGraph( 参数 )
这样也就不需要自己做太多格式转换
from ngbatis.
如果都是动态的,直接返回 ResultSet 确实是个比较好的选择
from ngbatis.
Related Issues (20)
- go from语句 HOT 16
- error on dependency version HOT 9
- docs: searching in en docs is broken HOT 2
- No extra connection: All servers are broken. HOT 2
- 批量插入数据报错 HOT 1
- NebulaDaoBasic是否可以实现一个listEndNodes方法 HOT 3
- 支持 springboot 3.x 有时间计划嘛? HOT 8
- The problem and solution of the first query taking a long time. 第一次查询的性能问题及解决方法
- 两个脚本都基于 USE SPACE 动态切换图空间,第一个生效,第二个不生效。
- 微信丨NgBatis交流群 · NGC22 0611-29
- StackOverflowError HOT 5
- java.net.SocketException: Socket closed HOT 1
- ResultSet error: SyntaxError: syntax error near ` go ' HOT 7
- 返回值映射问题 HOT 1
- Create Session failed HOT 2
- 龙行龘龘,灯火万家
- 同mybatis-plus共用提示:java.lang.NullPointerException at org.nebula.contrib.ngbatis.proxy.MapperProxy.invoke(MapperProxy.java:74) HOT 2
- When using `@Transient` for entity classes, please do not use v1.2.2 for now
- nebula.ngbatis.password encryption with druid
- uplift nebula-java 3.8.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngbatis.