link.jfire.sql.field.impl.AbstractMapField Maven / Gradle / Ivy
package link.jfire.sql.field.impl;
import java.lang.reflect.Field;
import link.jfire.baseutil.StringUtil;
import link.jfire.baseutil.reflect.ReflectUtil;
import link.jfire.sql.annotation.Column;
import link.jfire.sql.field.MapField;
import sun.misc.Unsafe;
/**
* 基础CURD操作映射的抽象属性类
*
* @author linbin
*
*/
@SuppressWarnings("restriction")
public abstract class AbstractMapField implements MapField
{
protected long offset;
protected String dbColName;
protected static Unsafe unsafe = ReflectUtil.getUnsafe();
protected boolean saveIgnore = false;
protected Field field;
public AbstractMapField(Field field)
{
offset = unsafe.objectFieldOffset(field);
this.field = field;
dbColName = field.getName();
if (field.isAnnotationPresent(Column.class) && StringUtil.isNotBlank(field.getAnnotation(Column.class).name()))
{
dbColName = field.getAnnotation(Column.class).name();
}
if (field.isAnnotationPresent(Column.class))
{
saveIgnore = field.getAnnotation(Column.class).saveIgnore();
}
}
@Override
public String getColName()
{
return dbColName;
}
public boolean saveIgnore()
{
return saveIgnore;
}
public String getFieldName()
{
return field.getName();
}
}