/** * Set the tenantId onto the bean. */ public void setTenantValue(EntityBean entityBean, Object tenantId) { setValue(entityBean, tenantId); }
/** * Load the given value into the property. */ public void load(BeanProperty target, Object dbVal) { if (!refreshLoading) { target.setValue(bean, dbVal); } else { target.setValueIntercept(bean, dbVal); } } }
/** * Set the draft to true for this entity bean instance. * This bean is being loaded via asDraft() query. */ @Override public void setDraft(EntityBean entityBean) { if (draft != null) { draft.setValue(entityBean, true); } }
public Object load(BeanProperty prop) { if (!rawSql && !prop.isLoadProperty(ctx.isDraftQuery())) { return null; } if ((bean == null) || (lazyLoading && ebi.isLoadedProperty(prop.getPropertyIndex())) || (type != null && !prop.isAssignableFrom(type))) { // ignore this property // ... null: bean already in persistence context // ... lazyLoading: partial bean that is lazy loading // ... type: inheritance and not assignable to this instance prop.loadIgnore(ctx); return null; } try { Object dbVal = prop.read(ctx); if (!refreshLoading) { prop.setValue(bean, dbVal); } else { prop.setValueIntercept(bean, dbVal); } return dbVal; } catch (Exception e) { bean._ebean_getIntercept().setLoadError(prop.getPropertyIndex(), e); ctx.handleLoadError(prop.getFullBeanName(), e); return prop.getValue(bean); } }
@Override public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException { Object id = idProperty.read(ctx); if (id != null) { idProperty.setValue(bean, id); } return id; }
public void preUpdate(EntityBean bean, long now) { Object value = generatedProperty.getUpdateValue(property, bean, now); property.setValue(bean, value); } }
@Override public void populate(EntityBean sourceBean, EntityBean embeddedId) { Object value = foreignProp.getValue(sourceBean); localProp.setValue(embeddedId, value); }
/** * Read the value for this property from L2 cache entry and set it to the bean. * <p> * This uses parse() as per the comment in getCacheDataValue(). * </p> */ public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceContext context) { if (cacheData instanceof String) { // parse back from string to support optimisation of java object serialisation cacheData = scalarType.parse((String) cacheData); } setValue(bean, cacheData); }
public void preInsert(EntityBean bean, long now) { Object value = generatedProperty.getInsertValue(property, bean, now); property.setValue(bean, value); }
/** * Set the join properties from the parent bean to the child bean. * This is only valid for OneToMany and NOT valid for ManyToMany. */ public void setJoinValuesToChild(EntityBean parent, EntityBean child, Object mapKeyValue) { if (mapKeyProperty != null) { mapKeyProperty.setValue(child, mapKeyValue); } if (!manyToMany && childMasterProperty != null) { // bidirectional in the sense that the 'master' property // exists on the 'detail' bean childMasterProperty.setValue(child, parent); } }
@Override public void populate(EntityBean sourceBean, EntityBean embeddedId) { Object assocBean = assocOne.getValue(sourceBean); if (assocBean == null) { throw new NullPointerException("The assoc bean for " + assocOne + " is null?"); } Object value = foreignProp.getValue((EntityBean) assocBean); localProp.setValue(embeddedId, value); }
/** * Convert back from a Map to embedded bean. */ @Override @SuppressWarnings("unchecked") public Object convertIdFromJson(Object value) { Map<String, Object> map = (Map<String, Object>) value; EntityBean idValue = idDesc.createEntityBean(); for (BeanProperty prop : props) { Object val = map.get(prop.getName()); prop.setValue(idValue, val); } return idValue; }
public Object readSet(DataReader reader, EntityBean bean) throws SQLException { try { Object value = scalarType.read(reader); if (bean != null) { setValue(bean, value); } return value; } catch (Exception e) { throw new PersistenceException("Error readSet on " + descriptor + "." + name, e); } }
/** * Set the changed value without invoking interception (lazy loading etc). * Typically used to set generated values on update. */ public void setValueChanged(EntityBean bean, Object value) { setValue(bean, value); bean._ebean_getIntercept().setChangedProperty(propertyIndex); }
/** * Set the soft delete property value on the bean without invoking lazy loading. */ public void setSoftDeleteValue(EntityBean bean) { // assumes boolean deleted true being set which is ok limitation for now setValue(bean, true); bean._ebean_getIntercept().setChangedProperty(propertyIndex); }
@Override public Object readData(DataInput dataInput) throws IOException { EntityBean embId = idDesc.createEntityBean(); boolean notNull = true; for (BeanProperty prop : props) { Object value = prop.readData(dataInput); prop.setValue(embId, value); if (value == null) { notNull = false; } } if (notNull) { return embId; } else { return null; } }
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException { try { Object value = scalarType.read(ctx.getDataReader()); if (bean != null) { setValue(bean, value); } return value; } catch (Exception e) { throw new PersistenceException("Error readSet on " + descriptor + "." + name, e); } }
/** * Set the parent bean to the child bean if it has not already been set. */ public void setParentBeanToChild(EntityBean parent, EntityBean child) { if (primaryKeyExport) { Object parentId = descriptor.getId(parent); targetDescriptor.convertSetId(parentId, child); } if (mappedBy != null) { BeanProperty beanProperty = targetDescriptor.getBeanProperty(mappedBy); if (beanProperty != null && beanProperty.getValue(child) == null) { // set the 'parent' bean to the 'child' bean beanProperty.setValue(child, parent); } } } }
private static EntityBean createSharableBean(BeanDescriptor<?> desc, EntityBean bean, EntityBeanIntercept beanEbi) { if (!desc.isCacheSharableBeans() || !beanEbi.isFullyLoadedBean()) { return null; } if (beanEbi.isReadOnly()) { return bean; } // create a readOnly sharable instance by copying the data EntityBean sharableBean = desc.createEntityBean(); BeanProperty idProp = desc.getIdProperty(); if (idProp != null) { Object v = idProp.getValue(bean); idProp.setValue(sharableBean, v); } BeanProperty[] propertiesNonTransient = desc.propertiesNonTransient(); for (BeanProperty aPropertiesNonTransient : propertiesNonTransient) { Object v = aPropertiesNonTransient.getValue(bean); aPropertiesNonTransient.setValue(sharableBean, v); } EntityBeanIntercept intercept = sharableBean._ebean_getIntercept(); intercept.setReadOnly(true); intercept.setLoaded(); return sharableBean; }
public void merge(EntityBean bean, EntityBean existing) { EntityBeanIntercept fromEbi = bean._ebean_getIntercept(); EntityBeanIntercept toEbi = existing._ebean_getIntercept(); int propertyLength = toEbi.getPropertyLength(); String[] names = getProperties(); for (int i = 0; i < propertyLength; i++) { if (fromEbi.isLoadedProperty(i)) { BeanProperty property = getBeanProperty(names[i]); if (!toEbi.isLoadedProperty(i)) { Object val = property.getValue(bean); property.setValue(existing, val); } else if (property.isMany()) { property.merge(bean, existing); } } } }