當前位置: 首頁>>代碼示例>>Java>>正文


Java Metamodel.getEntities方法代碼示例

本文整理匯總了Java中javax.persistence.metamodel.Metamodel.getEntities方法的典型用法代碼示例。如果您正苦於以下問題:Java Metamodel.getEntities方法的具體用法?Java Metamodel.getEntities怎麽用?Java Metamodel.getEntities使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.persistence.metamodel.Metamodel的用法示例。


在下文中一共展示了Metamodel.getEntities方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getIdFieldNames

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
public static Set<String> getIdFieldNames(Metamodel metamodel, String entityName) {
	Set<String> ids = entityIdMap.get(entityName);
	if(ids == null) {
		ids = new HashSet<>();
		for(EntityType<?> et : metamodel.getEntities()) {
			if(et.getJavaType().getName().equals(entityName)) {
				if(et.hasSingleIdAttribute()) {
					ids.add(et.getId(et.getIdType().getJavaType()).getName());
				} else {
					for(SingularAttribute<?, ?> idAttribute : et.getIdClassAttributes()) {
						ids.add(idAttribute.getName());
					}
				}
			}
		}
	}
	if(ids.size() == 0) {
		ids.add("id");
	}
	return ids;
}
 
開發者ID:wwu-pi,項目名稱:tap17-muggl-javaee,代碼行數:22,代碼來源:EntityConstraintAnalyzer.java

示例2: printPersistenceModel

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
public void printPersistenceModel() {
    Metamodel metaModel = entityManager.getMetamodel();
    Set<EntityType<? extends Object>> types = metaModel.getEntities();
    for(EntityType<? extends Object> type : types) {
        logger.log(Level.INFO, "--> Type: {0}", type);
        Set attributes = type.getAttributes();
        for(Object obj : attributes) {
            logger.log(Level.INFO, "Name: {0}", ((Attribute)obj).getName());
            logger.log(Level.INFO, "isCollection: {0}", ((Attribute)obj).isCollection());
            logger.log(Level.INFO, "Name: {0}", ((Attribute)obj).isAssociation());
            logger.log(Level.INFO, "Name: {0}", ((Attribute)obj).getPersistentAttributeType());
        }
        
    }
    
    EntityType<Item> item = metaModel.entity(Item.class);
}
 
開發者ID:rcuprak,項目名稱:actionbazaar,代碼行數:18,代碼來源:ItemManager.java

示例3: allClassMapping

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
@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);
	}
}
 
開發者ID:XiaoChenYung,項目名稱:YCBugsManager,代碼行數:12,代碼來源:JpaMappingTest.java

