use of org.grails.datastore.mapping.model.PersistentProperty 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;
}
use of org.grails.datastore.mapping.model.PersistentProperty 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;
}
Aggregations