public int handle(PersistentEntity entity, Query.Criterion criterion, StringBuilder q, StringBuilder whereClause, String logicalName, int position, List parameters, ConversionService conversionService, boolean allowJoins, boolean hibernateCompatible) { Query.IdEquals eq = (Query.IdEquals) criterion; PersistentProperty prop = entity.getIdentity(); Class propType = prop.getType(); position = appendCriteriaForOperator(whereClause, logicalName, prop.getName(), position, "=", hibernateCompatible); parameters.add(conversionService.convert( eq.getValue(), propType )); return position; } });
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; }
/** * Establish whether a collection property is sorted * * @param property The property * @return true if sorted */ protected boolean isSorted(PersistentProperty property) { return SortedSet.class.isAssignableFrom(property.getType()); }
persistentPropertyNames.add(persistentProperty.getName()); embedded.add((Embedded)persistentProperty); propertiesByName.put(persistentProperty.getName(), persistentProperty); final String targetName = persistentProperty.getMapping().getMappedForm().getTargetName(); if(targetName != null) { mappedPropertiesByName.put(targetName, persistentProperty); final Class type = v.getType(); this.versionCompatibleType = Number.class.isAssignableFrom(type) || Date.class.isAssignableFrom(type); String idName = identity.getName(); PersistentProperty idProp = propertiesByName.get(idName); if(idProp == null) { persistentPropertyNames.remove(idProp.getName()); if(!idProp.getName().equals(GormProperties.IDENTITY)) { disableDefaultId();
column.setNullable(property.isNullable()); column.setNullable(property.isNullable() || (parentProperty != null && parentProperty.isNullable())); if (String.class.isAssignableFrom(property.getType()) || byte[].class.isAssignableFrom(property.getType())) { bindStringColumnConstraints(column, property); if (Number.class.isAssignableFrom(property.getType())) { bindNumericColumnConstraints(column, property, cc); final PersistentEntity owner = property.getOwner(); if (!owner.isRoot()) { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name ["+column.getName()+"] set to nullable"); column.setNullable(true); } else { column.setNullable(property.isNullable()); LOG.debug("[GrailsDomainBinder] bound property [" + property.getName() + "] to column name ["+column.getName()+"] in table ["+table.getName()+"]");
@Override public T createMappedForm(PersistentProperty mpp) { Map<String, T> properties = entityToPropertyMap.get(mpp.getOwner()); if (properties != null && properties.containsKey(mpp.getName())) { return properties.get(mpp.getName()); } else if (properties != null) { Property property = properties.get(IDENTITY_PROPERTY); if (property != null && mpp.getName().equals(property.getName())) { return (T) property; } } T defaultMapping = properties != null ? properties.get("*") : null; if (defaultMapping != null) { try { return (T) defaultMapping.clone(); } catch (CloneNotSupportedException e) { return BeanUtils.instantiate(getPropertyMappedFormType()); } } else { return BeanUtils.instantiate(getPropertyMappedFormType()); } } }
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; }
prop.setName(grailsProperty.getName()); if (isBidirectionalManyToOneWithListMapping(grailsProperty, prop)) { prop.setInsertable(false); grailsProperty.getMapping().getMappedForm().getAccessType() ); prop.setPropertyAccessorName( accessType.getType() ); prop.setOptional(grailsProperty.isNullable()); !(grailsProperty instanceof Association) && !grailsProperty.equals(grailsProperty.getOwner().getIdentity()); handleLazyProxy(grailsProperty.getOwner(), grailsProperty);
protected void bindEnumType(PersistentProperty property, Class<?> propertyType, SimpleValue simpleValue, String columnName) { final PersistentEntity owner = property.getOwner(); String typeName = getTypeName(property, getPropertyConfig(property), getMapping(owner)); if (typeName == null) { LOG.warn("Invalid enumType specified when mapping property [" + property.getName() + "] of class [" + owner.getName() + "]. Using defaults instead."); column.setNullable(property.isNullable()); } else { Mapping mapping = getMapping(owner); if (mapping == null || mapping.getTablePerHierarchy()) { if (LOG.isDebugEnabled()) { LOG.debug("[GrailsDomainBinder] Sub class property [" + property.getName() + "] for column name [" + column.getName() + "] set to nullable"); column.setNullable(property.isNullable());
public PropertyConfig getPropertyConfig(PersistentProperty property) { return (PropertyConfig) property.getMapping().getMappedForm(); }
protected void createKeyForProps(PersistentProperty grailsProp, String path, Table table, String columnName, List<?> propertyNames, String sessionFactoryBeanName) { List<Column> keyList = new ArrayList<Column>(); keyList.add(new Column(columnName)); for (Object po : propertyNames) { String propertyName = (String) po; PersistentProperty otherProp = grailsProp.getOwner().getPropertyByName(propertyName); String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName); keyList.add(new Column(otherColumnName)); } createUniqueKeyForColumns(table, columnName, keyList); }
protected boolean isComponentPropertyNullable(PersistentProperty componentProperty) { if (componentProperty == null) return false; final PersistentEntity domainClass = componentProperty.getOwner(); final Mapping mapping = getMapping(domainClass.getJavaClass()); return !domainClass.isRoot() && (mapping == null || mapping.isTablePerHierarchy()) || componentProperty.isNullable(); }
protected void linkValueUsingAColumnCopy(PersistentProperty prop, Column column, DependantValue key) { Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isNullable()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key); key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
@Override public Class getPropertyType(String name) { PersistentProperty property = persistentEntity.getPropertyByName(name); if(property != null) { return property.getType(); } return null; }
Property mappedForm = p.getMapping().getMappedForm(); PersistentProperty version = entity.getVersion(); if (canPropertyBeConstrained(p) && !p.equals(version)) { if (mappedForm.isDerived()) { if (constrainedProperties.remove(p.getName()) != null) { LOG.warn("Derived properties may not be constrained. Property [" + p.getName() + "] of domain class " + theClass.getName() + " will not be checked during validation."); final String propertyName = p.getName(); ConstrainedProperty cp = constrainedProperties.get(propertyName); if (cp == null) { DefaultConstrainedProperty constrainedProperty = new DefaultConstrainedProperty(entity.getJavaClass(), propertyName, p.getType(), constraintRegistry); cp = constrainedProperty; constrainedProperty.setOrder(constrainedProperties.size() + 1);
if (currentGrailsProp.isInherited()) { continue; if(currentGrailsProp.getName().equals(GormProperties.VERSION) ) continue; if (isCompositeIdProperty(gormMapping, currentGrailsProp)) continue; if (isIdentityProperty(gormMapping, currentGrailsProp)) continue; LOG.debug("[GrailsDomainBinder] Binding persistent property [" + currentGrailsProp.getName() + "]"); CollectionType collectionType = CT.collectionTypeForClass(currentGrailsProp.getType()); LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as SimpleValue"); if ("serializable".equals(typeName)) { value = new SimpleValue(mappings, table); bindSimpleValue(typeName, (SimpleValue) value, currentGrailsProp.isNullable(), getColumnNameForPropertyAndPath(currentGrailsProp, EMPTY_PATH, null, sessionFactoryBeanName), mappings); else if (currentGrailsProp.getType().isEnum()) { value = new SimpleValue(mappings, table); bindEnumType(currentGrailsProp, (SimpleValue) value, EMPTY_PATH, sessionFactoryBeanName); if (currentGrailsProp instanceof org.grails.datastore.mapping.model.types.ManyToOne) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as ManyToOne"); LOG.debug("[GrailsDomainBinder] Binding property [" + currentGrailsProp.getName() + "] as OneToOne"); throw new MappingException("hasOne property [" + currentGrailsProp.getOwner().getName() +
/** * Binds the primary key value column * * @param property The property * @param key The key * @param mappings The mappings */ protected void bindDependentKeyValue(PersistentProperty property, DependantValue key, Mappings mappings, String sessionFactoryBeanName) { if (LOG.isDebugEnabled()) { LOG.debug("[GrailsDomainBinder] binding [" + property.getName() + "] with dependant key"); } PersistentEntity refDomainClass = property.getOwner(); final Mapping mapping = getMapping(refDomainClass.getJavaClass()); boolean hasCompositeIdentifier = hasCompositeIdentifier(mapping); if ((shouldCollectionBindWithJoinColumn((ToMany) property) && hasCompositeIdentifier) || (hasCompositeIdentifier && ( property instanceof ManyToMany))) { CompositeIdentity ci = (CompositeIdentity) mapping.getIdentity(); bindCompositeIdentifierToManyToOne((Association) property, key, ci, refDomainClass, EMPTY_PATH, sessionFactoryBeanName); } else { bindSimpleValue(property, null, key, EMPTY_PATH, mappings, sessionFactoryBeanName); } }
protected boolean canApplyNullableConstraint(String propertyName, PersistentProperty property, Constrained constrained) { if (property == null || property.getType() == null) return false; final PersistentEntity domainClass = property.getOwner(); // only apply default nullable to Groovy entities not legacy Java ones if (!GroovyObject.class.isAssignableFrom(domainClass.getJavaClass())) return false; final PersistentProperty versionProperty = domainClass.getVersion(); final boolean isVersion = versionProperty != null && versionProperty.equals(property); return !constrained.hasAppliedConstraint(ConstrainedProperty.NULLABLE_CONSTRAINT) && isConstrainableProperty(property, propertyName) && !isVersion; }