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


Java Metamodel.managedType方法代碼示例

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


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

示例1: getPath

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
@SuppressWarnings({"rawtypes", "unchecked", "serial"})
    public Path getPath(From root, FieldPath fieldPath, final CriteriaBuilder builder) {
        FieldPath myFieldPath = fieldPath;
        if (!StringUtils.isEmpty(fieldPath.getTargetProperty())) {
            myFieldPath = getFieldPath(root, fieldPath.getTargetProperty());
        }
        From myRoot = root;
        for (String pathElement : myFieldPath.getAssociationPath()) {
            myRoot = myRoot.join(pathElement);
        }
        Path path = myRoot;
        
        for (int i = 0; i < myFieldPath.getTargetPropertyPieces().size(); i++) {
            String piece = myFieldPath.getTargetPropertyPieces().get(i);
            
            if (path.getJavaType().isAnnotationPresent(Embeddable.class)) {
                String original = ((SingularAttributePath) path).getAttribute().getDeclaringType().getJavaType().getName() + "." + ((SingularAttributePath) path).getAttribute().getName() + "." + piece;
                String copy = path.getJavaType().getName() + "." + piece;
                copyCollectionPersister(original, copy, ((CriteriaBuilderImpl) builder).getEntityManagerFactory().getSessionFactory());
            }
            
            try {
                path = path.get(piece);
            } catch (IllegalArgumentException e) {
                // We weren't able to resolve the requested piece, likely because it's in a polymoprhic version
                // of the path we're currently on. Let's see if there's any polymoprhic version of our class to
                // use instead.
        	    EntityManagerFactoryImpl em = ((CriteriaBuilderImpl) builder).getEntityManagerFactory();
        	    Metamodel mm = em.getMetamodel();
        	    boolean found = false;
        	    
        	    Class<?>[] polyClasses = dynamicDaoHelper.getAllPolymorphicEntitiesFromCeiling(
        	            path.getJavaType(), em.getSessionFactory(), true, true);
        	    
        	    for (Class<?> clazz : polyClasses) {
            		ManagedType mt = mm.managedType(clazz);
            		try {
            		    Attribute attr = mt.getAttribute(piece);
            		    if (attr != null) {
                		    Root additionalRoot = criteria.from(clazz);
                		    restrictions.add(builder.equal(path, additionalRoot));
                		    path = additionalRoot.get(piece);
                		    found = true;
                		    break;
            		    }
            		} catch (IllegalArgumentException e2) {
            		    // Do nothing - we'll try the next class and see if it has the attribute
            		}
        	    }
        	    
        	    if (!found) {
        	        throw new IllegalArgumentException("Could not resolve requested attribute against path, including" +
        	        		" known polymorphic versions of the root", e);
        	    }
            }
            
            if (path.getParentPath() != null && path.getParentPath().getJavaType().isAnnotationPresent(Embeddable.class) && path instanceof PluralAttributePath) {
                //We need a workaround for this problem until it is resolved in Hibernate (loosely related to and likely resolved by https://hibernate.atlassian.net/browse/HHH-8802)
                //We'll throw a specialized exception (and handle in an alternate flow for calls from BasicPersistenceModule)
                throw new CriteriaConversionException(String.format("Unable to create a JPA criteria Path through an @Embeddable object to a collection that resides therein (%s)", fieldPath.getTargetProperty()), fieldPath);
//                //TODO this code should work, but there still appear to be bugs in Hibernate's JPA criteria handling for lists
//                //inside Embeddables
//                Class<?> myClass = ((PluralAttributePath) path).getAttribute().getClass().getInterfaces()[0];
//                //we don't know which version of "join" to call, so we'll let reflection figure it out
//                try {
//                    From embeddedJoin = myRoot.join(((SingularAttributePath) path.getParentPath()).getAttribute());
//                    Method join = embeddedJoin.getClass().getMethod("join", myClass);
//                    path = (Path) join.invoke(embeddedJoin, ((PluralAttributePath) path).getAttribute());
//                } catch (Exception e) {
//                    throw new RuntimeException(e);
//                }
            }
        }

        return path;
    }
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:77,代碼來源:FieldPathBuilder.java

示例2: EntityInformation

import javax.persistence.metamodel.Metamodel; //導入方法依賴的package包/類
/**
 * 構造函數.
 *
 * @param domainClass 實體類CLASS
 * @param metamodel 模型元數據,可從jpa的實體管理器EntityManage獲取
 */
public EntityInformation(Class<T> domainClass, Metamodel metamodel) {

  ManagedType<T> type = metamodel.managedType(domainClass);

  this.entityName = ((EntityType<?>) type).getName();

  IdentifiableType<T> identifiableType = (IdentifiableType<T>) type;

  this.idMetadata = new IdMetadata<T>(identifiableType);
}
 
開發者ID:ibankapp,項目名稱:ibankapp-base,代碼行數:17,代碼來源:EntityInformation.java


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