/** * 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({ "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);
/** * 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); }
/** * 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); }
/** * 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); } }
/** * 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); } }
JpaMetamodelEntityInformation nestedEntityInformation = new JpaMetamodelEntityInformation( ClassUtils.getUserClass(value), this.metamodel);