PropertyMapping.java
/*
* Copyright 2025-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.github.simplejdbcmapper.core;
import java.lang.reflect.Method;
import java.sql.Types;
/**
* Object property to database column mapping.
*
* @author Antony Joseph
*/
class PropertyMapping {
private String propertyName;
private Class<?> propertyType;
private Method writeMethod;
private Method readMethod;
private ResultSetType resultSetType;
private String columnName;
private Integer columnSqlType;
private boolean isEnum = false;
private boolean idAnnotation = false;
private boolean createdOnAnnotation = false;
private boolean updatedOnAnnotation = false;
private boolean versionAnnotation = false;
private boolean createdByAnnotation = false;
private boolean updatedByAnnotation = false;
private boolean binaryLargeObject = false;
private boolean characterLargeObject = false;
public PropertyMapping(String propertyName, Class<?> propertyType, String columnName, Integer columnSqlType) {
if (propertyName == null || propertyType == null || columnName == null) {
throw new IllegalArgumentException("propertyName, propertyType, columnName must not be null");
}
this.propertyName = propertyName;
this.propertyType = propertyType;
// column names stored in lower case always. No plans to support case sensitive
// table column names or column names with spaces in them
this.columnName = InternalUtils.toLowerCase(columnName);
this.columnSqlType = columnSqlType;
isEnum = propertyType.isEnum();
determineBlobClob();
}
public int getColumnSqlType() {
return columnSqlType;
}
public String getPropertyName() {
return propertyName;
}
public Class<?> getPropertyType() {
return this.propertyType;
}
public String getColumnName() {
return columnName;
}
public boolean isIdAnnotation() {
return idAnnotation;
}
public void setIdAnnotation(boolean idAnnotation) {
this.idAnnotation = idAnnotation;
}
public boolean isCreatedOnAnnotation() {
return createdOnAnnotation;
}
public void setCreatedOnAnnotation(boolean createdOnAnnotation) {
this.createdOnAnnotation = createdOnAnnotation;
}
public boolean isUpdatedOnAnnotation() {
return updatedOnAnnotation;
}
public void setUpdatedOnAnnotation(boolean updatedOnAnnotation) {
this.updatedOnAnnotation = updatedOnAnnotation;
}
public boolean isVersionAnnotation() {
return versionAnnotation;
}
public void setVersionAnnotation(boolean versionAnnotation) {
this.versionAnnotation = versionAnnotation;
}
public boolean isCreatedByAnnotation() {
return createdByAnnotation;
}
public void setCreatedByAnnotation(boolean createdByAnnotation) {
this.createdByAnnotation = createdByAnnotation;
}
public boolean isUpdatedByAnnotation() {
return updatedByAnnotation;
}
public void setUpdatedByAnnotation(boolean updatedByAnnotation) {
this.updatedByAnnotation = updatedByAnnotation;
}
public boolean isBinaryLargeObject() {
return binaryLargeObject;
}
public boolean isCharacterLargeObject() {
return characterLargeObject;
}
public boolean isEnum() {
return isEnum;
}
public Method getReadMethod() {
return readMethod;
}
public void setReadMethod(Method readMethod) {
this.readMethod = readMethod;
}
public Method getWriteMethod() {
return writeMethod;
}
public void setWriteMethod(Method writeMethod) {
this.writeMethod = writeMethod;
}
public ResultSetType getResultSetType() {
return resultSetType;
}
public void setResultSetType(ResultSetType resultSetType) {
this.resultSetType = resultSetType;
}
private void determineBlobClob() {
if (columnSqlType != null && (columnSqlType == Types.BLOB || columnSqlType == Types.ARRAY
|| columnSqlType == Types.LONGVARBINARY || columnSqlType == Types.VARBINARY)) {
binaryLargeObject = true;
} else if (columnSqlType != null && (columnSqlType == Types.CLOB || columnSqlType == Types.NCLOB
|| columnSqlType == Types.LONGVARCHAR || columnSqlType == Types.LONGNVARCHAR)) {
characterLargeObject = true;
}
}
}