JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation( ClassUtils.getUserClass(value), this.metamodel); if (!nestedEntityInformation.getJavaType().isAnnotationPresent(IdClass.class)) { .getPropertyValue(nestedEntityInformation.getRequiredIdAttribute().getName()); super.setPropertyValue(propertyName, nestedIdPropertyValue); return; BeanWrapper targetIdClassTypeWrapper = new BeanWrapperImpl(nestedEntityInformation.getIdType()); for (String idAttributeName : (Iterable<String>) nestedEntityInformation.getIdAttributeNames()) { targetIdClassTypeWrapper.setPropertyValue(idAttributeName, extractActualIdPropertyValue(sourceIdValueWrapper, idAttributeName));
/** * Creates a new {@link JpaMetamodelEntityInformation} for the given domain class and {@link Metamodel}. * * @param domainClass must not be {@literal null}. * @param metamodel must not be {@literal null}. */ public JpaMetamodelEntityInformation(Class<T> domainClass, Metamodel metamodel) { super(domainClass); Assert.notNull(metamodel, "Metamodel must not be null!"); this.metamodel = metamodel; ManagedType<T> type = metamodel.managedType(domainClass); if (type == null) { throw new IllegalArgumentException("The given domain class can not be found in the given Metamodel!"); } this.entityName = type instanceof EntityType ? ((EntityType<?>) type).getName() : null; if (!(type instanceof IdentifiableType)) { throw new IllegalArgumentException("The given domain class does not contain an id attribute!"); } IdentifiableType<T> identifiableType = (IdentifiableType<T>) type; this.idMetadata = new IdMetadata<T>(identifiableType); this.versionAttribute = findVersionAttribute(identifiableType, metamodel); }
@Override public Object getCompositeIdAttributeValue(Object id, String idAttribute) { Assert.isTrue(hasCompositeId(), "Model must have a composite Id!"); return new DirectFieldAccessFallbackBeanWrapper(id).getPropertyValue(idAttribute); }
/** * Creates a {@link JpaEntityInformation} for the given domain class and {@link EntityManager}. * * @param domainClass must not be {@literal null}. * @param em must not be {@literal null}. * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> JpaEntityInformation<T, ?> getEntityInformation(Class<T> domainClass, EntityManager em) { Assert.notNull(domainClass, "Domain class must not be null!"); Assert.notNull(em, "EntityManager must not be null!"); Metamodel metamodel = em.getMetamodel(); if (Persistable.class.isAssignableFrom(domainClass)) { return new JpaPersistableEntityInformation(domainClass, metamodel); } else { return new JpaMetamodelEntityInformation(domainClass, metamodel); } }
@SuppressWarnings("rawtypes") public String getIdName() { JpaMetamodelEntityInformation information = (JpaMetamodelEntityInformation) entityInformation; return information.getIdAttributeNames().iterator().next().toString(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private <S extends T> EntityInformation<Object, S> getEntityInformation(S entity) { Class<?> userClass = ClassUtils.getUserClass(entity.getClass()); if (entity instanceof AbstractPersistable<?>) { return new JpaPersistableEntityInformation(userClass, entityManager.getMetamodel()); } return new JpaMetamodelEntityInformation(userClass, entityManager.getMetamodel()); } }
JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation( ClassUtils.getUserClass(value), this.metamodel); if (!nestedEntityInformation.getJavaType().isAnnotationPresent(IdClass.class)) { .getPropertyValue(nestedEntityInformation.getRequiredIdAttribute().getName()); super.setPropertyValue(propertyName, nestedIdPropertyValue); return; BeanWrapper targetIdClassTypeWrapper = new BeanWrapperImpl(nestedEntityInformation.getIdType()); for (String idAttributeName : (Iterable<String>) nestedEntityInformation.getIdAttributeNames()) { targetIdClassTypeWrapper.setPropertyValue(idAttributeName, extractActualIdPropertyValue(sourceIdValueWrapper, idAttributeName));
/** * An initialization method which is run after the bean has been constructed. * This ensures that the entity manager is injected before we try to use it. */ @PostConstruct public void init() { JpaEntityInformation<Peptide, Long> peptideEntityInfo = new JpaMetamodelEntityInformation<Peptide, Long>(Peptide.class, entityManager.getMetamodel()); peptideRepository = new QueryDslJpaRepository<Peptide, Long>(peptideEntityInfo, entityManager); }
return findVersionAttribute((IdentifiableType<T>) managedSuperType, metamodel);
public Object getCompositeIdAttributeValue(Object id, String idAttribute) { Assert.isTrue(hasCompositeId(), "Model must have a composite Id!"); return new DirectFieldAccessFallbackBeanWrapper(id).getPropertyValue(idAttribute); }
/** * Creates a {@link JpaEntityInformation} for the given domain class and {@link EntityManager}. * * @param domainClass must not be {@literal null}. * @param em must not be {@literal null}. * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> JpaEntityInformation<T, ?> getEntityInformation(Class<T> domainClass, EntityManager em) { Assert.notNull(domainClass, "Domain class must not be null!"); Assert.notNull(em, "EntityManager must not be null!"); Metamodel metamodel = em.getMetamodel(); if (Persistable.class.isAssignableFrom(domainClass)) { return new JpaPersistableEntityInformation(domainClass, metamodel); } else { return new JpaMetamodelEntityInformation(domainClass, metamodel); } }
/** * Creates a new {@link JpaMetamodelEntityInformation} for the given domain class and {@link Metamodel}. * * @param domainClass must not be {@literal null}. * @param metamodel must not be {@literal null}. */ public JpaMetamodelEntityInformation(Class<T> domainClass, Metamodel metamodel) { super(domainClass); Assert.notNull(metamodel, "Metamodel must not be null!"); this.metamodel = metamodel; ManagedType<T> type = metamodel.managedType(domainClass); if (type == null) { throw new IllegalArgumentException("The given domain class can not be found in the given Metamodel!"); } this.entityName = type instanceof EntityType ? ((EntityType<?>) type).getName() : null; if (!(type instanceof IdentifiableType)) { throw new IllegalArgumentException("The given domain class does not contain an id attribute!"); } IdentifiableType<T> identifiableType = (IdentifiableType<T>) type; this.idMetadata = new IdMetadata<T>(identifiableType); this.versionAttribute = findVersionAttribute(identifiableType, metamodel); }
/** * An initialization method which is run after the bean has been constructed. * This ensures that the entity manager is injected before we try to use it. */ @PostConstruct public void init() { JpaEntityInformation<Protein, String> proteinEntityInfo = new JpaMetamodelEntityInformation<Protein, String>(Protein.class, entityManager.getMetamodel()); proteinRepository = new QueryDslJpaRepository<Protein, String>(proteinEntityInfo, entityManager); }
return findVersionAttribute((IdentifiableType<T>) managedSuperType, metamodel);
/** * Instancites a spring data repository: must be called within postconstruct. * * @param emf * the {@link EntityManagerFactory}. * @param em * the {@link EntityManager}. * @param domainClass * the repository class. */ protected void instanciateDelegateRepository(EntityManagerFactory emf, EntityManager em, Class<T> domainClass) { Metamodel mm = emf.getMetamodel(); if (Persistable.class.isAssignableFrom(domainClass)) { delegate = new TransactionalSimpleJpaRepository( new JpaPersistableEntityInformation(domainClass, mm), em); } else { delegate = new TransactionalSimpleJpaRepository( new JpaMetamodelEntityInformation(domainClass, mm), em); } }