Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.aoju.bus.mapper.entity.EntityColumn Maven / Gradle / Ivy
/*********************************************************************************
* *
* The MIT License (MIT) *
* *
* Copyright (c) 2015-2022 aoju.org mybatis.io and other contributors. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy *
* of this software and associated documentation files (the "Software"), to deal *
* in the Software without restriction, including without limitation the rights *
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
* THE SOFTWARE. *
* *
********************************************************************************/
package org.aoju.bus.mapper.entity;
import org.aoju.bus.core.lang.Symbol;
import org.aoju.bus.core.toolkit.StringKit;
import org.aoju.bus.mapper.criteria.Order;
import org.aoju.bus.mapper.genid.GenId;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
/**
* 数据库表对应的列
*
* @author Kimi Liu
* @since Java 17+
*/
public class EntityColumn {
private EntityTable table;
private String property;
private String column;
private Class> javaType;
private JdbcType jdbcType;
private Class extends TypeHandler>> typeHandler;
private boolean id = false;
private boolean identity = false;
private Class extends GenId> genIdClass;
/**
* 字段是否为 blob
*/
private boolean blob;
private String generator;
/**
* 排序
*/
private String orderBy;
private int orderPriority;
/**
* 可插入
*/
private boolean insertable = true;
/**
* 可更新
*/
private boolean updatable = true;
/**
* 排序
*/
private Order order = Order.DEFAULT;
/**
* 是否设置 javaType
*/
private boolean useJavaType;
/**
* 对应的字段信息
*/
private EntityField entityField;
public EntityColumn() {
}
public EntityColumn(EntityTable table) {
this.table = table;
}
/**
* 返回格式如:colum = #{age,jdbcType=NUMERIC,typeHandler=MyTypeHandler}
*
* @param entityName 实体映射名
* @return the string
*/
public String getColumnEqualsHolder(String entityName) {
return this.column + " = " + getColumnHolder(entityName);
}
/**
* 返回格式如:#{entityName.age,jdbcType=NUMERIC,typeHandler=MyTypeHandler}
*
* @param entityName 实体映射名
* @return the string
*/
public String getColumnHolder(String entityName) {
return getColumnHolder(entityName, null);
}
/**
* 返回格式如:#{entityName.age+suffix,jdbcType=NUMERIC,typeHandler=MyTypeHandler}
*
* @param entityName 实体映射名
* @param suffix 后缀
* @return the string
*/
public String getColumnHolder(String entityName, String suffix) {
return getColumnHolder(entityName, null, null);
}
/**
* 返回格式如:#{entityName.age+suffix,jdbcType=NUMERIC,typeHandler=MyTypeHandler},
*
* @param entityName 实体映射名
* @param suffix 后缀
* @return the string
*/
public String getColumnHolderWithComma(String entityName, String suffix) {
return getColumnHolder(entityName, suffix, Symbol.COMMA);
}
/**
* 返回格式如:#{entityName.age+suffix,jdbcType=NUMERIC,typeHandler=MyTypeHandler}+separator
*
* @param entityName 实体映射名
* @param suffix 后缀
* @param separator 分隔符
* @return the string
*/
public String getColumnHolder(String entityName, String suffix, String separator) {
StringBuffer sb = new StringBuffer("#{");
if (StringKit.isNotEmpty(entityName)) {
sb.append(entityName);
sb.append(".");
}
sb.append(this.property);
if (StringKit.isNotEmpty(suffix)) {
sb.append(suffix);
}
// 如果 null 被当作值来传递,对于所有可能为空的列,JDBC Type 是需要的
if (this.jdbcType != null) {
sb.append(", jdbcType=");
sb.append(this.jdbcType.toString());
}
// 为了以后定制类型处理方式,你也可以指定一个特殊的类型处理器类,例如枚举
if (this.typeHandler != null) {
sb.append(", typeHandler=");
sb.append(this.typeHandler.getName());
}
// useJavaType 默认 false,没有 javaType 限制时,对 ByPrimaryKey 方法的参数校验就放宽了,会自动转型
if (useJavaType && !this.javaType.isArray()) {
sb.append(", javaType=");
sb.append(javaType.getName());
}
sb.append("}");
if (StringKit.isNotEmpty(separator)) {
sb.append(separator);
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EntityColumn that = (EntityColumn) o;
if (id != that.id) return false;
if (identity != that.identity) return false;
if (table != null ? !table.equals(that.table) : that.table != null) return false;
if (property != null ? !property.equals(that.property) : that.property != null) return false;
if (column != null ? !column.equals(that.column) : that.column != null) return false;
if (javaType != null ? !javaType.equals(that.javaType) : that.javaType != null) return false;
if (jdbcType != that.jdbcType) return false;
if (typeHandler != null ? !typeHandler.equals(that.typeHandler) : that.typeHandler != null) return false;
if (generator != null ? !generator.equals(that.generator) : that.generator != null) return false;
return !(orderBy != null ? !orderBy.equals(that.orderBy) : that.orderBy != null);
}
@Override
public int hashCode() {
int result = table != null ? table.hashCode() : 0;
result = 31 * result + (property != null ? property.hashCode() : 0);
result = 31 * result + (column != null ? column.hashCode() : 0);
result = 31 * result + (javaType != null ? javaType.hashCode() : 0);
result = 31 * result + (jdbcType != null ? jdbcType.hashCode() : 0);
result = 31 * result + (typeHandler != null ? typeHandler.hashCode() : 0);
result = 31 * result + (id ? 1 : 0);
result = 31 * result + (identity ? 1 : 0);
result = 31 * result + (generator != null ? generator.hashCode() : 0);
result = 31 * result + (orderBy != null ? orderBy.hashCode() : 0);
return result;
}
public String getColumn() {
return column;
}
public void setColumn(String column) {
this.column = column;
}
/**
* 返回格式如:colum = #{age,jdbcType=NUMERIC,typeHandler=MyTypeHandler}
*
* @return the string
*/
public String getColumnEqualsHolder() {
return getColumnEqualsHolder(null);
}
/**
* 返回格式如:#{age,jdbcType=NUMERIC,typeHandler=MyTypeHandler}
*
* @return the string
*/
public String getColumnHolder() {
return getColumnHolder(null);
}
public EntityField getEntityField() {
return entityField;
}
public void setEntityField(EntityField entityField) {
this.entityField = entityField;
}
public String getGenerator() {
return generator;
}
public void setGenerator(String generator) {
this.generator = generator;
}
public Class> getJavaType() {
return javaType;
}
public void setJavaType(Class> javaType) {
this.javaType = javaType;
}
public JdbcType getJdbcType() {
return jdbcType;
}
public void setJdbcType(JdbcType jdbcType) {
this.jdbcType = jdbcType;
}
public String getOrderBy() {
return orderBy;
}
public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public EntityTable getTable() {
return table;
}
public void setTable(EntityTable table) {
this.table = table;
}
public Class extends TypeHandler>> getTypeHandler() {
return typeHandler;
}
public void setTypeHandler(Class extends TypeHandler>> typeHandler) {
this.typeHandler = typeHandler;
}
public boolean isId() {
return id;
}
public void setId(boolean id) {
this.id = id;
}
public boolean isIdentity() {
return identity;
}
public void setIdentity(boolean identity) {
this.identity = identity;
}
public Class extends GenId> getGenIdClass() {
return genIdClass;
}
public void setGenIdClass(Class extends GenId> genIdClass) {
this.genIdClass = genIdClass;
}
public boolean isInsertable() {
return insertable;
}
public void setInsertable(boolean insertable) {
this.insertable = insertable;
}
public boolean isUpdatable() {
return updatable;
}
public void setUpdatable(boolean updatable) {
this.updatable = updatable;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public boolean isBlob() {
return blob;
}
public void setBlob(boolean blob) {
this.blob = blob;
}
public boolean isUseJavaType() {
return useJavaType;
}
public void setUseJavaType(boolean useJavaType) {
this.useJavaType = useJavaType;
}
public int getOrderPriority() {
return orderPriority;
}
public void setOrderPriority(int orderPriority) {
this.orderPriority = orderPriority;
}
@Override
public String toString() {
return "EntityColumn{" +
"table=" + table.getName() +
", property='" + property + '\'' +
", column='" + column + '\'' +
", javaType=" + javaType +
", jdbcType=" + jdbcType +
", typeHandler=" + typeHandler +
", id=" + id +
", identity=" + identity +
", blob=" + blob +
", generator='" + generator + '\'' +
", orderBy='" + orderBy + '\'' +
", orderPriority='" + orderPriority + '\'' +
", insertable=" + insertable +
", updatable=" + updatable +
", order=" + order +
'}';
}
}