protected String getIdentifierName(ClassMapping cm) { final IdentityMapping identifier = cm.getIdentifier(); if (identifier != null && identifier.getIdentifierName() != null) { String[] identifierName = identifier.getIdentifierName(); if(identifierName.length > 0) { return identifierName[0]; } } return null; }
/** * Obtains the identifier name to use. Subclasses can override to provide their own strategy for looking up an identifier name * @param cm The ClassMapping instance * @return The identifier name */ protected String getIdentifierName(ClassMapping cm) { return cm.getIdentifier().getIdentifierName()[0]; }
protected boolean isExcludedProperty(String propertyName, ClassMapping classMapping, Collection transients, boolean includeIdentifiers) { IdentityMapping id = classMapping != null ? classMapping.getIdentifier() : null; String[] identifierName = id != null && !includeIdentifiers ? id.getIdentifierName() : null; return isExcludeId(propertyName, id, identifierName,includeIdentifiers) || EXCLUDED_PROPERTIES.contains(propertyName) || transients.contains(propertyName); }
/** * @see org.grails.datastore.mapping.model.MappingConfigurationStrategy#getIdentity(Class, org.grails.datastore.mapping.model.MappingContext) */ public PersistentProperty getIdentity(Class javaClass, MappingContext context) { ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); PersistentEntity entity = context.getPersistentEntity(javaClass.getName()); ClassMapping mapping = entity.getMapping(); IdentityMapping id = mapping.getIdentifier(); final String[] names = id.getIdentifierName(); if (names.length == 1) { final PropertyDescriptor pd = cpf.getPropertyDescriptor(names[0]); if (pd != null) { return propertyFactory.createIdentity(entity, context, pd); } if (!entity.isExternal() && isAbstract(entity)) { throw new IllegalMappingException("Mapped identifier [" + names[0] + "] for class [" + javaClass.getName() + "] is not a valid property"); } return null; } return null; }
@Override public PersistentProperty[] getCompositeIdentity(Class javaClass, MappingContext context) { ClassPropertyFetcher cpf = ClassPropertyFetcher.forClass(javaClass); PersistentEntity entity = context.getPersistentEntity(javaClass.getName()); ClassMapping mapping = entity.getMapping(); IdentityMapping id = mapping.getIdentifier(); final String[] names = id.getIdentifierName(); PersistentProperty[] identifiers = new PersistentProperty[names.length]; for (int i = 0; i < names.length; i++) { String name = names[i]; final PersistentProperty p = entity.getPropertyByName(name); if(p != null) { identifiers[i] = p; } else { final PropertyDescriptor pd = cpf.getPropertyDescriptor(name); if (pd != null) { identifiers[i] = propertyFactory.createIdentity(entity, context, pd); } else { throw new IllegalMappingException("Invalid composite id mapping. Could not resolve property ["+name+"] for entity ["+javaClass.getName()+"]"); } } } return identifiers; }
if(identity == null && identifier != null) { final String[] identifierName = identifier.getIdentifierName(); final MappingContext mappingContext = getMappingContext(); if(identifierName.length > 1) {