Java Code Examples for org.hibernate.metadata.ClassMetadata.setPropertyValue()

The following are Jave code examples for showing how to use setPropertyValue() of the org.hibernate.metadata.ClassMetadata class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jeecms6   File: HibernateBaseDao.java   View Source Code Vote up 6 votes
/**
 * 将更新对象拷贝至实体对象,并处理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);
		}
	}
}
 
Example 2
Project: breeze.server.java   File: RelationshipFixer.java   View Source Code Vote up 6 votes
/**
 * Set an association value based on the value of the foreign key.  This updates the property of the entity.
 * @param propName Name of the navigation/association property of the entity, e.g. "Customer".  May be null if the property is the entity's identifier.
 * @param propType Type of the property
 * @param entityInfo Breeze EntityInfo
 * @param meta Metadata for the entity class
 */
private void fixupRelationship(String propName, EntityType propType, EntityInfo entityInfo, ClassMetadata meta)
{
    Object entity = entityInfo.entity;
    if (removeMode) {
        meta.setPropertyValue(entity, propName, null);
        return;
    }
    Object relatedEntity = getPropertyValue(meta, entity, propName);
    if (relatedEntity != null) {
        // entities are already connected - still need to add to dependency graph
        EntityInfo relatedEntityInfo = saveWorkState.findEntityInfo(relatedEntity);
        maybeAddToGraph(entityInfo, relatedEntityInfo, propType); 
        return;
    }

    relatedEntity = getRelatedEntity(propName, propType, entityInfo, meta);

    if (relatedEntity != null) {
        meta.setPropertyValue(entity, propName, relatedEntity);
    }
}
 
Example 3
Project: breeze.server.java   File: HibernateSaveProcessor.java   View Source Code Vote up 6 votes
/**
 * Restore the old value of the concurrency column so Hibernate will save the entity.
 * Otherwise it will complain because Breeze has already changed the value.
 * @param entityInfo
 * @param classMeta
 */
protected void restoreOldVersionValue(EntityInfo entityInfo, ClassMetadata classMeta) {
    if (entityInfo.originalValuesMap == null || entityInfo.originalValuesMap.size() == 0)
        return;
    int vcol = classMeta.getVersionProperty();
    String vname = classMeta.getPropertyNames()[vcol];
    if (entityInfo.originalValuesMap.containsKey(vname)) {
        Object oldVersion = entityInfo.originalValuesMap.get(vname);
        Object entity = entityInfo.entity;
        if (oldVersion == null) {
            _possibleErrors.add("Hibernate does not support 'null' version properties. " +
                    "Entity: " + entity + ", Property: " + vname);
        }
        Class versionClazz = classMeta.getPropertyTypes()[vcol].getReturnedClass();
        DataType dataType = DataType.fromClass(versionClazz);
        Object oldValue = DataType.coerceData(oldVersion, dataType);
        classMeta.setPropertyValue(entity, vname, oldValue);
    }
}
 
Example 4
Project: Lottery   File: HibernateBaseDao.java   View Source Code Vote up 6 votes
/**
 * 将更新对象拷贝至实体对象,并处理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);
		}
	}
}