List of usage examples for javax.persistence.metamodel ManagedType getJavaType
Class<X> getJavaType();
From source file:org.querybyexample.jpa.JpaUtil.java
public static <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) { try {/*from w w w . j a va2 s. c om*/ Method m = BeanUtils.findMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName())); if (m != null && m.getAnnotation(Id.class) != null) { return true; } Field field = mt.getJavaType().getField(attr.getName()); return field.getAnnotation(Id.class) != null; } catch (Exception e) { return false; } }
From source file:de.micromata.genome.jpa.metainf.MetaInfoUtils.java
/** * To entity meta data./*w w w . j a va 2 s.c o m*/ * * @param mt the mt * @return the entity metadata */ private static EntityMetadata toEntityMetaData(ManagedType<?> mt) { EntityMetadataBean ret = new EntityMetadataBean(); ret.setJavaType(mt.getJavaType()); if (mt instanceof EntityType) { EntityType ift = (EntityType) mt; ret.setDatabaseName(ift.getName()); } // TODO RK delete propDesc List<PropertyDescriptor> propDescs = Arrays.asList(PropertyUtils.getPropertyDescriptors(ret.getJavaType())); Set<?> attr = mt.getAttributes(); for (Object oa : attr) { Attribute<?, ?> at = (Attribute<?, ?>) oa; Optional<PropertyDescriptor> pdo = propDescs.stream().filter((el) -> el.getName().equals(at.getName())) .findFirst(); ColumnMetadata colm = getColumnMetaData(ret, mt.getJavaType(), at, pdo); if (colm != null) { ret.getColumns().put(colm.getName(), colm); } } /// EntityType.getName() is not correct. Table[] tabs = mt.getJavaType().getAnnotationsByType(Table.class); if (tabs != null && tabs.length > 0) { for (Table tab : tabs) { if (StringUtils.isNotBlank(tab.name()) == true) { ret.setDatabaseName(tab.name()); break; } } } return ret; }
From source file:org.lightadmin.core.config.bootstrap.JpaMetamodelMappingContextFactoryBean.java
@Override protected JpaMetamodelMappingContext createInstance() throws Exception { Metamodel metamodel = entityManager.getMetamodel(); Set<ManagedType<?>> managedTypes = metamodel.getManagedTypes(); Set<Class<?>> entitySources = new HashSet<Class<?>>(managedTypes.size()); for (ManagedType<?> type : managedTypes) { Class<?> javaType = type.getJavaType(); if (javaType != null) { entitySources.add(javaType); }// w ww . j a v a 2 s .c om } Set<Metamodel> metaModelSet = new HashSet<>(Collections.singletonList(metamodel)); JpaMetamodelMappingContext context = new JpaMetamodelMappingContext(metaModelSet); context.setInitialEntitySet(entitySources); context.initialize(); return context; }
From source file:org.azrul.langkuik.Langkuik.java
public void initLangkuik(final EntityManagerFactory emf, final UI ui, final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) { List<Class<?>> rootClasses = new ArrayList<>(); for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) { Class<?> clazz = entity.getJavaType(); if (clazz.getAnnotation(WebEntity.class).isRoot() == true) { rootClasses.add(clazz);/* w ww .j av a 2 s .co m*/ } } //Manage custom type if (customTypeInterfaces == null) { customTypeInterfaces = new ArrayList<>(); } //add system level custom type customTypeInterfaces.add(AttachmentCustomType.class); //create DAOs for custom types final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>(); for (Class<?> clazz : customTypeInterfaces) { customTypeDaos.add(new HibernateGenericDAO(emf, clazz)); } //Setup page VerticalLayout main = new VerticalLayout(); VerticalLayout content = new VerticalLayout(); final Navigator navigator = new Navigator(ui, content); final HorizontalLayout breadcrumb = new HorizontalLayout(); MenuBar menubar = new MenuBar(); menubar.setId("MENUBAR"); main.addComponent(menubar); main.addComponent(breadcrumb); main.addComponent(content); final Deque<History> history = new ArrayDeque<>(); final Configuration config = Configuration.getInstance(); history.push(new History("START", "Start")); StartView startView = new StartView(history, breadcrumb); navigator.addView("START", startView); MenuBar.MenuItem create = menubar.addItem("Create", null); MenuBar.MenuItem view = menubar.addItem("View", null); final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history, config, breadcrumb); for (final Class rootClass : rootClasses) { final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class); final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass); create.addItem("New " + myObject.name(), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { Object object = dao.createNew(true); BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter); String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString(); navigator.addView(targetView, (View) createNewView); history.clear(); history.push(new History("START", "Start")); History his = new History(targetView, "Create new " + myObject.name()); history.push(his); navigator.navigateTo(targetView); } }); view.addItem("View " + myObject.name(), new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter); String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString(); navigator.addView(targetView, (View) seeApplicationView); history.clear(); history.push(new History("START", "Start")); History his = new History(targetView, "View " + myObject.name()); history.push(his); navigator.navigateTo(targetView); } }); } menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am", "Not quite", new ConfirmDialog.Listener() { @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest(); HttpServletResponse resp = (HttpServletResponse) VaadinService .getCurrentResponse(); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler(); ctxLogOut.logout(req, resp, auth); } } }); } }); navigator.navigateTo("START"); ui.setContent(main); }
From source file:com.dbs.sdwt.jpa.JpaUtil.java
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) { try {// w w w. j a v a 2 s . c o m Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null); if (m != null && m.getAnnotation(Id.class) != null) { return true; } Field field = mt.getJavaType().getField(attr.getName()); return field.getAnnotation(Id.class) != null; } catch (Exception e) { return false; } }
From source file:com.impetus.client.cassandra.CassandraClientBase.java
/** * Find./*www . jav a 2s .c o m*/ * * @param clazz * the clazz * @param metadata * the metadata * @param rowId * the row id * @param relationNames * the relation names * @return the object */ private final Object find(Class<?> clazz, EntityMetadata metadata, Object rowId, List<String> relationNames) { List<Object> result = null; try { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata() .getMetamodel(metadata.getPersistenceUnit()); EntityType entityType = metaModel.entity(clazz); List<ManagedType> subTypes = ((AbstractManagedType) entityType).getSubManagedType(); if (!subTypes.isEmpty()) { for (ManagedType subEntity : subTypes) { EntityMetadata subEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, subEntity.getJavaType()); result = populate(clazz, subEntityMetadata, rowId, subEntityMetadata.getRelationNames(), metaModel); if (result != null && !result.isEmpty()) { break; } } } else { result = populate(clazz, metadata, rowId, relationNames, metaModel); } } catch (Exception e) { log.error("Error while retrieving records from database for entity {} and key {}, Caused by: .", clazz, rowId, e); throw new PersistenceException(e); } return result != null && !result.isEmpty() ? result.get(0) : null; }
From source file:org.kuali.rice.krad.data.jpa.JpaPersistenceProvider.java
/** * {@inheritDoc}//w w w .ja v a2s .c o m */ @Override public boolean handles(final Class<?> type) { if (managedTypesCache == null) { managedTypesCache = new HashSet<Class<?>>(); Set<ManagedType<?>> managedTypes = sharedEntityManager.getMetamodel().getManagedTypes(); for (ManagedType managedType : managedTypes) { managedTypesCache.add(managedType.getJavaType()); } } if (managedTypesCache.contains(type)) { return true; } else { return false; } }