Skip to content

Commit

Permalink
!71 一些文档内容修正和代码逻辑优化
Browse files Browse the repository at this point in the history
Merge pull request !71 from flytreeleft/bugfixes
  • Loading branch information
entropy-cloud authored and gitee-org committed Jul 31, 2024
2 parents 8ec8c6e + b5b1aa7 commit cf7db82
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 69 deletions.
12 changes: 7 additions & 5 deletions docs/compare/nop-vs-apijson.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ APIJSON中 `["contactIdList<>":38710]`等价于执行SQL过滤条件`json_contai
allowFilterOp="contains,eq">
<graphql:transFilter>
<filter:sql>
json_contains(o.contactIdList,${value})
json_contains( o.contactIdList, ${value} )
</filter:sql>
</graphql:transFilter>
</prop>
Expand All @@ -733,7 +733,7 @@ APIJSON中 `["contactIdList<>":38710]`等价于执行SQL过滤条件`json_contai
* 可以配置`<graphql:transFilter>`来执行转换逻辑。例子中时使用`filter.xlib`标签库中的`<filter:sql>`标签函数来动态生成SQL片段。
* 如果感觉上面的配置有些繁琐,可以利用Nop平台内置的元编程机制在编译期为JSON类型的字段统一生成相应的transFilter配置。这样看起来就像是原生支持json_contains运算符。

```
```xml
<prop name="contactIdList" allowFilterOp="json_contains"/>
```

Expand Down Expand Up @@ -766,7 +766,9 @@ APIJSON中,如下调用
<prop name="existsComment" allowFilterOp="exists">
<graphql:transFilter>
<filter:sql>
EXISTS(SELECT * FROM Comment o2 WHERE o2.momentId=${filter.getAttr('momentId')})
EXISTS(
SELECT * FROM Comment o2 WHERE o2.momentId= ${ filter.getAttr('momentId') }
)
</filter:sql>
</graphql:transFilter>
</prop>
Expand Down Expand Up @@ -802,7 +804,7 @@ APIJSON中,如下调用
* 可以使用inject函数从IoC容器中获取bean,或者使用import语法导入Java类。
* 可以利用XPL模板语言的标签抽象机制类简化调用。例如

```
```xml
<prop name="isPraised">
<getter>
<api:invoke name="isContains" args="${{praiseUserIdList, userId:entityId}}" />
Expand Down Expand Up @@ -911,7 +913,7 @@ Nop平台采用标准的ORM设计,一般要求先获取数据到Java内存中

对于少数需要直接在数据库中执行递增或者递减语法的情况,可以在XBiz模型中直接执行SQL语句来进行处理。

```
```xml
<action name="changeAmount">
<arg name="accountId" type="String" />
<arg name="delta" type="Double" />
Expand Down
30 changes: 16 additions & 14 deletions docs/dev-guide/graphql/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
```xml

<meta>
<prop name="resources" displayName="资源列表" i18n-en:displayName="Resources" tagSet="pub,connection"
ext:kind="to-many" internal="true" ext:joinLeftProp="siteId" ext:joinRightProp="siteId"
ext:joinRightDisplayProp="displayName" insertable="false" updatable="false" lazy="true">
<schema type="io.nop.orm.IOrmEntitySet&lt;io.nop.auth.dao.entity.NopAuthResource&gt;"
bizObjName="NopAuthResource"/>
</prop>
<!--LOC:[90:22:0:0]/nop/core/xlib/biz-gen.xlib#/_delta/default/nop/auth/model/NopAuthSite/NopAuthSite.xmeta-->
<prop name="resourcesConnection" displayName="资源列表" internal="true"
graphql:connectionProp="resources" graphql:queryMethod="findConnection">
<schema type="io.nop.api.core.beans.graphql.GraphQLConnection&lt;io.nop.auth.dao.entity.NopAuthResource&gt;"
bizObjName="NopAuthResource"/>
</prop>
<props>
<prop name="resources" displayName="资源列表" i18n-en:displayName="Resources" tagSet="pub,connection"
ext:kind="to-many" internal="true" ext:joinLeftProp="siteId" ext:joinRightProp="siteId"
ext:joinRightDisplayProp="displayName" insertable="false" updatable="false" lazy="true">
<schema type="io.nop.orm.IOrmEntitySet&lt;io.nop.auth.dao.entity.NopAuthResource&gt;"
bizObjName="NopAuthResource"/>
</prop>
<!--LOC:[90:22:0:0]/nop/core/xlib/biz-gen.xlib#/_delta/default/nop/auth/model/NopAuthSite/NopAuthSite.xmeta-->
<prop name="resourcesConnection" displayName="资源列表" internal="true"
graphql:connectionProp="resources" graphql:queryMethod="findConnection">
<schema type="io.nop.api.core.beans.graphql.GraphQLConnection&lt;io.nop.auth.dao.entity.NopAuthResource&gt;"
bizObjName="NopAuthResource"/>
</prop>
</props>
</meta>
```

Expand Down Expand Up @@ -81,7 +83,7 @@ query($filter1:Map, $filter2:Map){
items{
id
}
},
}

inactiveRecords: mySubObjectConnection(filter:$filter2, limit:5){
total
Expand All @@ -97,7 +99,7 @@ query($filter1:Map, $filter2:Map){

## REST请求时通过`_subArgs`简化传参方式

```
```json
/r/MyObject__get?id=3&@selection=activeRecords:mySubObjectConnection,inactiveRecords:mySubObjectConnection

{
Expand Down
12 changes: 6 additions & 6 deletions docs/dev-guide/orm/eql.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ select o.dept.name, u.type
from NopAuthUser o left join MyEntity u on o.id = u.userId

select o.dept.name, u.type
from NopAuthUser o , MyEntity u
from NopAuthUser o , MyEntity u
where o.id = u.userId

```
Expand All @@ -36,25 +36,25 @@ select o from NopAuthUser o limit 10 offset 0

