List of usage examples for javax.persistence.metamodel Metamodel getEntities
Set<EntityType<?>> getEntities();
From source file:cn.aozhi.songify.repository.JpaMappingTest.java
@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); }/*from w w w . j a va2 s . c om*/ }
From source file:$.JpaMappingTest.java
@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); }//from www. j a v a 2 s. c o m }
From source file:com.xyxy.platform.examples.showcase.repository.jpa.JpaMappingTest.java
@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); }/* w ww.ja va 2 s .com*/ }
From source file:com.sdl.odata.datasource.jpa.JPAEdmModelLoader.java
private List<Class<?>> discoverEntities() { Map<String, Class<?>> foundEntities = new HashMap<>(); Metamodel metamodel = entityManagerFactory.getMetamodel(); for (EntityType t : metamodel.getEntities()) { LOG.debug("We have a JPA Entity type: {}", t.getBindableJavaType().getCanonicalName()); Class<?> entityType = t.getJavaType(); foundEntities.put(entityType.getName(), entityType); }// ww w .jav a2 s. co m return new ArrayList<>(foundEntities.values()); }
From source file:tools.xor.service.DatastoreDAS.java
@Override public List<String> getAggregateList() { List<String> result = new ArrayList<String>(); Metamodel metaModel = emf.getMetamodel(); Set<EntityType<?>> classMappings = metaModel.getEntities(); for (EntityType<?> classMapping : classMappings) { defineTypes(classMapping);// w w w . j av a2s.co m result.add(classMapping.getJavaType().getName()); } return result; }
From source file:tools.xor.service.DatastoreDAS.java
@Override public void define() { Metamodel metaModel = emf.getMetamodel(); Set<EntityType<?>> classMappings = metaModel.getEntities(); logger.info("Getting the list of JPA mapped classes"); for (EntityType<?> classMapping : classMappings) { logger.debug(" Adding JPA persisted class: " + classMapping.getName()); defineTypes(classMapping);//from w ww .j a v a 2 s . c o m } // Set the super type defineSuperType(); // Set the base types setBaseTypes(); // Define the properties for the Types // This will end up defining the simple types defineProperties(); postProcess(); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.BaseJpaDaoTest.java
/** * Deletes ALL entities from the database *//*from w ww . j a v a 2s .c om*/ @After public final void deleteAllEntities() { final EntityManager entityManager = getEntityManager(); final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final Metamodel metamodel = entityManagerFactory.getMetamodel(); Set<EntityType<?>> entityTypes = new LinkedHashSet<EntityType<?>>(metamodel.getEntities()); do { final Set<EntityType<?>> failedEntitieTypes = new HashSet<EntityType<?>>(); for (final EntityType<?> entityType : entityTypes) { final String entityClassName = entityType.getBindableJavaType().getName(); try { this.executeInTransaction(new Callable<Object>() { @Override public Object call() throws Exception { logger.trace("Purging all: " + entityClassName); final Query query = entityManager .createQuery("SELECT e FROM " + entityClassName + " AS e"); final List<?> entities = query.getResultList(); logger.trace("Found " + entities.size() + " " + entityClassName + " to delete"); for (final Object entity : entities) { entityManager.remove(entity); } return null; } }); } catch (DataIntegrityViolationException e) { logger.trace( "Failed to delete " + entityClassName + ". Must be a dependency of another entity"); failedEntitieTypes.add(entityType); } } entityTypes = failedEntitieTypes; } while (!entityTypes.isEmpty()); //Reset all spring managed mocks after every test MockitoFactoryBean.resetAllMocks(); }
From source file:utilities.internal.CopyOfDatabaseUtil.java
private Configuration buildConfiguration() { Configuration result;//w ww .j ava 2s. co m Metamodel metamodel; Collection<EntityType<?>> entities; Collection<EmbeddableType<?>> embeddables; result = new Configuration(); metamodel = entityManagerFactory.getMetamodel(); entities = metamodel.getEntities(); for (EntityType<?> entity : entities) result.addAnnotatedClass(entity.getJavaType()); embeddables = metamodel.getEmbeddables(); for (EmbeddableType<?> embeddable : embeddables) result.addAnnotatedClass(embeddable.getJavaType()); return result; }
From source file:org.makersoft.activerecord.jpa.JPQL.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private Set<String> getColumns() { Metamodel metamodel = em().getMetamodel(); Set<String> columns = new HashSet<String>(); for (EntityType entityType : metamodel.getEntities()) { if (entityName.equals(entityType.getName())) { Set<Attribute> attributes = entityType.getAttributes(); for (Attribute attribute : attributes) { columns.add(attribute.getName()); }/*from ww w . j a v a 2s . c o m*/ } } return columns; }
From source file:com.hgsoft.example.hello.web.HelloServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPost"); WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); // String[] beanNames = context.getBeanDefinitionNames(); // if(beanNames != null) // {//from w w w. ja v a2s. c o m // for(String beanName:beanNames) // { // System.out.println("bean name >> "+beanName); // } // } // HelloWorldBusiness helloWorldBusiness = context.getBean("helloWorldBusiness",HelloWorldBusiness.class); // helloWorldBusiness.hello(); // BlueprintContainer container = (BlueprintContainer) getServletContext().getAttribute(BlueprintContextListener.CONTAINER_ATTRIBUTE); // // System.out.println("BlueprintContainer "+container); // // Set<String> componentIds = container.getComponentIds(); // if(componentIds != null) // { // for(String componentId:componentIds) // { // System.out.println("componentId >> "+componentId); // } // } //jndi? HelloWorldService helloWorldService = (HelloWorldService) JNDIHelper.getHelloWorldService(); helloWorldService.hello(); EntityManagerFactory emf = (EntityManagerFactory) context.getBean("entityManagerFactory"); Metamodel model = emf.getMetamodel(); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is the result of test: "); if (null != model) { if (null != model.getEntities()) { for (EntityType type : model.getEntities()) { out.print(type.getName()); } } } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }