本文整理匯總了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);
}
}