Search in sources :

Example 1 with PersistentEntity

use of org.grails.datastore.mapping.model.PersistentEntity in project grails-core by grails.

the class DefaultGrailsDomainClass method getSubClasses.

/**
     * Obtains a Set of subclasses
     *
     * @deprecated Use {@link org.grails.datastore.mapping.model.MappingContext} API instead
     */
@Deprecated
@Override
@SuppressWarnings("unchecked")
public Set getSubClasses() {
    verifyContextIsInitialized();
    Set<GrailsDomainClass> subClasses = new LinkedHashSet<>();
    for (PersistentEntity e : mappingContext.getChildEntities(persistentEntity)) {
        subClasses.add((GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, e.getName()));
    }
    return subClasses;
}
Also used : PersistentEntity(org.grails.datastore.mapping.model.PersistentEntity) GrailsDomainClass(grails.core.GrailsDomainClass)

Example 2 with PersistentEntity

use of org.grails.datastore.mapping.model.PersistentEntity in project grails-core by grails.

the class DefaultGrailsDomainClass method getMergedConfigurationMap.

@SuppressWarnings("unchecked")
private Map getMergedConfigurationMap() {
    verifyContextIsInitialized();
    Map configurationMap = new HashMap();
    PersistentEntity currentEntity = this.persistentEntity;
    while (currentEntity != null) {
        List<Association> associations = currentEntity.getAssociations();
        for (Association association : associations) {
            PersistentEntity associatedEntity = association.getAssociatedEntity();
            if (associatedEntity != null) {
                configurationMap.put(association.getName(), associatedEntity.getJavaClass());
            }
        }
        currentEntity = currentEntity.getParentEntity();
    }
    return configurationMap;
}
Also used : Association(org.grails.datastore.mapping.model.types.Association) PersistentEntity(org.grails.datastore.mapping.model.PersistentEntity)

Example 3 with PersistentEntity

use of org.grails.datastore.mapping.model.PersistentEntity in project grails-core by grails.

the class DefaultGrailsDomainClass method getPersistentProperty.

public GrailsDomainClassProperty getPersistentProperty(String name) {
    initializePersistentProperties();
    if (propertyMap.containsKey(name)) {
        return propertyMap.get(name);
    }
    int indexOfDot = name.indexOf('.');
    if (indexOfDot > 0) {
        String basePropertyName = name.substring(0, indexOfDot);
        if (propertyMap.containsKey(basePropertyName)) {
            verifyContextIsInitialized();
            PersistentProperty prop = persistentEntity.getPropertyByName(basePropertyName);
            PersistentEntity referencedEntity = prop.getOwner();
            GrailsDomainClass referencedDomainClass = (GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, referencedEntity.getName());
            if (referencedDomainClass != null) {
                String restOfPropertyName = name.substring(indexOfDot + 1);
                return referencedDomainClass.getPropertyByName(restOfPropertyName);
            }
        }
    }
    return null;
}
Also used : PersistentEntity(org.grails.datastore.mapping.model.PersistentEntity) GrailsDomainClass(grails.core.GrailsDomainClass) PersistentProperty(org.grails.datastore.mapping.model.PersistentProperty)

Aggregations

PersistentEntity (org.grails.datastore.mapping.model.PersistentEntity)3 GrailsDomainClass (grails.core.GrailsDomainClass)2 PersistentProperty (org.grails.datastore.mapping.model.PersistentProperty)1 Association (org.grails.datastore.mapping.model.types.Association)1