use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class SqltoyUnifyFieldsHandler method forceUpdateFields.
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.plugins.IUnifyFieldsHandler#forceUpdateFields()
*/
@Override
public IgnoreCaseSet forceUpdateFields() {
// 最后修改时间作为必须修改字段
IgnoreCaseSet forceUpdateFields = new IgnoreCaseSet();
forceUpdateFields.add("updateTime");
return forceUpdateFields;
}
use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class DialectUtils method getUpdateReflectHandler.
/**
* @todo 构造修改记录参数反射赋值处理器
* @param preHandler
* @param forceUpdateProps
* @param unifyFieldsHandler
* @return
*/
public static ReflectPropsHandler getUpdateReflectHandler(final ReflectPropsHandler preHandler, String[] forceUpdateProps, IUnifyFieldsHandler unifyFieldsHandler) {
if (unifyFieldsHandler == null) {
return preHandler;
}
final Map<String, Object> keyValues = unifyFieldsHandler.updateUnifyFields();
if (keyValues == null || keyValues.isEmpty()) {
return preHandler;
}
// update操作强制更新字段优先
final Set<String> forceSet = new HashSet<String>();
if (forceUpdateProps != null && forceUpdateProps.length > 0) {
for (String field : forceUpdateProps) {
forceSet.add(field.toLowerCase().replace("_", ""));
}
}
// 强制修改字段赋值
IgnoreCaseSet tmpSet = unifyFieldsHandler.forceUpdateFields();
final IgnoreCaseSet forceUpdateFields = (tmpSet == null) ? new IgnoreCaseSet() : tmpSet;
ReflectPropsHandler handler = new ReflectPropsHandler() {
@Override
public void process() {
if (preHandler != null) {
preHandler.setPropertyIndexMap(this.getPropertyIndexMap());
preHandler.setRowIndex(this.getRowIndex());
preHandler.setRowData(this.getRowData());
preHandler.process();
}
// 修改操作
for (Map.Entry<String, Object> entry : keyValues.entrySet()) {
// 统一修改字段不在强制更新字段范围内
if (!forceSet.contains(entry.getKey().toLowerCase())) {
if (StringUtil.isBlank(this.getValue(entry.getKey())) || forceUpdateFields.contains(entry.getKey())) {
this.setValue(entry.getKey(), entry.getValue());
}
}
}
}
};
return handler;
}
use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class EntityManager method parseSecureConfig.
/**
* @todo 解析加解密配置
* @param entityMeta
* @param entityClass
*/
private void parseSecureConfig(EntityMeta entityMeta, Class entityClass) {
Class classType = entityClass;
SecureConfig secureConfig = null;
// 增加递归对父类检测
while (classType != null && !classType.equals(Object.class)) {
secureConfig = (SecureConfig) classType.getAnnotation(SecureConfig.class);
if (secureConfig != null) {
break;
}
classType = classType.getSuperclass();
}
// 不存在加解密配置
if (secureConfig == null) {
return;
}
Secure[] secures = secureConfig.secures();
if (secures != null && secures.length > 0) {
IgnoreCaseSet secureColumns = new IgnoreCaseSet();
String field;
FieldMeta fieldMeta;
for (Secure secure : secures) {
field = secure.field();
fieldMeta = entityMeta.getFieldMeta(field);
if (fieldMeta != null) {
// 加密
if (secure.secureType().equals(SecureType.ENCRYPT)) {
secureColumns.add(fieldMeta.getColumnName());
entityMeta.addSecureField(new FieldSecureConfig(field, SecureType.ENCRYPT, null, null, 0, 0, 0));
} else {
// 依据加密字段进行脱敏保存
entityMeta.addSecureField(new FieldSecureConfig(field, secure.secureType(), secure.sourceField(), secure.maskCode(), secure.headSize(), secure.tailSize(), secure.maskRate()));
}
}
}
// 加密字段
if (!secureColumns.isEmpty()) {
entityMeta.setSecureColumns(secureColumns);
}
}
}
use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class DialectUtils method getAddReflectHandler.
/**
* @todo 构造新增记录参数反射赋值处理器
* @param preHandler
* @param unifyFieldsHandler
* @return
*/
public static ReflectPropsHandler getAddReflectHandler(final ReflectPropsHandler preHandler, IUnifyFieldsHandler unifyFieldsHandler) {
if (unifyFieldsHandler == null) {
return preHandler;
}
final Map<String, Object> keyValues = unifyFieldsHandler.createUnifyFields();
if (keyValues == null || keyValues.isEmpty()) {
return preHandler;
}
// 强制修改字段赋值
IgnoreCaseSet tmpSet = unifyFieldsHandler.forceUpdateFields();
final IgnoreCaseSet forceUpdateFields = (tmpSet == null) ? new IgnoreCaseSet() : tmpSet;
ReflectPropsHandler handler = new ReflectPropsHandler() {
@Override
public void process() {
if (preHandler != null) {
preHandler.setPropertyIndexMap(this.getPropertyIndexMap());
preHandler.setRowIndex(this.getRowIndex());
preHandler.setRowData(this.getRowData());
preHandler.process();
}
for (Map.Entry<String, Object> entry : keyValues.entrySet()) {
if (StringUtil.isBlank(this.getValue(entry.getKey())) || forceUpdateFields.contains(entry.getKey())) {
this.setValue(entry.getKey(), entry.getValue());
}
}
}
};
return handler;
}
use of org.sagacity.sqltoy.model.IgnoreCaseSet in project sagacity-sqltoy by chenrenfei.
the class DialectUtils method getSaveOrUpdateReflectHandler.
/**
* @todo 构造创建和修改记录时的反射
* @param idFields
* @param prepHandler
* @param forceUpdateProps
* @param unifyFieldsHandler
* @return
*/
public static ReflectPropsHandler getSaveOrUpdateReflectHandler(final String[] idFields, final ReflectPropsHandler prepHandler, String[] forceUpdateProps, IUnifyFieldsHandler unifyFieldsHandler) {
if (unifyFieldsHandler == null) {
return prepHandler;
}
final Map<String, Object> addKeyValues = unifyFieldsHandler.createUnifyFields();
final Map<String, Object> updateKeyValues = unifyFieldsHandler.updateUnifyFields();
if ((addKeyValues == null || addKeyValues.isEmpty()) && (updateKeyValues == null || updateKeyValues.isEmpty())) {
return prepHandler;
}
// update操作强制更新字段优先
final Set<String> forceSet = new HashSet<String>();
if (forceUpdateProps != null && forceUpdateProps.length > 0) {
for (String field : forceUpdateProps) {
forceSet.add(field.toLowerCase().replace("_", ""));
}
}
// 强制修改字段赋值
IgnoreCaseSet tmpSet = unifyFieldsHandler.forceUpdateFields();
final IgnoreCaseSet forceUpdateFields = (tmpSet == null) ? new IgnoreCaseSet() : tmpSet;
final int idLength = (idFields == null) ? 0 : idFields.length;
// 构造一个新的包含update和save 的字段处理
ReflectPropsHandler handler = new ReflectPropsHandler() {
@Override
public void process() {
if (prepHandler != null) {
prepHandler.setPropertyIndexMap(this.getPropertyIndexMap());
prepHandler.setRowIndex(this.getRowIndex());
prepHandler.setRowData(this.getRowData());
prepHandler.process();
}
// 主键为空表示save操作
if (idLength > 0 && this.getValue(idFields[0]) == null) {
for (Map.Entry<String, Object> entry : addKeyValues.entrySet()) {
if (StringUtil.isBlank(this.getValue(entry.getKey()))) {
this.setValue(entry.getKey(), entry.getValue());
}
}
}
// 修改属性值
for (Map.Entry<String, Object> entry : updateKeyValues.entrySet()) {
// 统一修改字段不在强制更新字段范围内
if (!forceSet.contains(entry.getKey().toLowerCase())) {
if (StringUtil.isBlank(this.getValue(entry.getKey())) || forceUpdateFields.contains(entry.getKey())) {
this.setValue(entry.getKey(), entry.getValue());
}
}
}
}
};
return handler;
}
Aggregations