private void setupRelationshipRepositories ( Class < ? > resourceClass , boolean mapped ) { MetaLookup metaLookup = mapped ? resourceMetaLookup : jpaMetaLookup ; Class < ? extends MetaDataObject > metaClass = mapped ? MetaJsonObject . class : MetaJpaDataObject . class ; MetaDataObject meta = metaLookup . getMeta ( resourceClass , metaClass ) ; for ( MetaAttribute attr : meta . getAttributes ( ) ) { if ( ! attr . isAssociation ( ) ) { continue ; } MetaType attrType = attr . getType ( ) . getElementType ( ) ; if ( attrType instanceof MetaEntity ) { // normal entity association Class < ? > attrImplClass = attrType . getImplementationClass ( ) ; JpaRepositoryConfig < ? > attrConfig = getRepositoryConfig ( attrImplClass ) ; // only include relations that are exposed as repositories if ( attrConfig != null ) { RelationshipRepositoryV2 < ? , ? , ? , ? > relationshipRepository = filterRelationshipCreation ( attrImplClass , repositoryFactory . createRelationshipRepository ( this , resourceClass , attrConfig ) ) ; context . addRepository ( relationshipRepository ) ; } } else if ( attrType instanceof MetaResource ) { Class < ? > attrImplClass = attrType . getImplementationClass ( ) ; JpaRepositoryConfig < ? > attrConfig = getRepositoryConfig ( attrImplClass ) ; if ( attrConfig == null || attrConfig . getMapper ( ) == null ) { throw new IllegalStateException ( "no mapped entity for " + attrType . getName ( ) + " reference by " + attr . getId ( ) + " registered" ) ; } JpaRepositoryConfig < ? > targetConfig = getRepositoryConfig ( attrImplClass ) ; Class < ? > targetResourceClass = targetConfig . getResourceClass ( ) ; RelationshipRepositoryV2 < ? , ? , ? , ? > relationshipRepository = filterRelationshipCreation ( targetResourceClass , repositoryFactory . createRelationshipRepository ( this , resourceClass , attrConfig ) ) ; context . addRepository ( relationshipRepository ) ; } else { throw new IllegalStateException ( "unable to process relation: " + attr . getId ( ) + ", neither a entity nor a mapped entity is referenced" ) ; } } }
Sets up relationship repositories for the given resource class . In case of a mapper the resource class might not correspond to the entity class .