/** * Get a property value from a bean of this type. */ public Object getValue(EntityBean bean, String property) { return getBeanProperty(property).getValue(bean); }
/** * Return the property names as property index positions. */ protected int[] getPropertyPositions(Set<String> properties) { List<Integer> posList = new ArrayList<>(); for (String property : properties) { BeanProperty prop = desc.getBeanProperty(property); if (prop != null) { posList.add(prop.getPropertyIndex()); } } int[] pos = new int[posList.size()]; for (int i = 0; i < pos.length; i++) { pos[i] = posList.get(i); } return pos; }
/** * When help is attached to a specific many property. */ BeanMapHelp(BeanPropertyAssocMany<T> many) { this.many = many; this.targetDescriptor = many.getTargetDescriptor(); this.propertyName = many.getName(); this.beanProperty = targetDescriptor.getBeanProperty(many.getMapKey()); }
/** * Append check constraint values for the entire inheritance hierarchy. */ public void appendCheckConstraintValues(final String propertyName, final Set<String> checkConstraintValues) { visitChildren(inheritInfo -> { BeanProperty prop = inheritInfo.desc().getBeanProperty(propertyName); if (prop != null) { Set<String> values = prop.getDbCheckConstraintValues(); if (values != null) { checkConstraintValues.addAll(values); } } }); }
@Override public void inheritanceLoad(SqlBeanLoad sqlBeanLoad, STreeProperty property, DbReadContext ctx) { BeanProperty p = getBeanProperty(property.getName()); if (p != null) { p.load(sqlBeanLoad); } else { property.loadIgnore(ctx); } }
@Override @SuppressWarnings("unchecked") public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) { if (mapKey == null) { mapKey = many.getMapKey(); } BeanProperty beanProp = targetDescriptor.getBeanProperty(mapKey); if (bc instanceof BeanMap<?, ?>) { BeanMap<Object, Object> bm = (BeanMap<Object, Object>) bc; Map<Object, Object> actualMap = bm.getActualMap(); if (actualMap == null) { actualMap = new LinkedHashMap<>(); bm.setActualMap(actualMap); } return new Adder(beanProp, actualMap); } else { throw new RuntimeException("Unhandled type " + bc); } }
/** * 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); } } } }
if (JsonToken.FIELD_NAME == event) { String key = parser.getCurrentName(); BeanProperty p = desc.getBeanProperty(key); if (p != null) { p.jsonRead(readJson, bean);
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) { BeanProperty prop = targetDesc.getBeanProperty(path); if (prop == null || !(prop instanceof BeanPropertyAssoc)) { throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName()); } if (prop instanceof BeanPropertyAssocMany<?>) { BeanPropertyAssocMany<?> assocMany = (BeanPropertyAssocMany<?>) prop; if (assocMany.isManyToMany()) { return new MergeNodeAssocManyToMany(fullPath, assocMany); } else { return new MergeNodeAssocOneToMany(fullPath, assocMany); } } else { return new MergeNodeAssocOne(fullPath, (BeanPropertyAssocOne<?>) prop); } } }
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); } } } }
/** * Get a property value from a bean of this type. */ public Object getValue(EntityBean bean, String property) { return getBeanProperty(property).getValue(bean); }
/** * Return the property names as property index positions. */ protected int[] getPropertyPositions(Set<String> properties) { List<Integer> posList = new ArrayList<>(); for (String property : properties) { BeanProperty prop = desc.getBeanProperty(property); if (prop != null) { posList.add(prop.getPropertyIndex()); } } int[] pos = new int[posList.size()]; for (int i = 0; i < pos.length; i++) { pos[i] = posList.get(i); } return pos; }
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>) parentDesc.getBeanProperty(propertyName);
/** * Append check constraint values for the entire inheritance hierarchy. */ public void appendCheckConstraintValues(final String propertyName, final Set<String> checkConstraintValues) { visitChildren(inheritInfo -> { BeanProperty prop = inheritInfo.desc().getBeanProperty(propertyName); if (prop != null) { Set<String> values = prop.getDbCheckConstraintValues(); if (values != null) { checkConstraintValues.addAll(values); } } }); }
@Override public void inheritanceLoad(SqlBeanLoad sqlBeanLoad, STreeProperty property, DbReadContext ctx) { BeanProperty p = getBeanProperty(property.getName()); if (p != null) { p.load(sqlBeanLoad); } else { property.loadIgnore(ctx); } }
/** * When help is attached to a specific many property. */ BeanMapHelp(BeanPropertyAssocMany<T> many) { this.many = many; this.targetDescriptor = many.getTargetDescriptor(); this.propertyName = many.getName(); this.beanProperty = targetDescriptor.getBeanProperty(many.getMapKey()); }
@Override @SuppressWarnings("unchecked") public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) { if (mapKey == null) { mapKey = many.getMapKey(); } BeanProperty beanProp = targetDescriptor.getBeanProperty(mapKey); if (bc instanceof BeanMap<?, ?>) { BeanMap<Object, Object> bm = (BeanMap<Object, Object>) bc; Map<Object, Object> actualMap = bm.getActualMap(); if (actualMap == null) { actualMap = new LinkedHashMap<>(); bm.setActualMap(actualMap); } return new Adder(beanProp, actualMap); } else { throw new RuntimeException("Unhandled type " + bc); } }
/** * 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); } } } }
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) { BeanProperty prop = targetDesc.getBeanProperty(path); if (prop == null || !(prop instanceof BeanPropertyAssoc)) { throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName()); } if (prop instanceof BeanPropertyAssocMany<?>) { BeanPropertyAssocMany<?> assocMany = (BeanPropertyAssocMany<?>) prop; if (assocMany.isManyToMany()) { return new MergeNodeAssocManyToMany(fullPath, assocMany); } else { return new MergeNodeAssocOneToMany(fullPath, assocMany); } } else { return new MergeNodeAssocOne(fullPath, (BeanPropertyAssocOne<?>) prop); } } }
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); } } } }