## 4. for update语句

```
```sql
select o from NopAuthUser o where id = 1 for update
```

## 5. 删除语句

```
```sql
delete from NopAuthUser o wher o.id = 3
```

## 6. 更新语句

```
```sql
update NopAuthUser o set o.name = 'a' where o.id = 2
```

## 7. 插入语句

```
```sql
insert NopAuthUser(name, status) values('a',1)
```

Expand All @@ -76,4 +76,4 @@ insert NopAuthUser(name, status) values('a',1)
* `>>` : 右移位
* % : 取余
* ^
*
*
6 changes: 3 additions & 3 deletions docs/dev-guide/orm/orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NopORM是一个类似Hibernate的完整ORM引擎,因此它也是通过OrmSession来管理所有加载到内存中的实体对象。在同一个session中,只会按照id从数据库加载一次,然后得到的实体对象就会被缓存到session中。

```javascript
```java
MyEntity entity = dao.getEntityById("3");
List<MyEntity> entities = dao.findAll();
assertTrue(entityes.contains(entity));
Expand All @@ -19,9 +19,9 @@ assertTrue(entityes.contains(entity));
* 向集合对象中加入实体隐含的就表示该实体也要同步到数据库中,因此调用parent.getChildren().add(child)之后不需要再调用dao.saveEntity(child)来保存子实体。
* 从集合对象中删除实体会自动删除该实体,除非它的owner属性值被设置为null.

```
```java
parent.getChildren().remove(child);
// child.setParent(null);
// child.setParent(null);
```

如果不调用child.setParent(null),则从parent的children集合中删除child表示要从数据库中删除child。而如果设置了child的parent为null,则表示解除父实体和子实体的关联关系。
Expand Down
23 changes: 12 additions & 11 deletions docs/dev-guide/orm/sql-lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ sql模式针对SQL输出的情况做了特殊处理,主要增加了如下规

如果确实希望直接输出SQL文本,拼接到SQL语句中,可以使用raw函数来包装。

```
```sql
from MyEntity_${raw(postfix)} o
```

此外,NopOrm对于参数化SQL对象本身也建立了一个简单的包装模型

```
```java
SQL = Text + Params
```

Expand Down Expand Up @@ -228,21 +228,22 @@ XLang语言还内置了一些调试特性,方便在元编程阶段对问题进

3. 任何表达式都可以追加调用扩展函数`$`,它会自动打印当前表达式对应的文本、行号以及表达式执行的结果, 并返回表达式的结果值。例如

```
x = a.f().$(prefix) 实际对应于
```java
x = a.f().$(prefix)
// 实际对应于
x = DebugHelper.v(location,prefix, "a.f()",a.f())
```

## 7. 根据Dialect生成对应的SQL语句

利用标签库可以引入各种自定义的扩展逻辑。比如根据不同的数据库方言生成不同的SQL语句。

```
```xml
select
<sql:when-dialect name="h2">
...
</sql:when-dialect>
from my_entity
from my_entity
```

## 8. Mapper接口
Expand Down Expand Up @@ -327,8 +328,8 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提

也可以使用在构造SQL对象时直接指定enableFilter属性

```javascript
SQL sql = SQL.begin().enableFilter(true).sql("...").end();
```java
SQL sql = SQL.begin().enableFilter(true).sql("...").end();
```

