javax.persistence.EntityManager.getMetamodel()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(321)

本文整理了Java中javax.persistence.EntityManager.getMetamodel()方法的一些代码示例,展示了EntityManager.getMetamodel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.getMetamodel()方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:getMetamodel

EntityManager.getMetamodel介绍

[英]Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
[中]返回Metamodel接口的实例,以访问持久化单元的元模型。

代码示例

代码示例来源:origin: rapidoid/rapidoid

@Override
public Metamodel getMetamodel() {
  return em.getMetamodel();
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * 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());
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public Metamodel getMetamodel() {
  return em().getMetamodel();
}

代码示例来源:origin: spring-projects/spring-data-examples

@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());
  }
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * 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);
    }
  }
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * 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);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

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());
    }
  }
}

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * 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);
  }
}

代码示例来源:origin: rapidoid/rapidoid

public List<EntityType<?>> getEntityTypes() {
  return U.list(em.getMetamodel().getEntities());
}

代码示例来源:origin: hibernate/hibernate-orm

@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() ) );
    } );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@TestForIssue(jiraKey = "HHH-9403")
public void testWildcardGenericAttributeCanBeResolved() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    EntityType<AbstractOwner> entity = entityManager.getMetamodel().entity( AbstractOwner.class );
    assertNotNull( entity );
  } );
}

代码示例来源:origin: hibernate/hibernate-orm

@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 );
  } );
}

代码示例来源:origin: hibernate/hibernate-orm

@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() );
  } );
}

代码示例来源:origin: spring-projects/spring-integration

public static String getEntityName(EntityManager em, Class<?> entityClass) {

    return em.getMetamodel().entity(entityClass).getName();

  }
}

代码示例来源:origin: zstackio/zstack

void init() {
  for (EntityType<?> entity : dbf.getEntityManager().getMetamodel().getEntities()) {
    Class type = entity.getJavaType();
    String name = type.getSimpleName();

代码示例来源:origin: Impetus/Kundera

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());

代码示例来源:origin: io.github.dheid/roperty-jpa

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);
}

代码示例来源:origin: apache/oozie

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());
  }
}

代码示例来源:origin: ch.inftec.ju/ju-testing

@Before
public final void resetDatabase() throws Exception {
  this.em.getMetamodel();
  
  if (this.testDb != null) {
    this.testDb.resetDatabase();
  }
}

代码示例来源:origin: com.github.akiraly.reusable-poms/db4j

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);
}

相关文章