@Override public Metamodel getMetamodel() { return em.getMetamodel(); }
/** * Creates a new {@link EclipseLinkProjectionQueryCreationListener} for the given {@link EntityManager}. * * @param em must not be {@literal null}. */ public EclipseLinkProjectionQueryCreationListener(EntityManager em) { Assert.notNull(em, "EntityManager must not be null!"); this.metamodel = JpaMetamodel.of(em.getMetamodel()); }
@Override public Metamodel getMetamodel() { return em().getMetamodel(); }
@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()); } }
/** * Creates a new {@link DefaultJpaContext} for the given {@link Set} of {@link EntityManager}s. * * @param entityManagers must not be {@literal null}. */ public DefaultJpaContext(Set<EntityManager> entityManagers) { Assert.notNull(entityManagers, "EntityManagers must not be null!"); Assert.notEmpty(entityManagers, "EntityManagers must not be empty!"); this.entityManagers = new LinkedMultiValueMap<Class<?>, EntityManager>(); for (EntityManager em : entityManagers) { for (ManagedType<?> managedType : em.getMetamodel().getManagedTypes()) { this.entityManagers.add(managedType.getJavaType(), em); } } }
/** * Creates a new {@link AbstractJpaQuery} from the given {@link JpaQueryMethod}. * * @param method * @param em */ public AbstractJpaQuery(JpaQueryMethod method, EntityManager em) { Assert.notNull(method, "JpaQueryMethod must not be null!"); Assert.notNull(em, "EntityManager must not be null!"); this.method = method; this.em = em; this.metamodel = JpaMetamodel.of(em.getMetamodel()); this.provider = PersistenceProvider.fromEntityManager(em); }
public FieldManager(EntityConfiguration entityConfiguration, EntityManager entityManager) { this.entityConfiguration = entityConfiguration; this.entityManager = entityManager; if (entityManager != null) { Set<EntityType<?>> managedEntities = entityManager.getMetamodel().getEntities(); for (EntityType managedEntity : managedEntities) { managedEntityClasses.add(managedEntity.getJavaType()); } } }
/** * 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); } }
public List<EntityType<?>> getEntityTypes() { return U.list(em.getMetamodel().getEntities()); }
@Test @TestForIssue(jiraKey = "HHH-12124") public void testEmbeddableEquality() { doInJPA( this::entityManagerFactory, entityManager -> { assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Company_.address.getType() ) ); assertTrue( entityManager.getMetamodel().getEmbeddables().contains( Person_.address.getType() ) ); } ); } }
@Test @TestForIssue(jiraKey = "HHH-9403") public void testWildcardGenericAttributeCanBeResolved() { doInJPA( this::entityManagerFactory, entityManager -> { EntityType<AbstractOwner> entity = entityManager.getMetamodel().entity( AbstractOwner.class ); assertNotNull( entity ); } ); }
@Test @TestForIssue(jiraKey = "HHH-11111") public void testEmbeddableCanBeResolvedWhenUsedAsInterface() { doInJPA( this::entityManagerFactory, entityManager -> { assertNotNull( entityManager.getMetamodel().embeddable( LocalizedValue.class ) ); assertEquals( LocalizedValue.class, ProductEntity_.description.getElementType().getJavaType() ); assertNotNull( LocalizedValue_.value ); } ); }
@Test public void testJoin() { doInJPA( this::entityManagerFactory, em -> { SubEntity sub = new SubEntity(); em.persist( sub ); MainEntity main = new MainEntity(); main.setSub( sub ); em.persist( main ); this.mainId = main.getId(); }); doInJPA( this::entityManagerFactory, em -> { EntityPersister entityPersister = ( (MetamodelImplementor) em.getMetamodel() ) .entityPersister( MainEntity.class ); // use some specific lock options to trigger the creation of a loader with lock options LockOptions lockOptions = new LockOptions( LockMode.NONE ); lockOptions.setTimeOut( 10 ); MainEntity main = (MainEntity) entityPersister.load( this.mainId, null, lockOptions, (SharedSessionContractImplementor) em ); assertNotNull( main.getSub() ); } ); }
public static String getEntityName(EntityManager em, Class<?> entityClass) { return em.getMetamodel().entity(entityClass).getName(); } }
void init() { for (EntityType<?> entity : dbf.getEntityManager().getMetamodel().getEntities()) { Class type = entity.getJavaType(); String name = type.getSimpleName();
if (((MetamodelImpl) em.getMetamodel()).getEntityMetadataMap().isEmpty()) ((MetamodelImpl) em.getMetamodel()).addEntityMetadata(clazz, metadata); ((MetamodelImpl) em.getMetamodel()).addEntityNameToClassMapping(clazz.getSimpleName(), clazz); appMetadata.getMetamodelMap().put(getPersistenceUnit(), em.getMetamodel());
TypedQuery<Long> count(RopertyKey ropertyKey) { Validate.notNull(entityManager, "Entity manager must not be null"); Validate.notNull(resultClass, "Result class must not be null"); Metamodel metamodel = entityManager.getMetamodel(); CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Long> query = criteriaBuilder.createQuery(Long.class); EntityType<X> entityType = metamodel.entity(resultClass); Root<X> root = query.from(entityType); query.select(criteriaBuilder.count(root)); query.where(criteriaBuilder.equal(root.get(entityType.getSingularAttribute("key")), ropertyKey)); return entityManager.createQuery(query); }
private void initPossibleSortbyColumnList(EntityManager em) { Metamodel metamodel = em.getMetamodel(); EntityType<SLASummaryBean> slaSummaryBeanEntityType = metamodel.entity(SLASummaryBean.class); Set<Attribute<SLASummaryBean,?>> slaSummaryBeanAttributes = slaSummaryBeanEntityType.getDeclaredAttributes(); possibleSortbyColumns = new ArrayList<>(); for (Attribute<SLASummaryBean,?> attribute : slaSummaryBeanAttributes) { possibleSortbyColumns.add(attribute.getName()); } }
@Before public final void resetDatabase() throws Exception { this.em.getMetamodel(); if (this.testDb != null) { this.testDb.resetDatabase(); } }
protected final QueryDslJpaRepository<E, PK> newRepository() { EntityManager entityManager = entityManagerOrFail(); JpaPersistableEntityInformation<E, PK> jpaEntityInformation = new JpaPersistableEntityInformation<E, PK>( entityInformation.entityClass(), entityManager.getMetamodel()); return new QueryDslJpaRepository<>(jpaEntityInformation, entityManager); }