@Override public void setAttribute(String name, Object value) throws LayerException { metadata.setPropertyValue(object, name, value, EntityMode.POJO); }
@Override public void setChild(String name, Entity entity) throws LayerException { if (entity != null) { metadata.setPropertyValue(object, name, ((HibernateEntity) entity).getObject(), EntityMode.POJO); } else { metadata.setPropertyValue(object, name, null, EntityMode.POJO); } }
@Override public void removeEntity(Entity entity) throws LayerException { Object object = ((HibernateEntity) entity).getObject(); // remove parent from many-to-one if (parentName != null) { metadata.setPropertyValue(object, parentName, null, EntityMode.POJO); } objects.remove(object); }
@Override @SuppressWarnings("unchecked") public void addEntity(Entity entity) throws LayerException { Object object = ((HibernateEntity) entity).getObject(); // assign parent to many-to-one if (parentName != null) { metadata.setPropertyValue(object, parentName, parent, EntityMode.POJO); } objects.add(object); }
@Override public void setPropertyValue(final Object object, final String propertyName, final Object value) throws HibernateException { metadata.setPropertyValue(PropertyValueAdapter.adaptToV5(object), propertyName, value); }
metadata.setPropertyValue(object, property, value); } else if (type.isCollectionType()) { // 多对多 Object[] values = Beans.toArray(Object.class, value); metadata.setPropertyValue(object, property, objects); metadata.setPropertyValue(object, property, Beans.toObject(meta, value));
/** * 将更新对象拷贝至实体对象,并处理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); } catch (Exception e) { throw new RuntimeException("copy property to persistent object failed: '" + propName + "'", e); } } }
/** * 将更新对象拷贝至实体对象,并处理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); } catch (Exception e) { throw new RuntimeException("copy property to persistent object failed: '" + propName + "'", e); } } }
/** * 将更新对象拷贝至实体对象,并处理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); } catch (Exception e) { throw new RuntimeException("copy property to persistent object failed: '" + propName + "'", e); } } }
private Object createIndex(Content content) { ContentContainer container = content.getContainer(); if (container != null) { Object owner = container.getOwner(); if (owner != null) { String ownerClassName = Hibernate.getClass(owner).getName(); ClassMetadata meta = getIndexClassMetadata(ownerClassName); if (meta != null) { ContentIndex index = (ContentIndex) meta.instantiate(content.getId(), (SessionImplementor) sessionFactory.getCurrentSession()); String ownerProperty = StringUtils.uncapitalize(StringUtils.unqualify(ownerClassName)); meta.setPropertyValue(index, ownerProperty, owner); index.setContent(content); return index; } } } return null; }
@Override public EntityCollection getChildCollection(String name) throws LayerException { Type type = metadata.getPropertyType(name); if (type instanceof CollectionType) { CollectionType ct = (CollectionType) type; Collection coll = (Collection) metadata.getPropertyValue(object, name, EntityMode.POJO); if (coll == null) { // normally should not happen, hibernate instantiates it automatically coll = (Collection) ct.instantiate(0); metadata.setPropertyValue(object, name, coll, EntityMode.POJO); } String entityName = ct.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory); ClassMetadata childMetadata = sessionFactory.getClassMetadata(entityName); return new HibernateEntityCollection(metadata, childMetadata, object, coll); } else { throw new LayerException(ExceptionCode.FEATURE_MODEL_PROBLEM); } }