1 19 package org.netbeans.modules.j2ee.persistence.entitygenerator; 20 21 import java.util.ArrayList ; 22 import java.util.Collections ; 23 import java.util.List ; 24 import org.openide.filesystems.FileObject; 25 26 32 public class EntityClass { 33 34 private final String tableName; 35 private final FileObject rootFolder; 36 private final String className; 37 private final String packageName; 38 39 private List <RelationshipRole> roles; 40 private List <EntityMember> fields; 41 private boolean usePkField; 42 private String pkFieldName; 43 private CMPMappingModel mappingModel; 44 45 public EntityClass(String tableName, FileObject rootFolder, String packageName, String className) { 46 this.tableName = tableName; 47 this.rootFolder = rootFolder; 48 this.packageName = packageName; 49 this.className = className; 50 51 roles = Collections.<RelationshipRole>emptyList(); 52 fields = new ArrayList <EntityMember>(); 53 mappingModel = new CMPMappingModel(); 54 } 55 56 public void addRole(RelationshipRole role) { 57 if (roles == Collections.<RelationshipRole>emptyList()) { 58 roles = new ArrayList <RelationshipRole>(); 59 } 60 roles.add(role); 61 } 62 63 public List <RelationshipRole> getRoles() { 64 return roles; 65 } 66 67 public List <EntityMember> getFields() { 68 return fields; 69 } 70 71 public void setFields(List <EntityMember> fields) { 72 this.fields = fields; 73 } 74 75 public String toString() { 76 String cmpFields = ""; for (EntityMember entityMember : getFields()) { 78 cmpFields += " " + entityMember.getMemberName() + (entityMember.isPrimaryKey() ? " (PK) " : " "); } 80 return "bean name " + getClassName() + "\ncmp-fields "+ cmpFields; } 83 84 public FileObject getRootFolder() { 85 return rootFolder; 86 } 87 88 public String getPackage() { 89 return packageName; 90 } 91 92 public String getTableName() { 93 return tableName; 94 } 95 96 public String getClassName() { 97 return className; 98 } 99 100 public FileObject getPackageFileObject() { 101 String relative = packageName.replace('.', '/'); 102 return rootFolder.getFileObject(relative); 103 } 104 105 public CMPMappingModel getCMPMapping() { 106 mappingModel.getCMPFieldMapping().clear(); 107 for (EntityMember entityMember : getFields()) { 108 mappingModel.setTableName(entityMember.getTableName()); 109 mappingModel.getCMPFieldMapping().put(entityMember.getMemberName(), entityMember.getColumnName()); 110 } 111 return mappingModel; 112 } 113 114 public void usePkField(boolean usePkField) { 115 this.usePkField = usePkField; 116 } 117 118 public boolean isUsePkField() { 119 return usePkField; 120 } 121 122 public String getPkFieldName() { 123 return pkFieldName; 124 } 125 126 public void setPkFieldName(String pkFieldName) { 127 this.pkFieldName = pkFieldName; 128 } 129 } 130 | Popular Tags |