启用enableFilter后,会自动利用`IServiceContext.bindingCtx()`获取当前上下文中的IServiceContext,并调用`IDataAuthChecker.getFilter()`
Expand All @@ -338,7 +339,7 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提
### allowUnderscoreName设置为true,将会允许在EQL中直接使用数据库字段名

```
```xml
<eql name="xx" allowUnderscoreName="true">
<source>
select o.statusId, o.status_id from MyEntity o
Expand All @@ -350,6 +351,6 @@ OrmSessionFactory支持IEntityFilterProvider配置,nop-auth-service模块提

也可以使用在构造SQL对象时直接指定allowUnderscoreName属性

```javascript
SQL.begin().allowUnderscoreName(true).sql("....").end();
```java
SQL.begin().allowUnderscoreName(true).sql("....").end();
```
27 changes: 17 additions & 10 deletions docs/dev-guide/recipe/filter-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

XView模型中定义的grid可以配置filter条件,使用该grid生成的表格查询数据时会自动携带过滤条件。

```
```xml
<grid id="list">
<cols>
...
Expand All @@ -51,7 +51,7 @@ XView模型中定义的grid可以配置filter条件,使用该grid生成的表

xmeta配置文件中可以配置filter过滤条件。如果在meta中配置,则新增、修改的时候也会按照这里的过滤条件自动设置。例如

```
```xml
<filter>
<eq name="type" value="1" />
</filter>
Expand All @@ -61,7 +61,7 @@ xmeta配置文件中可以配置filter过滤条件。如果在meta中配置,

基于已有的xmeta,可以新建xmeta。例如 MyEntity\_ext.xmeta

```
```xml
<meta x:extends="MyEntity.xmeta">
<filter>
<eq name="type" value="1" />
Expand All @@ -71,7 +71,7 @@ xmeta配置文件中可以配置filter过滤条件。如果在meta中配置,

前台调用时使用对象名`MyEntity_ext`就会自动应用这里的meta。例如

```
```graphql
query{
MyEntity_ext__findPage{
...
Expand All @@ -83,7 +83,7 @@ query{

## 4. 在后台BizModel中增加新的方法

```
```java
class MyEntityBizModel extends CrudBizModel<MyEntity>{
@BizQuery
@GraphQLReturn(bizObjName = BIZ_OBJ_NAME_THIS_OBJ)
Expand All @@ -103,7 +103,7 @@ class MyEntityBizModel extends CrudBizModel<MyEntity>{

在前台可以继承已有的页面,然后定制其中的api数据请求链接

```
```xml
<form id="edit">
<cells>
<cell id="productId">
Expand All @@ -126,7 +126,10 @@ class MyEntityBizModel extends CrudBizModel<MyEntity>{
<filter>
<eq name="type" value="${3}" />
<filter:sql xpl:lib="/nop/core/xlib/filter.xlib">
o.id in (select t.task.id from MyTask t where t.userId = ${$context.userId || '1'})
o.id in (
select t.task.id from MyTask t
where t.userId = ${ $context.userId || '1' }
)
</filter:sql>
</filter>
```
Expand All @@ -137,7 +140,10 @@ class MyEntityBizModel extends CrudBizModel<MyEntity>{

```sql
o.type = 3
and o.id in (select t.task.id from MyTask t where t.userId = ${$context.userId || '1'})
and o.id in (
select t.task.id from MyTask t
where t.userId = ${ $context.userId || '1' }
)
```

> sql节点的value属性必须是SQL类型,不能是简单的文本字符串,这样约定的目的是避免前台提交filter查询条件插入子查询形成SQL注入攻击。要求value必须是SQL类型,就只能是在后台通过程序来构造。
Expand Down Expand Up @@ -242,8 +248,9 @@ QueryBean提供了transformFilter函数,可以对前台提交的查询条件
<prop name="myCustomFilter" queryable="true">
<graphql:transFilter>
<filter:sql>
exists(select o2 from NopAuthResource o2 where o2.siteId= o.id
and o2.status >= ${filter.getAttr('value')})
exists( select o2 from NopAuthResource o2 where o2.siteId= o.id
and o2.status >= ${ filter.getAttr('value') }
)
</filter:sql>
</graphql:transFilter>
</prop>
Expand Down
Loading

0 comments on commit cf7db82

Please sign in to comment.