private String getAssociationPath(String propertyName) { StringBuilder fullPath = new StringBuilder(); for (Iterator<Association> iterator = associationStack.iterator(); iterator.hasNext(); ) { Association association = iterator.next(); fullPath.append(association.getName()); fullPath.append('.'); } fullPath.append(propertyName); return fullPath.toString(); }
protected String getAssociationPath(String propertyName) { if(propertyName.indexOf('.') > -1) { return propertyName; } else { StringBuilder fullPath = new StringBuilder(); for (Association association : associationStack) { fullPath.append(association.getName()); fullPath.append('.'); } fullPath.append(propertyName); return fullPath.toString(); } }
/** * Designed for use when a projection query is used. The fetch arguments * need prepended with the projection property name. * * @param entity The {@link PersistentEntity} being queried * @param projectionName The name of the property being projected */ public EntityFetchOptions(PersistentEntity entity, String projectionName) { if (entity == null) { throw new IllegalArgumentException("Cannot retrieve fetch options for a null entity. Is GORM initialized?"); } this.entity = entity; this.propertyName = projectionName; for (Association association : entity.getAssociations()) { associations.put(association.getName(), association); } associationNames = associations.keySet(); }
private static int handleAssociationCriteria(StringBuilder query, StringBuilder whereClause, String logicalName, int position, List parameters, ConversionService conversionService, boolean allowJoins, Association<?> association, Query.Junction associationCriteria, List<Query.Criterion> associationCriteriaList, boolean hibernateCompatible) { if (association instanceof ToOne) { final String associationName = association.getName(); logicalName = logicalName + DOT + associationName; return buildWhereClauseForCriterion(association.getAssociatedEntity(), associationCriteria, query, whereClause, logicalName, associationCriteriaList, position, parameters, conversionService, allowJoins, hibernateCompatible); } if (association != null) { final String associationName = association.getName(); // TODO: Allow customization of join strategy! String joinType = " INNER JOIN "; query.append(joinType) .append(logicalName) .append(DOT) .append(associationName) .append(SPACE) .append(associationName); return buildWhereClauseForCriterion(association.getAssociatedEntity(), associationCriteria, query, whereClause, associationName, associationCriteriaList, position, parameters, conversionService, allowJoins, hibernateCompatible); } return position; }
protected void cascadeDeleteCollection(EntityAccess entityAccess, Association association) { Object propValue = entityAccess.getProperty(association.getName()); if (!(propValue instanceof Collection)) { return; } Collection collection = ((Collection) propValue); for (Iterator iter = collection.iterator(); iter.hasNext(); ) { Object child = iter.next(); deleteEntity(getMappingContext().getPersistentEntity(child.getClass().getName()), child); iter.remove(); } }
@Override public String toString() { return getOwner().getName() + "->" + getName(); }
String handleAssociationQuery(Association<?> association, List<Criterion> criteriaList, String alias) { String associationName = calculatePropertyName(association.getName()); return getOrCreateAlias(associationName, alias).alias; }
protected void logCascadeMapping(Association grailsProperty, String cascadeStrategy, PersistentEntity referenced) { if (LOG.isDebugEnabled() & referenced != null) { String assType = getAssociationDescription(grailsProperty); LOG.debug("Mapping cascade strategy for " + assType + " property " + grailsProperty.getOwner().getName() + "." + grailsProperty.getName() + " referencing type [" + referenced.getJavaClass().getName() + "] -> [CASCADE: " + cascadeStrategy + "]"); } }
private CriteriaAndAlias getCriteriaAndAlias(Association<?> association) { String associationName = calculatePropertyName(association.getName()); String newAlias = generateAlias(associationName); return getOrCreateAlias(associationName, newAlias); }
protected CriteriaAndAlias getCriteriaAndAlias(Association<?> association) { String associationName = calculatePropertyName(association.getName()); String newAlias = generateAlias(associationName); return getOrCreateAlias(associationName, newAlias); }
protected CriteriaAndAlias getCriteriaAndAlias(DetachedAssociationCriteria associationCriteria) { String associationPath = associationCriteria.getAssociationPath(); String alias = associationCriteria.getAlias(); if(associationPath == null) { associationPath = associationCriteria.getAssociation().getName(); } return getOrCreateAlias(associationPath, alias); }
protected void handleEmbeddedToOne(Association association, String key, EntityAccess entityAccess, T nativeEntry) { Object embeddedInstance = entityAccess.getProperty(association.getName()); if (embeddedInstance == null) { setEmbedded(nativeEntry, key, null); return; } T embeddedEntry = handleEmbeddedInstance(association, embeddedInstance); setEmbedded(nativeEntry, key, embeddedEntry); }
public static String associationtoString(String desc, Association a) { return desc + a.getOwner().getName() + "-> " + a.getName() + " ->" + a.getAssociatedEntity().getName(); }
/** * @return The inverse side or null if the association is not bidirectional */ public Association getInverseSide() { final PersistentProperty associatedProperty = associatedEntity.getPropertyByName(referencedPropertyName); if (associatedProperty == null) return null; if (associatedProperty instanceof Association) { return (Association) associatedProperty; } throw new IllegalMappingException("The inverse side [" + associatedEntity.getName() + "." + associatedProperty.getName() + "] of the association [" + getOwner().getName() + "." + getName() + "] is not valid. Associations can only map to other entities and collection types."); }
@Override public List query(Object primaryKey) { Association inverseSide = association.getInverseSide(); Query query = session.createQuery(association.getAssociatedEntity().getJavaClass()); query.eq(inverseSide.getName(), primaryKey); query.projections().id(); return query.list(); }
String associationName = association.getName(); if (getCurrentAlias() != null) { associationName = getCurrentAlias() + '.' + associationName;
AssociationQuery associationQuery = createQuery(ac.getAssociation().getName()); for (Criterion associationCriterion : ac.getCriteria()) { associationQuery.add(associationCriterion);
protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne, String path, String sessionFactoryBeanName) { PropertyConfig config = getPropertyConfig(property); final Association otherSide = property.getInverseSide(); final boolean hasOne = isHasOne(otherSide); oneToOne.setConstrained(hasOne); oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT); oneToOne.setAlternateUniqueKey(true); if (config != null && config.getFetchMode() != null) { oneToOne.setFetchMode(config.getFetchMode()); } else { oneToOne.setFetchMode(FetchMode.DEFAULT); } oneToOne.setReferencedEntityName(otherSide.getOwner().getName()); oneToOne.setPropertyName(property.getName()); bindOneToOneInternal(property, oneToOne, path); if (hasOne) { PropertyConfig pc = getPropertyConfig(property); bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName); } else { oneToOne.setReferencedPropertyName(otherSide.getName()); } }