/** * <p>Checks if the given {@link java.lang.annotation.Annotation} was define during the mapping of a specific * {@link org.picketlink.idm.model.AttributedType}.</p> * * @param attributedType * @param annotation * * @throws org.picketlink.idm.config.SecurityConfigurationException If not annotation was defined to map the type. */ private void checkIfAnnotationIsDefined(Class<? extends AttributedType> attributedType, Class<? extends Annotation> annotation) throws SecurityConfigurationException { if (getEntityMapperForProperty(attributedType, annotation) == null) { throw MESSAGES.configJpaStoreRequiredMappingAnnotationForAttributedType(attributedType, annotation); } }
/** * <p>Checks if the given {@link java.lang.annotation.Annotation} was define during the mapping of a specific * {@link org.picketlink.idm.model.AttributedType}.</p> * * @param attributedType * @param annotation * * @throws org.picketlink.idm.config.SecurityConfigurationException If not annotation was defined to map the type. */ private void checkIfAnnotationIsDefined(Class<? extends AttributedType> attributedType, Class<? extends Annotation> annotation) throws SecurityConfigurationException { if (getEntityMapperForProperty(attributedType, annotation) == null) { throw MESSAGES.configJpaStoreRequiredMappingAnnotationForAttributedType(attributedType, annotation); } }
public <P extends Partition> List<P> getPartitions(IdentityContext identityContext, Class<P> partitionClass, String name) { EntityManager entityManager = getEntityManager(identityContext); String PARTITION_NAME_PROPERTY_NAME = "name"; EntityMapper entityMapper = getEntityMapperForProperty(partitionClass, PARTITION_NAME_PROPERTY_NAME); CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityMapper.getEntityType()); Root from = cq.from(entityMapper.getEntityType()); List<Predicate> predicates = new ArrayList<Predicate>(); if (!isNullOrEmpty(name)) { Property nameProperty = entityMapper.getProperty(partitionClass, PARTITION_NAME_PROPERTY_NAME).getValue(); predicates.add(cb.equal(from.get(nameProperty.getName()), name)); } if (!Partition.class.equals(partitionClass)) { Property typeProperty = entityMapper.getProperty(partitionClass, PartitionClass.class).getValue(); predicates.add(cb.equal(from.get(typeProperty.getName()), partitionClass.getName())); } cq.where(predicates.toArray(new Predicate[predicates.size()])); Query query = entityManager.createQuery(cq); List<P> result = new ArrayList<P>(); for (Object entity : query.getResultList()) { result.add(entityMapper.<P>createType(entity, entityManager)); } return result; }
public <P extends Partition> List<P> getPartitions(IdentityContext identityContext, Class<P> partitionClass, String name) { EntityManager entityManager = getEntityManager(identityContext); String PARTITION_NAME_PROPERTY_NAME = "name"; EntityMapper entityMapper = getEntityMapperForProperty(partitionClass, PARTITION_NAME_PROPERTY_NAME); CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(entityMapper.getEntityType()); Root from = cq.from(entityMapper.getEntityType()); List<Predicate> predicates = new ArrayList<Predicate>(); if (!isNullOrEmpty(name)) { Property nameProperty = entityMapper.getProperty(partitionClass, PARTITION_NAME_PROPERTY_NAME).getValue(); predicates.add(cb.equal(from.get(nameProperty.getName()), name)); } if (!Partition.class.equals(partitionClass)) { Property typeProperty = entityMapper.getProperty(partitionClass, PartitionClass.class).getValue(); predicates.add(cb.equal(from.get(typeProperty.getName()), partitionClass.getName())); } cq.where(predicates.toArray(new Predicate[predicates.size()])); Query query = entityManager.createQuery(cq); List<P> result = new ArrayList<P>(); for (Object entity : query.getResultList()) { result.add(entityMapper.<P>createType(entity, entityManager)); } return result; }
private List<?> findChildRelationships(IdentityContext context, Relationship relationship) { EntityManager em = getEntityManager(context); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationship.getClass(), RelationshipMember.class); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); List<Predicate> predicates = new ArrayList<Predicate>(); Property ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); Join<?, ?> join = root.join(ownerProperty.getName()); EntityMapper relationshipMapper = getRootMapper(relationship.getClass()); Property identifierProperty = relationshipMapper.getProperty(Identifier.class).getValue(); predicates.add(builder.equal(join.get(identifierProperty.getName()), relationship.getId())); criteria.where(predicates.toArray(new Predicate[predicates.size()])); return em.createQuery(criteria).getResultList(); }
private List<?> findChildRelationships(IdentityContext context, Relationship relationship) { EntityManager em = getEntityManager(context); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationship.getClass(), RelationshipMember.class); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<?> criteria = builder.createQuery(relationshipMemberMapper.getEntityType()); Root<?> root = criteria.from(relationshipMemberMapper.getEntityType()); List<Predicate> predicates = new ArrayList<Predicate>(); Property ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); Join<?, ?> join = root.join(ownerProperty.getName()); EntityMapper relationshipMapper = getRootMapper(relationship.getClass()); Property identifierProperty = relationshipMapper.getProperty(Identifier.class).getValue(); predicates.add(builder.equal(join.get(identifierProperty.getName()), relationship.getId())); criteria.where(predicates.toArray(new Predicate[predicates.size()])); return em.createQuery(criteria).getResultList(); }
private void storeRelationshipMembers(Relationship relationship, EntityManager entityManager) { Object ownerEntity = getRootEntity(relationship, entityManager); List<Property<IdentityType>> props = PropertyQueries.<IdentityType>createQuery(relationship.getClass()) .addCriteria(new TypedPropertyCriteria(IdentityType.class, MatchOption.SUB_TYPE)).getResultList(); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationship.getClass(), RelationshipMember.class); for (Property<IdentityType> prop : props) { Object relationshipIdentity = relationshipMemberMapper.createEntity(); IdentityType identityType = prop.getValue(relationship); if (identityType != null) { Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); // in this case we hold only the reference to the identity type identifier if (identityTypeProperty.getJavaClass().equals(String.class)) { identityTypeProperty.setValue(relationshipIdentity, IdentityTypeUtil.formatId(identityType)); } else { identityTypeProperty.setValue(relationshipIdentity, getRootEntity(identityType, entityManager)); } Property<Object> descriptorProperty = relationshipMemberMapper.getProperty(RelationshipDescriptor.class).getValue(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); descriptorProperty.setValue(relationshipIdentity, prop.getName()); ownerProperty.setValue(relationshipIdentity, ownerEntity); } entityManager.persist(relationshipIdentity); } }
RelationshipQueryParameter identityTypeParameter = (RelationshipQueryParameter) entry.getKey(); List<String> identityTypeIdentifiers = new ArrayList<String>(); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationshipType, RelationshipMember.class); Object[] parameterValues = entry.getValue(); EntityMapper parameterEntityMapper = getEntityMapperForProperty(relationshipType, attributeParameter.getName());
RelationshipQueryParameter identityTypeParameter = (RelationshipQueryParameter) entry.getKey(); List<String> identityTypeIdentifiers = new ArrayList<String>(); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationshipType, RelationshipMember.class); Object[] parameterValues = entry.getValue(); EntityMapper parameterEntityMapper = getEntityMapperForProperty(relationshipType, attributeParameter.getName());
private void storeRelationshipMembers(Relationship relationship, EntityManager entityManager) { Object ownerEntity = getRootEntity(relationship, entityManager); List<Property<IdentityType>> props = PropertyQueries.<IdentityType>createQuery(relationship.getClass()) .addCriteria(new TypedPropertyCriteria(IdentityType.class, MatchOption.SUB_TYPE)).getResultList(); EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationship.getClass(), RelationshipMember.class); for (Property<IdentityType> prop : props) { Object relationshipIdentity = relationshipMemberMapper.createEntity(); IdentityType identityType = prop.getValue(relationship); if (identityType != null) { Property<Object> identityTypeProperty = relationshipMemberMapper.getProperty(RelationshipMember.class).getValue(); // in this case we hold only the reference to the identity type identifier if (identityTypeProperty.getJavaClass().equals(String.class)) { identityTypeProperty.setValue(relationshipIdentity, IdentityTypeUtil.formatId(identityType)); } else { identityTypeProperty.setValue(relationshipIdentity, getRootEntity(identityType, entityManager)); } Property<Object> descriptorProperty = relationshipMemberMapper.getProperty(RelationshipDescriptor.class).getValue(); Property<Object> ownerProperty = relationshipMemberMapper.getProperty(OwnerReference.class).getValue(); descriptorProperty.setValue(relationshipIdentity, prop.getName()); ownerProperty.setValue(relationshipIdentity, ownerEntity); } entityManager.persist(relationshipIdentity); } }
AttributeParameter attributeParameter = (AttributeParameter) queryParameter; EntityMapper parameterEntityMapper = getEntityMapperForProperty(type, attributeParameter.getName());
AttributeParameter attributeParameter = (AttributeParameter) queryParameter; EntityMapper parameterEntityMapper = getEntityMapperForProperty(type, attributeParameter.getName());
EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationshipType, RelationshipMember.class); Property<Object> identityProperty = relationshipMemberMapper.getProperty(relationshipType, RelationshipMember.class).getValue(); Property<String> descriptorProperty = relationshipMemberMapper.getProperty(relationshipType, RelationshipDescriptor.class).getValue();
EntityMapper relationshipMemberMapper = getEntityMapperForProperty(relationshipType, RelationshipMember.class); Property<Object> identityProperty = relationshipMemberMapper.getProperty(relationshipType, RelationshipMember.class).getValue(); Property<String> descriptorProperty = relationshipMemberMapper.getProperty(relationshipType, RelationshipDescriptor.class).getValue();