Search in sources :

Example 1 with GrailsDomainException

use of org.grails.core.exceptions.GrailsDomainException in project grails-core by grails.

the class DefaultGrailsDomainClass method initializePersistentProperties.

private void initializePersistentProperties() {
    if (!propertiesInitialized) {
        verifyContextIsInitialized();
        propertyMap = new LinkedHashMap<>();
        PersistentProperty identity = persistentEntity.getIdentity();
        if (identity != null) {
            identifier = new DefaultGrailsDomainClassProperty(this, persistentEntity, identity);
        }
        // First go through the properties of the class and create domain properties
        // populating into a map
        populateDomainClassProperties();
        // set properties from map values
        persistentProperties = propertyMap.values().toArray(new GrailsDomainClassProperty[propertyMap.size()]);
        // if no identifier property throw exception
        if (identifier == null) {
            throw new GrailsDomainException("Identity property not found, but required in domain class [" + getFullName() + "]");
        } else {
            propertyMap.put(identifier.getName(), identifier);
        }
        // if no version property throw exception
        if (version != null) {
            propertyMap.put(version.getName(), version);
        }
        List<MetaProperty> properties = getMetaClass().getProperties();
        for (MetaProperty property : properties) {
            String name = property.getName();
            if (!propertyMap.containsKey(name) && !NameUtils.isConfigurational(name) && !Modifier.isStatic(property.getModifiers())) {
                propertyMap.put(name, new MetaGrailsDomainClassProperty(this, property));
            }
        }
        this.properties = propertyMap.values().toArray(new GrailsDomainClassProperty[propertyMap.size()]);
    }
    propertiesInitialized = true;
}
Also used : GrailsDomainClassProperty(grails.core.GrailsDomainClassProperty) PersistentProperty(org.grails.datastore.mapping.model.PersistentProperty) MetaProperty(groovy.lang.MetaProperty) GrailsDomainException(org.grails.core.exceptions.GrailsDomainException)

Aggregations

GrailsDomainClassProperty (grails.core.GrailsDomainClassProperty)1 MetaProperty (groovy.lang.MetaProperty)1 GrailsDomainException (org.grails.core.exceptions.GrailsDomainException)1 PersistentProperty (org.grails.datastore.mapping.model.PersistentProperty)1