protected boolean mappingManyToManyByPropertyAnnotation(MetadataContext context,EntityMappingBuilder emb,RelationMappingBuilder rmb, BeanProperty bp, ManyToMany a) { if(null == a){ return false; } rmb.setName(a.name()); rmb.setType(RelationType.MANY_TO_MANY); Class<?> targetEntityType = Classes.firstNonVoid(a.target(),a.value()); if(null == targetEntityType){ rmb.setTargetEntityType(bp.getType()); }else{ rmb.setTargetEntityType(targetEntityType); } if(!a.joinEntityType().equals(void.class)){ rmb.setJoinEntityType(a.joinEntityType()); } rmb.setJoinTableName(a.joinTableName()); return true; }
protected void mappingManyToManyByClassAnnotation(MetadataContext context,EntityMappingBuilder emb,ManyToMany[] annotations) { for(ManyToMany a : annotations) { Class<?> targetEntityType = Classes.firstNonVoid(a.target(),a.value()); if(null == targetEntityType){ throw new MappingConfigException("The 'ManyToOne' annotation at class '" + emb.getEntityClass() + "' must defines 'targetEntityType'"); } if(null == targetEntityType){ throw new MappingConfigException("The 'ManyToMany' annotation at class '" + emb.getEntityClass() + "' must defines 'targetEntityType'"); } RelationMappingBuilder rmb = new RelationMappingBuilder(); rmb.setType(RelationType.MANY_TO_MANY); rmb.setName(a.name()); rmb.setTargetEntityType(targetEntityType); rmb.setOptional(Boolean.TRUE); if(!a.joinEntityType().equals(void.class)){ rmb.setJoinEntityType(a.joinEntityType()); } rmb.setJoinTableName(a.joinTableName()); emb.addRelationMapping(rmb); } }
protected void mappingManyToOneByClassAnnotation(MetadataContext context,EntityMappingBuilder emb,ManyToOne[] annotations) { for(ManyToOne a : annotations){ Class<?> targetEntityType = Classes.firstNonVoid(a.target(),a.value()); if(null == targetEntityType){ throw new MappingConfigException("The 'ManyToOne' annotation at class '" + emb.getEntityClass() + "' must defines 'targetEntityType'"); } RelationMappingBuilder rmb = new RelationMappingBuilder(); rmb.setType(RelationType.MANY_TO_ONE); rmb.setName(a.name()); rmb.setOptional(a.optional().getValue()); rmb.setOnCascadeDelete(a.onCascadeDelete()); rmb.setTargetEntityType(targetEntityType); //join fields createManyToOneJoinFields(emb, rmb, a.fields()); emb.addRelationMapping(rmb); } }
protected boolean mappingManyToOneByPropertyAnnotation(MetadataContext context,EntityMappingBuilder emb,RelationMappingBuilder rmb, BeanProperty bp, ManyToOne a) { if(null == a){ return false; } rmb.setName(a.name()); rmb.setType(RelationType.MANY_TO_ONE); rmb.setOptional(a.optional().getValue()); rmb.setOnCascadeDelete(a.onCascadeDelete()); Class<?> targetEntityType = Classes.firstNonVoid(a.target(),a.value()); if(null == targetEntityType){ rmb.setTargetEntityType(bp.getType()); }else{ rmb.setTargetEntityType(targetEntityType); } JoinField[] jfs = bp.getField().getDeclaredAnnotationsByType(JoinField.class); createManyToOneJoinFields(emb, rmb, jfs); return true; }