@Override public void initialiseOther(BeanDescriptorInitContext initContext) { super.initialiseOther(initContext); this.targetDescriptor = embeddedProperty.getTargetDescriptor(); }
/** * Create a bean of the target type to be used as an embeddedId * value. */ public Object createEmbeddedId() { return getTargetDescriptor().createEntityBean(); }
/** * Find a depth based on imported relationships (to a parent that is already in the buffer). */ private int relativeToParentDepth(BeanDescriptor<?> beanDescriptor) { BeanPropertyAssocOne<?>[] imported = beanDescriptor.propertiesOneImported(); if (imported.length == 0) { // a top level type so just maintain the order relative to the current depth return maxDepth + 1; } int parentMaxDepth = -1; for (BeanPropertyAssocOne<?> parent : imported) { BatchedBeanHolder parentBatch = beanHoldMap.get(parent.getTargetDescriptor().rootName()); if (parentBatch != null) { // deeper that the parent parentMaxDepth = Math.max(parentMaxDepth, parentBatch.getOrder() + 1); } } return parentMaxDepth; }
@Override public void initialise() { this.idDesc = embIdProperty.getTargetDescriptor(); this.props = embIdProperty.getProperties(); this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed(); }
/** * Create the array of ExportedProperty used to build reference objects. */ private ExportedProperty[] createExported() { BeanProperty idProp = descriptor.getIdProperty(); ArrayList<ExportedProperty> list = new ArrayList<>(); if (idProp != null && idProp.isEmbedded()) { BeanPropertyAssocOne<?> one = (BeanPropertyAssocOne<?>) idProp; try { for (BeanProperty emId : one.getTargetDescriptor().propertiesBaseScalar()) { list.add(findMatch(true, emId)); } } catch (PersistenceException e) { // not found as individual scalar properties logger.error("Could not find a exported property?", e); } } else { if (idProp != null) { list.add(findMatch(false, idProp)); } } return list.toArray(new ExportedProperty[list.size()]); }
/** * Initialise after the target bean descriptors have been all set. */ public void initialisePostTarget() { if (childMasterProperty != null) { BeanProperty masterId = childMasterProperty.getTargetDescriptor().getIdProperty(); if (masterId != null) { // in docstore only, the master-id may be not available childMasterIdProperty = childMasterProperty.getName() + "." + masterId.getName(); } } }
/** * Create the array of ExportedProperty used to build reference objects. */ private ExportedProperty[] createExported() { BeanProperty idProp = descriptor.getIdProperty(); ArrayList<ExportedProperty> list = new ArrayList<>(); if (idProp != null && idProp.isEmbedded()) { BeanPropertyAssocOne<?> one = (BeanPropertyAssocOne<?>) idProp; BeanDescriptor<?> targetDesc = one.getTargetDescriptor(); BeanProperty[] emIds = targetDesc.propertiesBaseScalar(); try { for (BeanProperty emId : emIds) { list.add(findMatch(true, emId)); } } catch (PersistenceException e) { // not found as individual scalar properties e.printStackTrace(); } } else { if (idProp != null) { list.add(findMatch(false, idProp)); } } return list.toArray(new ExportedProperty[list.size()]); }
@Override public void diff(String prefix, Map<String, ValuePair> map, EntityBean newBean, EntityBean oldBean) { Object newEmb = (newBean == null) ? null : getValue(newBean); Object oldEmb = (oldBean == null) ? null : getValue(oldBean); if (newEmb == null && oldEmb == null) { return; } if (embedded) { prefix = (prefix == null) ? name : prefix + "." + name; BeanDescriptor<T> targetDescriptor = getTargetDescriptor(); targetDescriptor.diff(prefix, map, (EntityBean) newEmb, (EntityBean) oldEmb); } else { // we are only interested in the Id value newBean = (EntityBean) newEmb; oldBean = (EntityBean) oldEmb; BeanDescriptor<T> targetDescriptor = getTargetDescriptor(); BeanProperty idProperty = targetDescriptor.getIdProperty(); Object newId = (newBean == null) ? null : idProperty.getValue(newBean); Object oldId = (oldBean == null) ? null : idProperty.getValue(oldBean); if (newId != null || oldId != null) { prefix = (prefix == null) ? name : prefix + "." + name; idProperty.diffVal(prefix, map, newId, oldId); } } }
@Override public void visitPush(int position) { stack.push(descriptor); BeanPropertyAssocOne<?> embedded = (BeanPropertyAssocOne<?>)descriptor.propertiesIndex[position]; descriptor = embedded.getTargetDescriptor(); newJson.writeStartObject(embedded.getName()); if (oldJson != null) { oldJson.writeStartObject(embedded.getName()); } }
/** * Add expressions to the list for all the non-null properties (and do this recursively). */ private void addExpressions(ArrayList<SpiExpression> list, BeanDescriptor<?> beanDescriptor, EntityBean bean, String prefix) { for (BeanProperty beanProperty : beanDescriptor.propertiesAll()) { if (!beanProperty.isTransient()) { Object value = beanProperty.getValue(bean); if (value != null) { String propName = SplitName.add(prefix, beanProperty.getName()); if (beanProperty.isScalar()) { if (value instanceof String) { list.add(new LikeExpression(propName, value, caseInsensitive, likeType)); } else { // exclude the zero values typically to weed out // primitive int and long that initialise to 0 if (includeZeros || !isZero(value)) { list.add(new SimpleExpression(propName, Op.EQ, value)); } } } else if ((beanProperty instanceof BeanPropertyAssocOne) && (value instanceof EntityBean)) { BeanPropertyAssocOne<?> assocOne = (BeanPropertyAssocOne<?>) beanProperty; BeanDescriptor<?> targetDescriptor = assocOne.getTargetDescriptor(); addExpressions(list, targetDescriptor, (EntityBean) value, propName); } } } } }
@Override public void registerColumn(BeanDescriptor<?> desc, String prefix) { if (embedded) { for (BeanProperty prop : embeddedProps) { prop.registerColumn(desc, SplitName.add(prefix, name)); } } else { if (targetIdProperty != null) { BeanDescriptor<T> target = getTargetDescriptor(); String basePath = SplitName.add(prefix, name); if (dbColumn != null) { BeanProperty idProperty = target.getIdProperty(); desc.registerColumn(dbColumn, SplitName.add(basePath, idProperty.getName())); } desc.registerTable(target.getBaseTable(), this); } } }
/** * Fetch draftable element relationships. */ public void draftQueryOptimise(Query<T> query) { BeanPropertyAssocOne<?>[] one = desc.propertiesOne(); for (BeanPropertyAssocOne<?> anOne : one) { if (anOne.getTargetDescriptor().isDraftableElement()) { query.fetch(anOne.getName()); } } BeanPropertyAssocMany<?>[] many = desc.propertiesMany(); for (BeanPropertyAssocMany<?> aMany : many) { if (aMany.getTargetDescriptor().isDraftableElement()) { query.fetch(aMany.getName()); } } } }
BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar(); ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps, others);
@Override public void initialiseOther(BeanDescriptorInitContext initContext) { super.initialiseOther(initContext); this.targetDescriptor = embeddedProperty.getTargetDescriptor(); }
if (columns.length > 1) { String refTable = p.getTargetDescriptor().getBaseTable(); String fkName = determineForeignKeyConstraintName(p.getName()); String fkIndex = determineForeignKeyIndexName(p.getName()); if (refTable == null) { refTable = p.getTargetDescriptor().getBaseTable();
/** * Create a bean of the target type to be used as an embeddedId * value. */ public Object createEmbeddedId() { return getTargetDescriptor().createEntityBean(); }
@Override public void initialise() { this.idDesc = embIdProperty.getTargetDescriptor(); this.props = embIdProperty.getProperties(); this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed(); }
/** * Initialise after the target bean descriptors have been all set. */ public void initialisePostTarget() { if (childMasterProperty != null) { BeanProperty masterId = childMasterProperty.getTargetDescriptor().getIdProperty(); if (masterId != null) { // in docstore only, the master-id may be not available childMasterIdProperty = childMasterProperty.getName() + "." + masterId.getName(); } } }
BeanDescriptor<?> targetDesc = expOne.getTargetDescriptor();
@Override public void visitPush(int position) { stack.push(descriptor); BeanPropertyAssocOne<?> embedded = (BeanPropertyAssocOne<?>)descriptor.propertiesIndex[position]; descriptor = embedded.getTargetDescriptor(); newJson.writeStartObject(embedded.getName()); if (oldJson != null) { oldJson.writeStartObject(embedded.getName()); } }