001/* 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.field; 017 018import com.mybatisflex.core.util.FieldWrapper; 019 020import java.io.Serializable; 021 022/** 023 * 查询属性的信息。 024 */ 025@SuppressWarnings("rawtypes") 026public class FieldQuery implements Serializable { 027 028 private Class<?> entityClass; 029 private String fieldName; 030 private FieldWrapper fieldWrapper; 031 private boolean prevent; 032 private QueryBuilder queryBuilder; 033 034 public Class<?> getEntityClass() { 035 return entityClass; 036 } 037 038 public void setEntityClass(Class entityClass) { 039 this.entityClass = entityClass; 040 } 041 042 public String getFieldName() { 043 return fieldName; 044 } 045 046 public void setFieldName(String fieldName) { 047 this.fieldName = fieldName; 048 } 049 050 public FieldWrapper getFieldWrapper() { 051 return fieldWrapper; 052 } 053 054 public void setFieldWrapper(FieldWrapper fieldWrapper) { 055 this.fieldWrapper = fieldWrapper; 056 } 057 058 public boolean isPrevent() { 059 return prevent; 060 } 061 062 public void setPrevent(boolean prevent) { 063 this.prevent = prevent; 064 } 065 066 public QueryBuilder getQueryBuilder() { 067 return queryBuilder; 068 } 069 070 public void setQueryBuilder(QueryBuilder queryBuilder) { 071 this.queryBuilder = queryBuilder; 072 } 073 074 public static class Builder<T> { 075 076 private final FieldQuery fieldQuery; 077 078 public Builder(Class entityClass, String fieldName) { 079 this.fieldQuery = new FieldQuery(); 080 this.fieldQuery.setEntityClass(entityClass); 081 this.fieldQuery.setFieldName(fieldName); 082 this.fieldQuery.setFieldWrapper(FieldWrapper.of(entityClass, fieldName)); 083 } 084 085 /** 086 * 阻止对嵌套类属性的查询,只对 集合 与 实体类 两种属性类型有效。 087 * 088 * @return 构建者 089 */ 090 public Builder<T> prevent() { 091 this.fieldQuery.setPrevent(true); 092 return this; 093 } 094 095 /** 096 * 设置是否阻止对嵌套类属性的查询,只对 集合 与 实体类 两种属性类型有效。 097 * 098 * @param prevent 是否阻止对嵌套类属性查询 099 * @return 构建者 100 */ 101 public Builder<T> prevent(boolean prevent) { 102 this.fieldQuery.setPrevent(prevent); 103 return this; 104 } 105 106 /** 107 * 设置查询这个属性的 {@code QueryWrapper} 对象。 108 * 109 * @param queryBuilder 查询包装器 110 * @return 构建者 111 */ 112 public Builder<T> queryWrapper(QueryBuilder<T> queryBuilder) { 113 this.fieldQuery.setQueryBuilder(queryBuilder); 114 return this; 115 } 116 117 protected FieldQuery build() { 118 return this.fieldQuery; 119 } 120 121 } 122 123}