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


Java ClassMetadata.getIdentifierPropertyName方法代碼示例

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


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

示例1: getIdName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
/**
 * 取得對象的主鍵名,輔助函數.
 * 
 * @param entityClass
 *            實體類型
 * @return 主鍵名稱
 */
public String getIdName(Class entityClass) {
    Assert.notNull(entityClass);
    entityClass = ReflectUtils.getOriginalClass(entityClass);

    ClassMetadata meta = this.getSessionFactory().getClassMetadata(
            entityClass);
    Assert.notNull(meta, "Class " + entityClass
            + " not define in hibernate session factory.");

    String idName = meta.getIdentifierPropertyName();
    Assert.hasText(idName, entityClass.getSimpleName()
            + " has no identifier property define.");

    return idName;
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:23,代碼來源:HibernateBasicDao.java

示例2: _countRows

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
private TreeMap<String, Object> _countRows(Object value) {
    ClassMetadata meta = getSessionFactory().getClassMetadata(value.getClass());
    String idName = meta.getIdentifierPropertyName();
    Serializable idValue = meta.getIdentifier(value, (SessionImplementor)getTmpSession());

    ArrayList<String[]> fieldSets;
    if(this._fields.length > 0){
        fieldSets = _prepareFields();
    }else{
        fieldSets = _getFieldsFromUniqueConstraint(value);
        fieldSets.addAll(_extractFieldsFromObject(value));
    }

    for(String[] fieldSet : fieldSets){
        TreeMap<String, Object> fieldMap = new TreeMap<>();
        for(String fieldName: fieldSet){
            fieldMap.put(fieldName, meta.getPropertyValue(value, fieldName));
        }
        if(_hasRecord(value, fieldMap, idName, idValue, meta)){
            return fieldMap;
        }
    }

    return null;
}
 
開發者ID:Klinton90,項目名稱:UniqueValidator,代碼行數:26,代碼來源:UniqueValidator.java

示例3: extractIdPropertyNames

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@Override
public String[] extractIdPropertyNames(Object entity)
{
    final IdClass idClassAnn = entity.getClass().getAnnotation(IdClass.class);
    if (idClassAnn != null)
    {
        final Class<?> entityClass = idClassAnn.value();
        final List<String> retVal = new ArrayList<>(3);
        ReflectionUtils.doWithFields(entityClass, (f)->
           {
               if (! Modifier.isStatic(f.getModifiers()))
               {
                   retVal.add(f.getName());
               }
           });
        return retVal.toArray(new String[retVal.size()]);
    }
    else
    {
        final ClassMetadata classMetadata = factory.getClassMetadata(entity.getClass());
        final String propertyName = classMetadata.getIdentifierPropertyName();
        return propertyName != null ? new String[]{propertyName} : null;
    }
}
 
開發者ID:ethlo,項目名稱:dachs,代碼行數:25,代碼來源:HibernateLazyIdExtractor.java

示例4: getIdMetadata

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
    Map<String, Object> response = new HashMap<String, Object>();
    SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
    
    ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
    if (metadata == null) {
        return null;
    }
    
    String idProperty = metadata.getIdentifierPropertyName();
    response.put("name", idProperty);
    Type idType = metadata.getIdentifierType();
    response.put("type", idType);

    return response;
}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:18,代碼來源:DynamicDaoHelperImpl.java

示例5: updaterCopyToPersistentObject

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
/**
 * 將更新對象拷貝至實體對象,並處理many-to-one的更新。
 * 
 * @param updater
 * @param po
 */
private void updaterCopyToPersistentObject(Updater<T> updater, T po,
		ClassMetadata cm) {
	String[] propNames = cm.getPropertyNames();
	String identifierName = cm.getIdentifierPropertyName();
	T bean = updater.getBean();
	Object value;
	for (String propName : propNames) {
		if (propName.equals(identifierName)) {
			continue;
		}
		try {
			value = MyBeanUtils.getSimpleProperty(bean, propName);
			if (!updater.isUpdate(propName, value)) {
				continue;
			}
			cm.setPropertyValue(po, propName, value, POJO);
		} catch (Exception e) {
			throw new RuntimeException(
					"copy property to persistent object failed: '"
							+ propName + "'", e);
		}
	}
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:30,代碼來源:HibernateBaseDao.java

示例6: getIdMetadata

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
    entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
    Map<String, Object> response = new HashMap<String, Object>();
    SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
    
    ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
    if (metadata == null) {
        return null;
    }
    
    String idProperty = metadata.getIdentifierPropertyName();
    response.put("name", idProperty);
    Type idType = metadata.getIdentifierType();
    response.put("type", idType);

    return response;
}
 
