/** * Return the Id property name or null if no Id property exists. */ public String getIdName() { return (idProperty == null) ? null : idProperty.getName(); }
@Override public String getDefaultOrderBy() { return idProperty.getName(); }
@Override public String getAssocIdInExpr(String prefix) { StringBuilder sb = new StringBuilder(); if (prefix != null) { sb.append(prefix); sb.append("."); } sb.append(idProperty.getName()); return sb.toString(); }
@Override public String getOrderBy(String pathPrefix, boolean ascending) { StringBuilder sb = new StringBuilder(); if (pathPrefix != null) { sb.append(pathPrefix).append("."); } sb.append(idProperty.getName()); if (!ascending) { sb.append(" desc"); } return sb.toString(); }
/** * Append a logical where for the foreign db column to logical property name, */ public void appendWhere(StringBuilder sb, String alias, String path) { sb.append(alias).append(foreignDbColumn).append(" = "); if (path != null) { sb.append(path).append("."); } sb.append(property.getName()); } }
@Override public String getAssocOneIdExpr(String prefix, String operator) { StringBuilder sb = new StringBuilder(); if (prefix != null) { sb.append(prefix); sb.append("."); } sb.append(idProperty.getName()); sb.append(operator); return sb.toString(); }
private boolean isIncludeTransientProperty(BeanProperty prop) { if (prop.isUnmappedJson()) { return false; } else if (!explicitAllProps && currentIncludeProps != null) { // explicitly controlled by pathProperties return currentIncludeProps.contains(prop.getName()); } else { // by default include transient properties return true; } }
/** * Initialise the property before returning to client code. Used to * initialise variables that can't be done in construction due to recursive * issues. */ public void initialise(BeanDescriptorInitContext initContext) { // do nothing for normal BeanProperty if (!isTransient && scalarType == null) { throw new RuntimeException("No ScalarType assigned to " + descriptor.getFullName() + "." + getName()); } }
@Override public String getDefaultOrderBy() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < props.length; i++) { if (i > 0) { sb.append(","); } sb.append(embIdProperty.getName()); sb.append("."); sb.append(props[i].getName()); } return sb.toString(); }
/** * Convert from embedded bean to Map. */ @Override public Object getIdForJson(EntityBean bean) { EntityBean ebValue = (EntityBean) embIdProperty.getValue(bean); Map<String, Object> map = new LinkedHashMap<>(); for (BeanProperty prop : props) { map.put(prop.getName(), prop.getValue(ebValue)); } return map; }
/** * 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; }
/** * Add to the query to fetch the Ids values for the foreign keys basically. */ void addSelectId(Query<?> query) { BeanProperty idProperty = targetDescriptor.getIdProperty(); query.fetch(fullPath, idProperty.getName()); }
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()); } }
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); } } }
/** * Appends the Id property to the OrderBy clause if it is not believed * to be already contained in the order by. * <p> * This is primarily used for paging queries to ensure that an order by clause is provided and that the order by * provides unique ordering of the rows (so that the paging is predicable). * </p> */ public void appendOrderById(SpiQuery<T> query) { if (idProperty != null && !idProperty.isEmbedded() && !query.order().containsProperty(idProperty.getName())) { query.order().asc(idProperty.getName()); } }
/** * Add a PathProperties for an embedded 'many' property (at the root level). */ private void prepare(String prop, BeanPropertyAssoc<?> embProp) { BeanDescriptor<?> targetDesc = embProp.getTargetDescriptor(); PathProperties manyRootPath = new PathProperties(); manyRootPath.addToPath(null, targetDesc.getIdProperty().getName()); manyRootPath.addNested(prop, embedded.get(prop)); manyRoot.put(prop, manyRootPath); } }
/** * 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(); } } }
@Override public void addFkeys(String name) { BeanFkeyProperty fkey = new BeanFkeyProperty(name + "." + foreignProperty.getName(), localDbColumn, owner.getDeployOrder()); owner.getBeanDescriptor().add(fkey); }
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, String localSqlFormula, BeanProperty foreignProperty, int position, boolean insertable, boolean updateable) { this.owner = owner; this.localDbColumn = InternString.intern(localDbColumn); this.localSqlFormula = InternString.intern(localSqlFormula); this.foreignProperty = foreignProperty; this.position = position; this.insertable = insertable; this.updateable = updateable; this.logicalName = InternString.intern(owner.getName() + "." + foreignProperty.getName()); }
@Override public void addFkeys(String name) { BeanProperty[] embeddedProps = foreignAssocOne.getProperties(); for (int i = 0; i < imported.length; i++) { String n = name + "." + foreignAssocOne.getName() + "." + embeddedProps[i].getName(); BeanFkeyProperty fkey = new BeanFkeyProperty(n, imported[i].localDbColumn, foreignAssocOne.getDeployOrder()); owner.getBeanDescriptor().add(fkey); } }