/** * Find and set imported primary keys. * * <p>This is where @ManyToOne properties maps to a PFK (Primary and foreign key). Perform the * match by naming convention on property name and db column. */ private void setImportedPrimaryKeys(DeployBeanDescriptor<?> deploy) { List<DeployBeanProperty> ids = deploy.propertiesId(); if (ids.size() == 1) { DeployBeanProperty id = ids.get(0); if (id instanceof DeployBeanPropertyAssocOne<?>) { // only interested if the primary key is a compound key DeployBeanDescriptor<?> targetDeploy = ((DeployBeanPropertyAssocOne<?>) id).getTargetDeploy(); for (DeployBeanPropertyAssocOne<?> assoc : deploy.propertiesAssocOne()) { DeployBeanProperty pkMatch = targetDeploy.findMatch(assoc.getName(), assoc.getDbColumn()); if (pkMatch != null) { assoc.setImportedPrimaryKey(pkMatch); } } } } }
public String toString() { return desc.getFullName() + "." + name; }
/** Return true if this is local to this type - aka not from a super type. */ public boolean isLocal() { return owningType == null || owningType.equals(desc.getBeanType()); }
public String getFullBeanName() { return desc.getFullName() + "." + name; }
@SuppressWarnings({"unchecked", "rawtypes"}) public DeployBeanPropertyLists( BeanDescriptorMap owner, BeanDescriptor<?> desc, DeployBeanDescriptor<?> deploy) { this.desc = desc; setImportedPrimaryKeys(deploy); DeployBeanPropertyAssocOne<?> deployUnidirectional = deploy.getUnidirectional(); if (deployUnidirectional == null) { unidirectional = null; } else { unidirectional = new BeanPropertyAssocOne(owner, desc, deployUnidirectional); } this.propertyMap = new LinkedHashMap<String, BeanProperty>(); // see if there is a discriminator property we should add String discriminatorColumn = null; BeanProperty discProperty = null; InheritInfo inheritInfo = deploy.getInheritInfo(); if (inheritInfo != null) { // Create a BeanProperty for the discriminator column to support // using RawSql queries with inheritance discriminatorColumn = inheritInfo.getDiscriminatorColumn(); DeployBeanProperty discDeployProp = new DeployBeanProperty(deploy, String.class, new ScalarTypeString(), null); discDeployProp.setDiscriminator(); discDeployProp.setName(discriminatorColumn); discDeployProp.setDbColumn(discriminatorColumn); // only register it in the propertyMap. This might not be used if // an explicit property is mapped to the discriminator on the bean discProperty = new BeanProperty(desc, discDeployProp); } for (DeployBeanProperty prop : deploy.propertiesAll()) { if (discriminatorColumn != null && discriminatorColumn.equals(prop.getDbColumn())) { // we have an explicit property mapped to the discriminator column prop.setDiscriminator(); discProperty = null; } BeanProperty beanProp = createBeanProperty(owner, prop); propertyMap.put(beanProp.getName(), beanProp); } int order = 0; for (BeanProperty prop : propertyMap.values()) { prop.setDeployOrder(order++); allocateToList(prop); } if (discProperty != null) { // put the discriminator property into the property map only // (after the real properties have been organised into their lists) propertyMap.put(discProperty.getName(), discProperty); } List<DeployTableJoin> deployTableJoins = deploy.getTableJoins(); tableJoins = new TableJoin[deployTableJoins.size()]; for (int i = 0; i < deployTableJoins.size(); i++) { tableJoins[i] = new TableJoin(deployTableJoins.get(i)); } }