示例4: listAssignableEntityTypes

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <E extends GenericEntity<?, ?>> List<Class<? extends E>> listAssignableEntityTypes(Class<E> superclass) {
	List<Class<? extends E>> classes = Lists.newLinkedList();
	Metamodel metamodel = entityManager.getMetamodel();
	for (EntityType<?> entity : metamodel.getEntities()) {
		Class<?> clazz = entity.getBindableJavaType();
		if (superclass.isAssignableFrom(clazz)) {
			classes.add((Class<? extends E>) clazz);
		}
	}
	return classes;
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:14,代碼來源:EntityDaoImpl.java

示例5: doInitialize

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void doInitialize() {

  super.doInitialize();
  if (this.entityManager == null) {
    throw new ResourceMissingException("entityManager");
  }
  if (this.pojoFactory == null) {
    DefaultPojoFactory factory = new DefaultPojoFactory();
    factory.initialize();
    this.pojoFactory = factory;
  }

  Metamodel metamodel = this.entityManager.getMetamodel();
  Set<EntityType<?>> entities = metamodel.getEntities();
  getLogger().info("EntityManager registered with " + entities.size() + " entities.");
  for (EntityType<?> entityType : entities) {
    Class<?> entityClass = entityType.getJavaType();
    if (entityClass == null) {
      // ignore entities that have no java type such as audit/jornal tables from envers.
    } else if (GenericEntity.class.isAssignableFrom(entityClass)) {
      if (!hasDao((Class<? extends GenericEntity<?>>) entityClass)) {
        JpaGenericDao manager = new JpaGenericDao(entityClass);
        manager.setEntityManager(this.entityManager);
        manager.setPojoFactory(this.pojoFactory);
        manager.initialize();
        addDao(manager);
        getLogger().info("Added generic manager for entity " + entityClass.getName());
      } else {
        getLogger().debug("Found registered manager for entity " + entityClass.getName());
      }
    } else {
      getLogger().warn(
          "Entity " + entityClass.getName() + " does NOT implement " + GenericEntity.class.getName());
    }
  }
}
 
開發者ID:m-m-m,項目名稱:persistence,代碼行數:42,代碼來源:PersistenceManagerImplJpa.java

示例6: addForeignKeys

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
private void addForeignKeys(MetadataFactory mf, Metamodel model, ManagedType<?> entity, Table entityTable) throws TranslatorException {
	for (Attribute<?, ?> attr:entity.getAttributes()) {
		if (attr.isCollection()) {
			
			PluralAttribute pa = (PluralAttribute)attr;
			Table forignTable = null;
			
			for (EntityType et:model.getEntities()) {
				if (et.getJavaType().equals(pa.getElementType().getJavaType())) {
					forignTable = mf.getSchema().getTable(et.getName());
					break;
				}
			}
			
			if (forignTable == null) {
				continue;
			}
			
			// add foreign keys as columns in table first; check if they exist first
			ArrayList<String> keys = new ArrayList<String>();
			KeyRecord pk = entityTable.getPrimaryKey();
			for (Column entityColumn:pk.getColumns()) {
				addColumn(mf, entityColumn.getName(), entityColumn.getDatatype().getRuntimeTypeName(), forignTable);
				keys.add(entityColumn.getName());
			}

			if (!foreignKeyExists(keys, forignTable)) {
				addForiegnKey(mf, attr.getName(), keys, entityTable.getName(), forignTable);
			}
		}
	}
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:33,代碼來源:JPAMetadataProcessor.java

示例7: buildCreateCurrentSchema

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
private static String[] buildCreateCurrentSchema(CatalogDAO c, Properties catalogProperties) throws PEException {
	ArrayList<String> buf = new ArrayList<String>();
	EntityManagerFactory emf = c.getEntityManager().getEntityManagerFactory();
	Configuration cfg = new Configuration();
	Metamodel model = emf.getMetamodel();
	for(EntityType<?> e : model.getEntities()) {
		cfg.addAnnotatedClass(e.getBindableJavaType());
	}
	String[] out = cfg.generateSchemaCreationScript(Dialect.getDialect(catalogProperties));
	buf.addAll(Arrays.asList(out));
	buf.addAll(Arrays.asList(getAdditionalCommands()));
	// current version table must be last - necessary for the upgraded code needed test
	buf.addAll(CatalogVersions.getCurrentVersion().buildCurrentVersionTable());
	return buf.toArray(new String[0]);
}
 
開發者ID:Tesora,項目名稱:tesora-dve-pub,代碼行數:16,代碼來源:CatalogSchemaGenerator.java

示例8: parse

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
public void parse(Metamodel metaModel) {
	// clear the (old) state
	this.isRootType.clear();
	this.managedTypes.clear();
	this.idProperties.clear();
	this.managedTypes.clear();
	this.managedTypes.putAll(
			metaModel.getManagedTypes().stream().filter(
					(meta3) -> {
						return meta3 instanceof EntityType;
					}
			).collect(
					Collectors.toMap(
							(meta) -> {
								return meta.getJavaType();
							}, (meta2) -> {
								return meta2;
							}
					)
			)
	);
	Set<EntityType<?>> emptyVisited = Collections.emptySet();
	this.totalVisitedEntities.clear();
	for ( EntityType<?> curEntType : metaModel.getEntities() ) {
		// we only consider Entities that are @Indexed here
		if ( curEntType.getJavaType().isAnnotationPresent( Indexed.class ) ) {
			this.idProperties.put( curEntType.getJavaType(), this.getIdProperty( metaModel, curEntType ) );
			this.isRootType.put( curEntType.getJavaType(), true );
			Map<Class<? extends Annotation>, Set<Attribute<?, ?>>> attributeForAnnotationType = buildAttributeForAnnotationType(
					curEntType
			);
			// and do the recursion
			this.doRecursion( attributeForAnnotationType, curEntType, emptyVisited );
		}
	}
}
 
開發者ID:Hotware,項目名稱:Hibernate-Search-GenericJPA,代碼行數:37,代碼來源:MetaModelParser.java

示例9: allClassMapping

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
@Test
public void allClassMapping() throws Exception {
	Metamodel model = em.getEntityManagerFactory().getMetamodel();
	
	assertTrue("No entity mapping found", model.getEntities().size() > 0);

	for (EntityType entityType : model.getEntities()) {
		String entityName = entityType.getName();
		em.createQuery("select o from " + entityName + " o").getResultList();
		logger.info("ok: " + entityName);

	}
}
 
開發者ID:Michaelleolee,項目名稱:appengine,代碼行數:14,代碼來源:JpaMappingTest.java

示例10: allClassMapping

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
@Test
public void allClassMapping() throws Exception {
	Metamodel model = em.getEntityManagerFactory().getMetamodel();

	assertTrue("No entity mapping found", model.getEntities().size() > 0);

	for (EntityType entityType : model.getEntities()) {
		String entityName = entityType.getName();
		em.createQuery("select o from " + entityName + " o").getResultList();
		logger.info("ok: " + entityName);
	}
}
 
開發者ID:Michaelleolee,項目名稱:appengine,代碼行數:13,代碼來源:JpaMappingTest.java


注:本文中的javax.persistence.metamodel.Metamodel.getEntities方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。