protected boolean isCircularAssociation(PersistentProperty grailsProperty) { return grailsProperty.getType().equals(grailsProperty.getOwner().getJavaClass()); }
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 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; }
protected String getForeignKeyForPropertyDomainClass(PersistentProperty property, String sessionFactoryBeanName) { final String propertyName = NameUtils.decapitalize( property.getOwner().getName() ); NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); return namingStrategy.propertyToColumnName(propertyName) + FOREIGN_KEY_SUFFIX; }
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(); }
@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 void setTypeForPropertyConfig(PersistentProperty grailsProp, SimpleValue simpleValue, PropertyConfig config) { final String typeName = getTypeName(grailsProp, getPropertyConfig(grailsProp), getMapping(grailsProp.getOwner())); if (typeName == null) { simpleValue.setTypeName(grailsProp.getType().getName()); } else { simpleValue.setTypeName(typeName); if (config != null) { simpleValue.setTypeParameters(config.getTypeParams()); } } }
/** * 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 String getIndexColumnType(PersistentProperty property, String defaultType) { PropertyConfig pc = getPropertyConfig(property); if (pc != null && pc.getIndexColumn() != null && pc.getIndexColumn().getType() != null) { return getTypeName(property, pc.getIndexColumn(), getMapping(property.getOwner())); } return defaultType; }
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) {
Mappings mappings, Identity mappedId, String sessionFactoryBeanName) { Mapping mapping = getMapping(identifier.getOwner()); boolean useSequence = mapping != null && mapping.isTablePerConcreteClass();
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; }
protected void bindVersion(PersistentProperty version, RootClass entity, Mappings mappings, String sessionFactoryBeanName) { if(version != null) { SimpleValue val = new SimpleValue(mappings, entity.getTable()); bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName); if (val.isTypeSpecified()) { if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType || val.getType() instanceof TimestampType)) { LOG.warn("Invalid version class specified in " + version.getOwner().getName() + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version."); return; } } else { val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp"); } Property prop = new Property(); prop.setValue(val); bindProperty(version, prop, mappings); val.setNullValue("undefined"); entity.setVersion(prop); entity.setOptimisticLockMode(0); // 0 is to use version column entity.addProperty(prop); } }
throw new MappingException("hasOne property [" + currentGrailsProp.getOwner().getName() + "." + currentGrailsProp.getName() + "] is not bidirectional. Specify the other side of the relationship!");
final PersistentEntity owner = property.getOwner(); if (!owner.isRoot()) { Mapping mapping = getMapping(owner);
protected void setCascadeBehaviour(PersistentProperty grailsProperty, Property prop) { String cascadeStrategy = "none"; PersistentEntity domainClass = grailsProperty.getOwner(); PropertyConfig config = getPropertyConfig(grailsProperty); if (config != null && config.getCascade() != null) {
LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getOwner().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); ManyToOne element = new ManyToOne(mappings, collection.getCollectionTable()); bindManyToMany((Association)otherSide, element, mappings, sessionFactoryBeanName);
if (cc == null) { PersistentEntity domainClass = grailsProp.getOwner(); Mapping m = getMapping(domainClass); if (m != null) {