EntityTable.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.nuliji.tools.mybatis;
  2. import javax.persistence.Id;
  3. import java.util.HashMap;
  4. import java.util.LinkedHashSet;
  5. import java.util.Map;
  6. import java.util.Set;
  7. /**
  8. * Created by gaojie on 2017/11/9.
  9. */
  10. public class EntityTable {
  11. //类
  12. private Class<?> entityClass;
  13. //实体类 => 全部列属性
  14. private Set<EntityField> entityFields;
  15. //实体类 => 主键信息
  16. private Set<EntityField> entityPK;
  17. //属性和列对应
  18. protected Map<String, EntityField> propertyMap;
  19. public EntityTable(Class<?> entityClass){
  20. this.entityClass = entityClass;
  21. this.entityPK = new LinkedHashSet<EntityField>();
  22. this.entityFields = new LinkedHashSet<EntityField>();
  23. }
  24. public Set<EntityField> getEntityPK() {
  25. return entityPK;
  26. }
  27. public void setEntityPK(Set<EntityField> entityPK) {
  28. this.entityPK = entityPK;
  29. }
  30. public int countEntityPK(){
  31. return entityPK.size();
  32. }
  33. public void initPropertyMap() {
  34. propertyMap = new HashMap<String, EntityField>(getEntityFields().size());
  35. for (EntityField field : getEntityFields()) {
  36. if (field.isAnnotationPresent(Id.class)) {
  37. this.getEntityPK().add(field);
  38. }
  39. propertyMap.put(field.getName(), field);
  40. }
  41. }
  42. public Set<EntityField> getEntityFields() {
  43. return entityFields;
  44. }
  45. public void setEntityFields(Set<EntityField> entityFields) {
  46. this.entityFields = entityFields;
  47. }
  48. public EntityField getEntityProperty(String property){
  49. return propertyMap.get(property);
  50. }
  51. public Class<?> getEntityClass() {
  52. return entityClass;
  53. }
  54. public void setEntityClass(Class<?> entityClass) {
  55. this.entityClass = entityClass;
  56. }
  57. }