All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.featherfly.hammer.mapping.ClassMapping Maven / Gradle / Ivy

There is a newer version: 0.7.2
Show newest version
package cn.featherfly.hammer.mapping;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 

* 类映射 *

* * @param 类型 * @author zhongj * @since 0.1.0 * @version 0.1.0 */ public class ClassMapping { /** * @param type 类型 * @param repositoryName 存储名 */ public ClassMapping(Class type, String repositoryName) { this.type = type; this.repositoryName = repositoryName; } /** *

* 返回指定属性名称的属性映射. 没有找到返回null. *

* * @param propertyName 属性名称 * @return 属性映射对象 */ public PropertyMapping getPropertyMapping(String propertyName) { return propertyMappings.get(propertyName); } /** *

* 通过持久化字段(数据库字段)的名称返回指定属性映射. 没有找到返回null. *

* * @param persitField 持久化字段(数据库字段) * @return 属性映射对象 */ public PropertyMapping getPropertyMappingByPersitField(String persitField) { for (PropertyMapping pm : propertyMappings.values()) { if (pm.getRepositoryFieldName().equals(persitField)) { return pm; } } return null; } /** *

* 返回所有属性映射 *

* * @return 所有属性映射 */ public Collection getPropertyMappings() { return propertyMappings.values(); } /** *

* 返回所有主键属性映射 *

* * @return 所有属性映射 */ public List getPrivaryKeyPropertyMappings() { return propertyMappings.values().stream().filter(p -> p.isPrimaryKey()).collect(Collectors.toList()); } public void addPropertyMapping(PropertyMapping propertyMapping) { propertyMappings.put(propertyMapping.getPropertyName(), propertyMapping); } public void addPropertyMappings(Collection propertyMappings) { for (PropertyMapping propertyMapping : propertyMappings) { addPropertyMapping(propertyMapping); } } // ******************************************************************** // // ******************************************************************** private Map propertyMappings = new HashMap<>(0); private String repositoryName; private Class type; /** * @return 返回tableName */ public String getRepositoryName() { return repositoryName; } /** * @return 返回type */ public Class getType() { return type; } /** * {@inheritDoc} */ @Override public String toString() { return "ClassMapping [repositoryName=" + repositoryName + ", type=" + type + ", propertyMappings=" + propertyMappings + "]"; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy