Ejemplo n.º 1
0
  @Test
  public void allClassMapping() throws Exception {
    Metamodel model = em.getEntityManagerFactory().getMetamodel();
    assertThat(model.getEntities()).as("No entity mapping found").isNotEmpty();

    for (EntityType entityType : model.getEntities()) {
      String entityName = entityType.getName();
      em.createQuery("select o from " + entityName + " o").getResultList();
      logger.info("ok: " + entityName);
    }
  }
 private synchronized void reloadCache(EntityManager em) {
   if (em == null || ref.get() != null) return;
   Metamodel metamodel = em.getMetamodel();
   Map<String, Class<?>> map = new HashMap<>(metamodel.getEntities().size() + 2);
   for (EntityType<?> entity : metamodel.getEntities()) {
     System.out.printf(
         "---  Carregando do Metamodel: %s [%s] \n", entity.getName(), entity.getJavaType());
     map.put(entity.getName(), entity.getJavaType());
   }
   ref = new SoftReference(map);
 }
Ejemplo n.º 3
0
 @Test
 public void allClassMapping() throws Exception {
   Metamodel model = em.getEntityManagerFactory().getMetamodel();
   for (EntityType<?> entityType : model.getEntities()) {
     String entityName = entityType.getName();
     em.createQuery("select o from " + entityName + " o").getFirstResult();
     logger.info("ok: " + entityName);
   }
 }
Ejemplo n.º 4
0
 @Override
 public Map<String, Class<Entity>> getTableMap() {
   Map<String, Class<Entity>> map = new HashMap<String, Class<Entity>>();
   Metamodel metamodel = entityManager.getEntityManagerFactory().getMetamodel();
   Set<EntityType<?>> set = metamodel.getEntities();
   for (EntityType<?> entityType : set) {
     Class<Entity> clazz = (Class<Entity>) entityType.getJavaType();
     map.put(entityType.getName(), clazz);
   }
   return map;
 }
Ejemplo n.º 5
0
  @Before
  public void setUp() throws Exception {
    initMocks(this);
    final EntityType<Foo> foo = mock(EntityType.class);
    when(foo.getName()).thenReturn("foo");
    when(foo.getJavaType()).thenReturn(Foo.class);
    when(metamodel.entity(Foo.class)).thenReturn(foo);
    when(metamodel.getEntities()).thenReturn(new HashSet<EntityType<?>>(Arrays.asList(foo)));

    wrapper = new MetamodelWrapper(metamodel);
  }
Ejemplo n.º 6
0
 @Override
 public Map<String, Map<String, Class<?>>> getTableColumnMap() {
   Metamodel metamodel = entityManager.getEntityManagerFactory().getMetamodel();
   Set<EntityType<?>> entityTypes = metamodel.getEntities();
   Map<String, Map<String, Class<?>>> tableColumnMap =
       new HashMap<String, Map<String, Class<?>>>();
   for (EntityType<?> type : entityTypes) {
     EntityType<Entity> entityType = (EntityType<Entity>) type;
     Set<SingularAttribute<? super Entity, ?>> singularAttributes =
         entityType.getSingularAttributes();
     Map<String, Class<?>> columnMap = new HashMap<String, Class<?>>();
     for (SingularAttribute<? super Entity, ?> singularAttribute : singularAttributes) {
       columnMap.put(singularAttribute.getName(), singularAttribute.getJavaType());
     }
     tableColumnMap.put(entityType.getName(), columnMap);
   }
   return tableColumnMap;
 }