開發者ID:takbani,項目名稱:blcdemo,代碼行數:19,代碼來源:DynamicDaoHelperImpl.java

示例7: get

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T extends Serializable, I extends Serializable> T get(Class<T> type, I id) {
    Object idv = id;
    String name = type.getName();
    ClassMetadata classMetadata = (ClassMetadata) new MetadataResolver().getAllClassMetadata(sessionFactory).get(name);
    String oid = classMetadata.getIdentifierPropertyName();
    if (id instanceof String) {
        IdentifierType<?> identifierType = (IdentifierType<?>) classMetadata.getIdentifierType();
        if (!(identifierType instanceof StringType)) {
            try {
                idv = identifierType.stringToObject((String) id);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    QueryParameters hql = new QueryParameters("from " + name + " where " + oid + "=:" + oid,
            new QueryParameter().setName(oid).setValueTypeText(idv));
    logger.debug("hql={}", hql);
    List<Serializable> value = execute(hql).getResults().getValue();
    return (T) (value.isEmpty() ? null : value.get(0));
}
 
開發者ID:jurgendl,項目名稱:hql-builder,代碼行數:24,代碼來源:HqlServiceImpl.java

示例8: getPrimaryKeyPropertyName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@Override
public String getPrimaryKeyPropertyName() {
    ClassMetadata classMetadata = getClassMetadata();
    if (classMetadata == null) {
        return null;
    }

    if (classMetadata.hasIdentifierProperty() == true) {
        return classMetadata.getIdentifierPropertyName();
    } else {
        return null;
    }
}
 
開發者ID:ix3,項目名稱:ix3,代碼行數:14,代碼來源:MetaDataImplHibernate.java

示例9: getIdName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
/**
 * 取得對象的主鍵名.
 */
public String getIdName() {
    ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
    return meta.getIdentifierPropertyName();
}
 
開發者ID:dragon-yuan,項目名稱:Ins_fb_pictureSpider_WEB,代碼行數:8,代碼來源:GenericDao.java

示例10: getIdName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
@Override
public String getIdName() {
	ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
	return meta.getIdentifierPropertyName();
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:6,代碼來源:SimpleHibernateDao.java

示例11: getIdName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
/**
 * 取得對象的主鍵名.
 */
public String getIdName() {
	ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
	return meta.getIdentifierPropertyName();
}
 
開發者ID:wanliyang10010,項目名稱:Shop,代碼行數:8,代碼來源:HibernateRepository.java

示例12: loadByExample

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
private Object loadByExample(PageContext pc, Object obj,  boolean unique) throws PageException {
	Component cfc=HibernateCaster.toComponent(obj);
	Key dsn = KeyImpl.init(ORMUtil.getDataSourceName(pc, cfc));
	ComponentScope scope = cfc.getComponentScope();
	String name=HibernateCaster.getEntityName(cfc);
	Session sess = getSession(dsn);
	Object rtn=null;

	try{
		//trans.begin();
		
		ClassMetadata metaData = sess.getSessionFactory().getClassMetadata(name);
		String idName = metaData.getIdentifierPropertyName();
		Type idType = metaData.getIdentifierType();
	 
		Criteria criteria=sess.createCriteria(name);
		if(!Util.isEmpty(idName)){
			Object idValue = scope.get(CommonUtil.createKey(idName),null);
			if(idValue!=null){
				criteria.add(Restrictions.eq(idName, HibernateCaster.toSQL(idType, idValue,null)));
			}
		}
		criteria.add(Example.create(cfc));
     
     	// execute
		
		if(!unique){
			rtn = criteria.list();
		}
		else {
			//Map map=(Map) criteria.uniqueResult();
			rtn= criteria.uniqueResult();
		}
	 }
	 catch(Throwable t){
		lucee.commons.lang.ExceptionUtil.rethrowIfNecessary(t);
		// trans.rollback();
		throw CommonUtil.toPageException(t);
	 }
	 //trans.commit();

	 return rtn;
}
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:44,代碼來源:HibernateORMSession.java

示例13: GrailsHibernateDomainClass

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
/**
 * Contructor to be used by all child classes to create a new instance
 * and get the name right.
 *
 * @param clazz          the Grails class
 * @param sessionFactory The Hibernate SessionFactory instance
 * @param metaData       The ClassMetaData for this class retrieved from the SF
 * @param defaultConstraints The default global constraints definition
 */
public GrailsHibernateDomainClass(Class<?> clazz, SessionFactory sessionFactory, GrailsApplication application, ClassMetadata metaData, Map<String, Object> defaultConstraints) {
	super(clazz, "");
	this.application = application;

	new StandardAnnotationMetadata(clazz);
	String ident = metaData.getIdentifierPropertyName();
	this.defaultConstraints = defaultConstraints;
	if (ident != null) {
		Class<?> identType = getPropertyType(ident);
		this.identifier = new GrailsHibernateDomainClassProperty(this, ident);
		this.identifier.setIdentity(true);
		this.identifier.setType(identType);
		this.propertyMap.put(ident, this.identifier);
	}

	// configure the version property
	final int versionIndex = metaData.getVersionProperty();
	String versionPropertyName = null;
	if (versionIndex > -1) {
		versionPropertyName = metaData.getPropertyNames()[versionIndex];
		this.version = new GrailsHibernateDomainClassProperty(this, versionPropertyName);
		this.version.setType(getPropertyType(versionPropertyName));
	}

	// configure remaining properties
	String[] propertyNames = metaData.getPropertyNames();
	boolean[] propertyNullablility = metaData.getPropertyNullability();
	for (int i = 0; i < propertyNames.length; i++) {
		String propertyName = propertyNames[i];
		if (!propertyName.equals(ident) && !(versionPropertyName != null && propertyName.equals(versionPropertyName))) {
			GrailsHibernateDomainClassProperty prop = new GrailsHibernateDomainClassProperty(this, propertyName);
			prop.setType(getPropertyType(propertyName));
			Type hibernateType = metaData.getPropertyType(propertyName);

			// if its an association type
			if (hibernateType.isAssociationType()) {
				prop.setAssociation(true);
				// get the associated type from the session factory and set it on the property
				AssociationType assType = (AssociationType) hibernateType;
				if (assType instanceof AnyType) {
					continue;
				}
				try {
					String associatedEntity = assType.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
					ClassMetadata associatedMetaData = sessionFactory.getClassMetadata(associatedEntity);
					prop.setRelatedClassType(associatedMetaData.getMappedClass(EntityMode.POJO));
				} catch (MappingException me) {
					// other side must be a value object
					if (hibernateType.isCollectionType()) {
						prop.setRelatedClassType(Collection.class);
					}
				}
				// configure type of relationship
				if (hibernateType.isCollectionType()) {
					prop.setOneToMany(true);
				} else if (hibernateType.isEntityType()) {
					prop.setManyToOne(true);
					// might not really be true, but for our purposes this is ok
					prop.setOneToOne(true);
				}

				prop.setOptional(propertyNullablility[i]);
			}
			this.propertyMap.put(propertyName, prop);
		}
	}

	this.properties = this.propertyMap.values().toArray(new GrailsDomainClassProperty[this.propertyMap.size()]);
	// process the constraints
	evaluateConstraints();
}
 
開發者ID:curtiszimmerman,項目名稱:AlgoTrader,代碼行數:81,代碼來源:GrailsHibernateDomainClass.java

示例14: getIdPropertyName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
protected String getIdPropertyName() {
	ClassMetadata meta = getSessionFactory().getClassMetadata(entityType);
	return meta.getIdentifierPropertyName();
}
 
開發者ID:VonChange,項目名稱:haloDao-Hibernate3,代碼行數:5,代碼來源:HaloDao.java

示例15: getIdName

import org.hibernate.metadata.ClassMetadata; //導入方法依賴的package包/類
public String getIdName() {
	ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
	return meta.getIdentifierPropertyName();
}
 
開發者ID:iamtowne,項目名稱:yscardII,代碼行數:5,代碼來源:SimpleHibernateDao.java


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