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); } }
@SuppressWarnings({"unchecked", "rawtypes"}) private BeanProperty createProperty(BeanDescriptorMap owner, DeployBeanProperty prop) { if (prop instanceof DeployBeanPropertyAssocOne<?>) { return new BeanPropertyAssocOne(owner, (DeployBeanPropertyAssocOne<?>) prop); } else { return new BeanProperty(prop); } }
@Override public void appendSelect(DbSqlContext ctx, boolean subQuery) { for (BeanProperty prop : props) { prop.appendSelect(ctx, subQuery); } }
@Override public void pathSet(Object bean, Object value) { if (bean != null) { Object logicalVal = convertToLogicalType(value); setValueIntercept((EntityBean) bean, logicalVal); } }
private void onUpdateGeneratedProperties() { for (BeanProperty prop : beanDescriptor.propertiesGenUpdate()) { GeneratedProperty generatedProperty = prop.getGeneratedProperty(); if (prop.isVersion()) { if (isLoadedProperty(prop)) { // @Version property must be loaded to be involved Object value = generatedProperty.getUpdateValue(prop, entityBean, now()); Object oldVal = prop.getValue(entityBean); setVersionValue(value); intercept.setOldValue(prop.getPropertyIndex(), oldVal); } } else { // @WhenModified set without invoking interception Object oldVal = prop.getValue(entityBean); Object value = generatedProperty.getUpdateValue(prop, entityBean, now()); prop.setValueChanged(entityBean, value); intercept.setOldValue(prop.getPropertyIndex(), oldVal); } } }
/** * Set the tenantId onto the bean. */ public void setTenantValue(EntityBean entityBean, Object tenantId) { setValue(entityBean, tenantId); }
/** * Return true if this property is loaded (full bean or included in partial bean). */ public boolean isLoadedProperty(BeanProperty prop) { return intercept.isLoadedProperty(prop.getPropertyIndex()); }
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); } } } }
private static void loadProperty(EntityBean bean, CachedBeanData cacheBeanData, EntityBeanIntercept ebi, BeanProperty prop, PersistenceContext context) { if (cacheBeanData.isLoaded(prop.getName())) { if (!ebi.isLoadedProperty(prop.getPropertyIndex())) { Object value = cacheBeanData.getData(prop.getName()); prop.setCacheDataValue(bean, value, context); } } }
/** * Check for mutable scalar types and mark as dirty if necessary. */ public void checkMutableProperties(EntityBeanIntercept ebi) { for (BeanProperty beanProperty : propertiesMutable) { int propertyIndex = beanProperty.getPropertyIndex(); if (!ebi.isDirtyProperty(propertyIndex) && ebi.isLoadedProperty(propertyIndex)) { Object value = beanProperty.getValue(ebi.getOwner()); if (value == null || beanProperty.isDirtyValue(value)) { // mutable scalar value which is considered dirty so mark // it as such so that it is included in an update ebi.markPropertyAsChanged(propertyIndex); } } } }
public static CachedBeanData extract(BeanDescriptor<?> desc, EntityBean bean) { EntityBeanIntercept ebi = bean._ebean_getIntercept(); Map<String, Object> data = new LinkedHashMap<>(); BeanProperty idProperty = desc.getIdProperty(); if (idProperty != null) { int propertyIndex = idProperty.getPropertyIndex(); if (ebi.isLoadedProperty(propertyIndex)) { data.put(idProperty.getName(), idProperty.getCacheDataValue(bean)); } } BeanProperty[] props = desc.propertiesNonMany(); // extract all the non-many properties for (BeanProperty prop : props) { if (ebi.isLoadedProperty(prop.getPropertyIndex())) { data.put(prop.getName(), prop.getCacheDataValue(bean)); } } for (BeanPropertyAssocMany<?> prop : desc.propertiesMany()) { if (prop.isElementCollection()) { data.put(prop.getName(), prop.getCacheDataValue(bean)); } } long version = desc.getVersion(bean); EntityBean sharableBean = createSharableBean(desc, bean, ebi); return new CachedBeanData(sharableBean, desc.getDiscValue(), data, version); }
/** * If there is a @DraftDirty property set it's value on the bean. */ public void setDraftDirty(EntityBean entityBean, boolean value) { if (draftDirty != null) { // check to see if the dirty property has already // been set and if so do not set the value if (!entityBean._ebean_getIntercept().isChangedProperty(draftDirty.getPropertyIndex())) { draftDirty.setValueIntercept(entityBean, value); } } }
void jsonWriteDirtyProperties(SpiJsonWriter writeJson, EntityBean bean, boolean[] dirtyProps) throws IOException { writeJson.writeStartObject(null); // render the dirty properties BeanProperty[] props = desc.propertiesNonTransient(); for (BeanProperty prop : props) { if (dirtyProps[prop.getPropertyIndex()]) { prop.jsonWrite(writeJson, bean); } } writeJson.writeEndObject(); }
private boolean isIncludeProperty(BeanProperty prop) { if (explicitAllProps) return true; if (currentIncludeProps != null) { // explicitly controlled by pathProperties return currentIncludeProps.contains(prop.getName()); } else { // include only loaded properties return currentBean._ebean_getIntercept().isLoadedProperty(prop.getPropertyIndex()); } }
/** * 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); } } }
String propertyName = sourceProperties[i].getName(); String dbColumn = propColMap.get(propertyName); if (dbColumn == null) { dbColumn = sourceProperties[i].getDbColumn(); if (columnPrefix != null) { dbColumn = columnPrefix + dbColumn; embeddedProperties[i] = new BeanPropertyAssocOne((BeanPropertyAssocOne)sourceProperties[i], overrides); } else { embeddedProperties[i] = new BeanProperty(sourceProperties[i], overrides);
discProperty = new BeanProperty(desc, discDeployProp); propertyMap.put(beanProp.getName(), beanProp); prop.setDeployOrder(order++); allocateToList(prop); orderColumn.setDeployOrder(order++); allocateToList(orderColumn); propertyMap.put(orderColumn.getName(), orderColumn); propertyMap.put(discProperty.getName(), discProperty);