private boolean isLazyAssociation(PropertyMapping<Property> associationPropertyMapping) { if (associationPropertyMapping == null) { return true; } Property kv = associationPropertyMapping.getMappedForm(); return kv.getFetchStrategy() == FetchType.LAZY; }
public PropertyConfig getPropertyConfig(PersistentProperty property) { return (PropertyConfig) property.getMapping().getMappedForm(); }
@Override protected String getNativePropertyKey(PersistentProperty prop) { PropertyMapping<KeyValue> pm = prop.getMapping(); String propKey = null; if (pm.getMappedForm()!=null) { propKey = pm.getMappedForm().getKey(); } if (propKey == null) { propKey = prop.getName(); } return propKey; }
protected String getNativePropertyKey(PersistentProperty prop) { PropertyMapping<Property> pm = prop.getMapping(); String propKey = null; if (pm.getMappedForm()!=null) { propKey = pm.getMappedForm().getTargetName(); } if (propKey == null) { propKey = prop.getName(); } return propKey; }
public static String getTargetKey(PersistentProperty property) { PropertyMapping<Property> mapping = property.getMapping(); String targetName; if (mapping != null && mapping.getMappedForm() != null) { String tmp = mapping.getMappedForm().getTargetName(); targetName = tmp != null ? tmp : property.getName(); } else { targetName = property.getName(); } return targetName; }
/** * @return The fetch strategy for the association */ public FetchType getFetchStrategy() { return getMapping().getMappedForm().getFetchStrategy(); }
protected boolean isIndexed(PersistentProperty property) { PropertyMapping<Property> pm = property.getMapping(); final Property keyValue = pm.getMappedForm(); return keyValue != null && keyValue.isIndex(); }
public boolean isNullable() { final T mappedForm = getMapping().getMappedForm(); return mappedForm != null && mappedForm.isNullable(); }
protected boolean isAssignedId(PersistentEntity persistentEntity) { boolean assignedId = false; PersistentProperty identity = persistentEntity.getIdentity(); if(identity != null) { PropertyMapping mapping = identity.getMapping(); if (mapping != null) { Property p = mapping.getMappedForm(); assignedId = p != null && "assigned".equals(p.getGenerator()); } } return assignedId; }
protected boolean isConstrainableProperty(PersistentProperty persistentProperty, String propertyName) { if(persistentProperty == null) { return NameUtils.isNotConfigurational(propertyName); } else { return !propertyName.equals(GormProperties.VERSION) && !propertyName.equals(GormProperties.DATE_CREATED) && !propertyName.equals(GormProperties.LAST_UPDATED) && !(persistentProperty instanceof Identity) && !(persistentProperty.getMapping().getMappedForm().isDerived()) && !( (persistentProperty instanceof ToOne) && ((ToOne)persistentProperty).isBidirectional() && ((ToOne) persistentProperty).isCircular()); } }
/** * @return Whether this association is lazy */ public boolean isLazy() { return getFetchStrategy() == FetchType.EAGER && getMapping().getMappedForm().isLazy(); }
public Property getMappedForm() { return classMapping.getEntity().getIdentity().getMapping().getMappedForm(); } };
protected String getPropertyKey(PersistentProperty prop) { PropertyMapping<Property> pm = prop.getMapping(); Property mappedProperty = pm.getMappedForm(); String key = null; if (mappedProperty != null) { key = mappedProperty.getTargetName(); } if (key == null) key = prop.getName(); return key; }
/** * Obtain the fetch strategy for the given property * * @param property The fetch strategy * @return A specific strategy or lazy by default */ protected FetchType fetchStrategy(String property) { final FetchType fetchType = fetchStrategies.get(property); if(fetchType != null) { return fetchType; } else { final PersistentProperty prop = entity.getPropertyByName(property); if(prop != null) { return prop.getMapping().getMappedForm().getFetchStrategy(); } } return FetchType.LAZY; }
public Property getMappedForm() { return classMapping.getEntity().getIdentity().getMapping().getMappedForm(); } };
public String[] getIdentifierName() { PersistentProperty identity = classMapping.getEntity().getIdentity(); String propertyName = identity != null ? identity.getMapping().getMappedForm().getName() : null; if(propertyName != null) { return new String[] { propertyName }; } else { return new String[] { IDENTITY_PROPERTY }; } }
/** * Interrogates the specified constraints looking for any constraints that would limit the * length of the property's value. If such constraints exist, this method adjusts the length * of the column accordingly. * @param column the column that corresponds to the property * @param constrainedProperty the property's constraints */ protected void bindStringColumnConstraints(Column column, PersistentProperty constrainedProperty) { final org.grails.datastore.mapping.config.Property mappedForm = constrainedProperty.getMapping().getMappedForm(); Number columnLength = mappedForm.getMaxSize(); List<?> inListValues = mappedForm.getInList(); if (columnLength != null) { column.setLength(columnLength.intValue()); } else if (inListValues != null) { column.setLength(getMaxSize(inListValues)); } }
protected AbstractPersistentCollection(final Association association, Serializable associationKey, final Session session, Collection collection) { this.collection = collection; this.session = session; this.associationKey = associationKey; this.proxyEntities = association.getMapping().getMappedForm().isLazy(); this.childType = association.getAssociatedEntity().getJavaClass(); this.indexer = new AssociationQueryExecutor() { @Override public boolean doesReturnKeys() { return true; } @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(); } @Override public PersistentEntity getIndexedEntity() { return association.getAssociatedEntity(); } }; }
protected void bindColumnConfigToColumn(PersistentProperty property, Column column, ColumnConfig columnConfig) { final PropertyConfig mappedForm = property != null ? (PropertyConfig) property.getMapping().getMappedForm() : null; boolean allowUnique = mappedForm != null && !mappedForm.isUniqueWithinGroup(); if (columnConfig == null) { return; } if (columnConfig.getLength() != -1) { column.setLength(columnConfig.getLength()); } if (columnConfig.getPrecision() != -1) { column.setPrecision(columnConfig.getPrecision()); } if (columnConfig.getScale() != -1) { column.setScale(columnConfig.getScale()); } if (columnConfig.getSqlType() != null && !columnConfig.getSqlType().isEmpty()) { column.setSqlType(columnConfig.getSqlType()); } if(allowUnique) { column.setUnique(columnConfig.getUnique()); } }
protected String getDefaultColumnName(PersistentProperty property, String sessionFactoryBeanName) { NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String columnName = namingStrategy.propertyToColumnName(property.getName()); if (property instanceof Association) { Association association = (Association) property; boolean isBasic = property instanceof Basic; if(isBasic && ((PropertyConfig)property.getMapping().getMappedForm()).getType() != null ) { return columnName; } if (isBasic) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (property instanceof ManyToMany) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (!association.isBidirectional() && association instanceof org.grails.datastore.mapping.model.types.OneToMany) { String prefix = namingStrategy.classToTableName(property.getOwner().getName()); return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX; } if (property.isInherited() && isBidirectionalManyToOne(property)) { return namingStrategy.propertyToColumnName(property.getOwner().getName()) + '_'+ columnName + FOREIGN_KEY_SUFFIX; } return columnName + FOREIGN_KEY_SUFFIX; } return columnName; }