FilterJoinNode优化
This commit is contained in:
@@ -46,7 +46,7 @@ public class FilterJoinNode extends FilterNode {
|
|||||||
this.joinClass = joinClass;
|
this.joinClass = joinClass;
|
||||||
this.joinColumns = joinColumns;
|
this.joinColumns = joinColumns;
|
||||||
this.column = column;
|
this.column = column;
|
||||||
this.express = express == null ? EQ : express;
|
this.express = express == null ? EQ : FilterNodes.oldExpress(express);
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,20 +57,24 @@ public class FilterJoinNode extends FilterNode {
|
|||||||
this.nodes = node.nodes;
|
this.nodes = node.nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(since = "2.8.0")
|
||||||
public static FilterJoinNode create(Class joinClass, String joinColumn, String column, Serializable value) {
|
public static FilterJoinNode create(Class joinClass, String joinColumn, String column, Serializable value) {
|
||||||
return create(joinClass, new String[]{joinColumn}, column, value);
|
return FilterNodes.joinInner(joinClass, new String[]{joinColumn}, column, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(since = "2.8.0")
|
||||||
public static FilterJoinNode create(Class joinClass, String joinColumn, String column, FilterExpress express, Serializable value) {
|
public static FilterJoinNode create(Class joinClass, String joinColumn, String column, FilterExpress express, Serializable value) {
|
||||||
return create(joinClass, new String[]{joinColumn}, column, express, value);
|
return FilterNodes.joinInner(joinClass, new String[]{joinColumn}, column, express, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(since = "2.8.0")
|
||||||
public static FilterJoinNode create(Class joinClass, String[] joinColumns, String column, Serializable value) {
|
public static FilterJoinNode create(Class joinClass, String[] joinColumns, String column, Serializable value) {
|
||||||
return create(joinClass, joinColumns, column, null, value);
|
return FilterNodes.joinInner(joinClass, joinColumns, column, null, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(since = "2.8.0")
|
||||||
public static FilterJoinNode create(Class joinClass, String[] joinColumns, String column, FilterExpress express, Serializable value) {
|
public static FilterJoinNode create(Class joinClass, String[] joinColumns, String column, FilterExpress express, Serializable value) {
|
||||||
return new FilterJoinNode(joinClass, joinColumns, column, express, value);
|
return FilterNodes.joinInner(joinClass, joinColumns, column, express, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -86,22 +90,22 @@ public class FilterJoinNode extends FilterNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FilterNode any(final FilterNode node0, boolean signor) {
|
protected FilterNode any(final FilterNode node0, boolean isOr) {
|
||||||
Objects.requireNonNull(node0);
|
Objects.requireNonNull(node0);
|
||||||
if (!(node0 instanceof FilterJoinNode)) {
|
if (!(node0 instanceof FilterJoinNode)) {
|
||||||
throw new IllegalArgumentException(this + (signor ? " or " : " and ") + " a node but "
|
throw new IllegalArgumentException(this + (isOr ? " or " : " and ") + " a node but "
|
||||||
+ String.valueOf(node0) + " is not a " + FilterJoinNode.class.getSimpleName());
|
+ String.valueOf(node0) + " is not a " + FilterJoinNode.class.getSimpleName());
|
||||||
}
|
}
|
||||||
final FilterJoinNode node = (FilterJoinNode) node0;
|
final FilterJoinNode node = (FilterJoinNode) node0;
|
||||||
if (this.nodes == null) {
|
if (this.nodes == null) {
|
||||||
this.nodes = new FilterNode[]{node};
|
this.nodes = new FilterNode[]{node};
|
||||||
this.or = signor;
|
this.or = isOr;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (or == signor || this.column == null) {
|
if (or == isOr || this.column == null) {
|
||||||
this.nodes = Utility.append(this.nodes, node);
|
this.nodes = Utility.append(this.nodes, node);
|
||||||
if (this.column == null) {
|
if (this.column == null) {
|
||||||
this.or = signor;
|
this.or = isOr;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -112,7 +116,7 @@ public class FilterJoinNode extends FilterNode {
|
|||||||
this.joinClass = null;
|
this.joinClass = null;
|
||||||
this.joinEntity = null;
|
this.joinEntity = null;
|
||||||
this.joinColumns = null;
|
this.joinColumns = null;
|
||||||
this.or = signor;
|
this.or = isOr;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public final class FilterNodeBean<T extends FilterBean> implements Comparable<Fi
|
|||||||
if (this.joinClass == null) {
|
if (this.joinClass == null) {
|
||||||
node = FilterNodes.create(column, express, val);
|
node = FilterNodes.create(column, express, val);
|
||||||
} else {
|
} else {
|
||||||
node = FilterJoinNode.create(joinClass, joinColumns, column, express, val);
|
node = FilterNodes.joinInner(joinClass, joinColumns, column, express, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -502,7 +502,25 @@ public final class FilterNodes {
|
|||||||
public static <T, F extends FilterValue> FilterNode fvdiv(LambdaFunction<T, F> func, F value) {
|
public static <T, F extends FilterValue> FilterNode fvdiv(LambdaFunction<T, F> func, F value) {
|
||||||
return new FilterNode(LambdaFunction.readColumn(func), FV_DIV, value);
|
return new FilterNode(LambdaFunction.readColumn(func), FV_DIV, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public static FilterJoinNode joinInner(Class joinClass, String joinColumn, String column, Serializable value) {
|
||||||
|
return joinInner(joinClass, new String[]{joinColumn}, column, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FilterJoinNode joinInner(Class joinClass, String joinColumn, String column, FilterExpress express, Serializable value) {
|
||||||
|
return joinInner(joinClass, new String[]{joinColumn}, column, express, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FilterJoinNode joinInner(Class joinClass, String[] joinColumns, String column, Serializable value) {
|
||||||
|
return joinInner(joinClass, joinColumns, column, null, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FilterJoinNode joinInner(Class joinClass, String[] joinColumns, String column, FilterExpress express, Serializable value) {
|
||||||
|
return new FilterJoinNode(joinClass, joinColumns, column, express, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
static FilterExpress oldExpress(FilterExpress express) {
|
static FilterExpress oldExpress(FilterExpress express) {
|
||||||
switch (express) {
|
switch (express) {
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ public class FilterNodeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
final CarTestBean bean = CarTestBean.create();
|
final CarTestBean bean = CarTestBean.create();
|
||||||
FilterNode joinNode1 = FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
FilterNode joinNode1 = FilterNodes.joinInner(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
||||||
.or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GT, bean.createtime));
|
.or(FilterNodes.joinInner(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GT, bean.createtime));
|
||||||
FilterNode joinNode2 = FilterJoinNode.create(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename);
|
FilterNode joinNode2 = FilterNodes.joinInner(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename);
|
||||||
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNodes.gt("carid", bean.carid).and(joinNode1).or(joinNode2);
|
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNodes.gt("carid", bean.carid).and(joinNode1).or(joinNode2);
|
||||||
final FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
final FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||||
System.out.println("node.string = " + node);
|
System.out.println("node.string = " + node);
|
||||||
|
|||||||
Reference in New Issue
Block a user