Package javax.persistence.metamodel

Examples of javax.persistence.metamodel.Metamodel


        assertEquivalence(c, jpql);
       
    }
   
    public void testDisjunctionAsFalse() {
        Metamodel mm = em.getMetamodel();

        CriteriaQuery<Order> cquery = cb.createQuery(Order.class);
        Root<Order> order = cquery.from(Order.class);
       
       EntityType<Order> Order_ = order.getModel();
       EntityType<Customer> Customer_ = mm.entity(Customer.class);
       cquery.where(cb.and(cb.equal(
         order.get(Order_.getSingularAttribute("customer", Customer.class))
                  .get(Customer_.getSingularAttribute("name", String.class)), "Robert E. Bissett"),
         cb.isFalse(cb.disjunction())));
View Full Code Here


  @PersistenceContext EntityManager em;

  @Test
  public void considersOneToOneAttributeAnAssociation() {

    Metamodel metamodel = em.getMetamodel();
    ManagedType<User> type = metamodel.managedType(User.class);

    Attribute<? super User, ?> attribute = type.getSingularAttribute("manager");
    assertThat(attribute.isAssociation(), is(true));
  }
View Full Code Here

  public static <T> JpaEntityInformation<T, ?> getMetadata(Class<T> domainClass, EntityManager em) {

    Assert.notNull(domainClass);
    Assert.notNull(em);

    Metamodel metamodel = em.getMetamodel();

    if (Persistable.class.isAssignableFrom(domainClass)) {
      return new JpaPersistableEntityInformation(domainClass, metamodel);
    } else {
      return new JpaMetamodelEntityInformation(domainClass, metamodel);
View Full Code Here

   */
  @Override
  protected JpaPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
      JpaPersistentEntityImpl<?> owner, SimpleTypeHolder simpleTypeHolder) {

    Metamodel metamodel = getMetamodelFor(owner.getType());
    return new JpaPersistentPropertyImpl(metamodel, field, descriptor, owner, simpleTypeHolder);
  }
View Full Code Here

            } catch (IllegalArgumentException e) {
                // We weren't able to resolve the requested piece, likely because it's in a polymoprhic version
                // of the path we're currently on. Let's see if there's any polymoprhic version of our class to
                // use instead.
              EntityManagerFactoryImpl em = ((CriteriaBuilderImpl) builder).getEntityManagerFactory();
              Metamodel mm = em.getMetamodel();
              boolean found = false;
             
              Class<?>[] polyClasses = dynamicDaoHelper.getAllPolymorphicEntitiesFromCeiling(
                      path.getJavaType(), em.getSessionFactory(), true, true);
             
              for (Class<?> clazz : polyClasses) {
                ManagedType mt = mm.managedType(clazz);
                try {
                    Attribute attr = mt.getAttribute(piece);
                    if (attr != null) {
                        Root additionalRoot = criteria.from(clazz);
                        restrictions.add(builder.equal(path, additionalRoot));
View Full Code Here

  @Test
  public void guardsAgainstNullJavaTypesReturnedFromJpaMetamodel() throws Exception {

    ApplicationContext context = mock(ApplicationContext.class);
    EntityManagerFactory emf = mock(EntityManagerFactory.class);
    Metamodel metamodel = mock(Metamodel.class);
    ManagedType<?> managedType = mock(ManagedType.class);

    Set<ManagedType<?>> managedTypes = Collections.<ManagedType<?>> singleton(managedType);

    when(context.getBeansOfType(EntityManagerFactory.class)).thenReturn(Collections.singletonMap("emf", emf));
    when(emf.getMetamodel()).thenReturn(metamodel);
    when(metamodel.getManagedTypes()).thenReturn(managedTypes);

    JpaMetamodelMappingContextFactoryBean factoryBean = new JpaMetamodelMappingContextFactoryBean();
    factoryBean.setApplicationContext(context);

    factoryBean.createInstance().afterPropertiesSet();
View Full Code Here

      if (entityClassCache.containsKey(className)) {
    return entityClassCache.get(className);
      }

      EntityManager em = entityManagerFactory.createEntityManager();
      Metamodel meta = em.getMetamodel();

      for (EntityType<?> et : meta.getEntities()) {
    if (et.getJavaType().getName().endsWith("." + className)) {
        Class<?> clazz = et.getJavaType();
        entityClassCache.put(className, clazz);
        return clazz;
    }
View Full Code Here

     * @return Metamodel instance
     * @since Java Persistence 2.0
     */
    public Metamodel getMetamodel() {
        // perform lazy initialisation
        Metamodel tempMetaModel = null;
        if(null == metaModel) {
            // 338837: verify that the collection is not empty - this would mean entities did not make it into the search path
            tempMetaModel = new MetamodelImpl(this);
            // If the canonical metamodel classes exist, initialize them
            initializeCanonicalMetamodel(tempMetaModel);
View Full Code Here

  }

  private String generateEntityManagerFactoryClass(
      TreeLogger logger, GeneratorContext context, EntityManagerFactory emf) {
    EntityManager em = emf.createEntityManager();
    Metamodel mm = em.getMetamodel();

    final ClassStructureBuilder<?> classBuilder =
        Implementations.implement(ErraiEntityManagerFactory.class, GENERATED_CLASS_NAME);

    classBuilder.publicMethod(ErraiEntityManager.class, "createEntityManager")
View Full Code Here

     * @return Metamodel instance
     * @since Java Persistence 2.0
     */
    public Metamodel getMetamodel() {
        // perform lazy initialisation
        Metamodel tempMetaModel = null;
        if(null == metaModel) {
            // 338837: verify that the collection is not empty - this would mean entities did not make it into the search path
            tempMetaModel = new MetamodelImpl(this);
            // If the canonical metamodel classes exist, initialize them
            initializeCanonicalMetamodel(tempMetaModel);
View Full Code Here

TOP

Related Classes of javax.persistence.metamodel.Metamodel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.