@Override public KeyValue createMappedForm(@SuppressWarnings("rawtypes") PersistentProperty mpp) { return new KeyValue(mpp.getName()); }
protected boolean isIdentityProperty(Mapping gormMapping, PersistentProperty currentGrailsProp) { if (gormMapping == null) { return false; } Object identityMapping = gormMapping.getIdentity(); if (!(identityMapping instanceof Identity)) { return false; } String identityName = ((Identity)identityMapping).getName(); return identityName != null && identityName.equals(currentGrailsProp.getName()); }
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; }
public List doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(type); hibernateTemplate.applySettings(criteria); return criteria.add( Restrictions.in(persistentEntity.getIdentity().getName(), getIterableAsCollection(keys))) .list(); } });
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; }
@Override public KeyValue createMappedForm(PersistentProperty mpp) { KeyValue kv = super.createMappedForm(mpp); if (kv.getKey() == null) { kv.setKey(mpp.getName()); } return kv; }
protected void setVersion(final EntityAccess ea) { final String versionName = ea.getPersistentEntity().getVersion().getName(); if (Number.class.isAssignableFrom(ea.getPropertyType(versionName))) { ea.setProperty(versionName, 0); } else { setDateVersion(ea); } }
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; } });
public static void incrementEntityVersion(EntityAccess ea) { final String versionName = ea.getPersistentEntity().getVersion().getName(); if (Number.class.isAssignableFrom(ea.getPropertyType(versionName))) { Number currentVersion = (Number) ea.getProperty(versionName); if (currentVersion == null) { currentVersion = 0L; } ea.setProperty(versionName, currentVersion.longValue() + 1); } else { setDateVersionInternal(versionName, ea); } }
@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; }
protected void configureDerivedProperties(PersistentEntity domainClass, Mapping m) { for (PersistentProperty prop : domainClass.getPersistentProperties()) { PropertyConfig propertyConfig = m.getPropertyConfig(prop.getName()); if (propertyConfig != null && propertyConfig.getFormula() != null) { propertyConfig.setDerived(true); } } }
@Override public Object getIdentifier() { String idName = getIdentifierName(persistentEntity.getMapping()); if (idName != null) { return getProperty(idName); } PersistentProperty identity = persistentEntity.getIdentity(); if(identity != null) { return getProperty(identity.getName()); } return null; }
private void handleCustom(PersistentProperty prop, EntityAccess ea, T nativeEntry) { CustomTypeMarshaller customTypeMarshaller = ((Custom) prop).getCustomTypeMarshaller(); if (!customTypeMarshaller.supports(getMappingContext())) { return; } Object value = customTypeMarshaller.read(prop, nativeEntry); ea.setProperty(prop.getName(), value); }
/** * Checks for any custom cascading saves set up via the mapping DSL and records them within the persistent property. * @param mapping The Mapping. * @param persistentProperties The persistent properties of the domain class. */ protected void trackCustomCascadingSaves(Mapping mapping, Iterable<PersistentProperty> persistentProperties) { for (PersistentProperty property : persistentProperties) { PropertyConfig propConf = mapping.getPropertyConfig(property.getName()); if (propConf != null && propConf.getCascade() != null) { propConf.setExplicitSaveUpdateCascade(isSaveUpdateCascade(propConf.getCascade())); } } }
/** * @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."); }
protected Property createProperty(Value value, PersistentClass persistentClass, PersistentProperty grailsProperty, Mappings mappings) { // set type value.setTypeUsingReflection(persistentClass.getClassName(), grailsProperty.getName()); if (value.getTable() != null) { value.createForeignKey(); } Property prop = new Property(); prop.setValue(value); bindProperty(grailsProperty, prop, mappings); return prop; }
protected String getMapElementName(PersistentProperty property, String sessionFactoryBeanName) { PropertyConfig pc = getPropertyConfig(property); if (hasJoinTableColumnNameMapping(pc)) { return pc.getJoinTable().getColumn().getName(); } NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); return namingStrategy.propertyToColumnName(property.getName()) + UNDERSCORE + IndexedCollection.DEFAULT_ELEMENT_COLUMN_NAME; }
protected String getIndexColumnName(PersistentProperty property, String sessionFactoryBeanName) { PropertyConfig pc = getPropertyConfig(property); if (pc != null && pc.getIndexColumn() != null && pc.getIndexColumn().getColumn() != null) { return pc.getIndexColumn().getColumn(); } NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); return namingStrategy.propertyToColumnName(property.getName()) + UNDERSCORE + IndexedCollection.DEFAULT_INDEX_COLUMN_NAME; }