本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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());
}
}
}
示例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);
}
}
}
}
示例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]);
}
示例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 );
}
}
}
示例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);
}
}
示例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);
}
}