protected String getKeyspace(ClassMapping<Family> cm, String defaultValue) { String keyspace = null; if (cm.getMappedForm() != null) { keyspace = cm.getMappedForm().getKeyspace(); } if (keyspace == null) keyspace = defaultValue; return keyspace; } }
private PersistentEntity getPersistentEntity(Class javaClass, MappingContext context, ClassMapping classMapping) { if (classMapping != null) { return classMapping.getEntity(); } return context.getPersistentEntity(javaClass.getName()); }
/** * 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]; }
final T mappedForm = mapping.getMappedForm();// initialize mapping IdentityMapping identifier = mapping != null ? mapping.getIdentifier() : null; if(identity == null && identifier != null) {
protected String getFamily(PersistentEntity persistentEntity, ClassMapping<Family> cm) { String table = null; if (cm.getMappedForm() != null) { table = cm.getMappedForm().getFamily(); } if (table == null) table = persistentEntity.getJavaClass().getName(); return table; }
@Override public IdentityMapping createIdentityMapping(ClassMapping classMapping) { Map<String, T> props = entityToPropertyMap.get(classMapping.getEntity()); if (props != null) { T property = props.get(IDENTITY_PROPERTY); IdentityMapping customIdentityMapping = getIdentityMappedForm(classMapping,property); if (customIdentityMapping != null) { return customIdentityMapping; } } return super.createIdentityMapping(classMapping); }
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); }
/** * Obtain all of the {@link ConnectionSource} names for the given entity * * @param entity The entity * @return The {@link ConnectionSource} names */ public static List<String> getConnectionSourceNames(PersistentEntity entity) { final Entity mappedForm = entity.getMapping().getMappedForm(); if(mappedForm != null) { return mappedForm.getDatasources(); } return DEFAULT_CONNECTION_SOURCE_NAMES; }
public Property getMappedForm() { return classMapping.getEntity().getIdentity().getMapping().getMappedForm(); } };
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; }
public boolean isStateless(PersistentEntity entity) { Entity mappedForm = entity != null ? entity.getMapping().getMappedForm() : null; return isStateless() || (mappedForm != null && mappedForm.isStateless()); }
public Property getMappedForm() { return classMapping.getEntity().getIdentity().getMapping().getMappedForm(); } };
/** * @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; }
public Mapping evaluateMapping(PersistentEntity domainClass, Closure<?> defaultMapping, boolean cache) { try { final Mapping m = (Mapping) domainClass.getMapping().getMappedForm(); trackCustomCascadingSaves(m, domainClass.getPersistentProperties()); if (cache) { MAPPING_CACHE.put(domainClass.getJavaClass(), m); } return m; } catch (Exception e) { throw new DatastoreConfigurationException("Error evaluating ORM mappings block for domain [" + domainClass.getName() + "]: " + e.getMessage(), e); } }
public String[] getIdentifierName() { PersistentProperty identity = classMapping.getEntity().getIdentity(); String propertyName = identity != null ? identity.getMapping().getMappedForm().getName() : null; if(propertyName != null) { return new String[] { propertyName }; } else { return new String[] { IDENTITY_PROPERTY }; } }
@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; }
protected void storeDateCreatedAndLastUpdatedInfo(PersistentEntity persistentEntity) { if(persistentEntity.isInitialized()) { ClassMapping<?> classMapping = persistentEntity.getMapping(); Entity mappedForm = classMapping.getMappedForm(); if(mappedForm == null || mappedForm.isAutoTimestamp()) { storeTimestampAvailability(entitiesWithDateCreated, persistentEntity, persistentEntity.getPropertyByName(DATE_CREATED_PROPERTY)); storeTimestampAvailability(entitiesWithLastUpdated, persistentEntity, persistentEntity.getPropertyByName(LAST_UPDATED_PROPERTY)); } } else { uninitializedEntities.add(persistentEntity.getName()); } }
@Override public IdentityMapping getIdentityMapping(final ClassMapping classMapping) { final PersistentEntity entity = classMapping.getEntity();
private static void autowire(Object instance) { if(!Environment.isInitializing()) { GrailsApplication application = Holders.findApplication(); if(application != null) { try { PersistentEntity domainClass = application.getMappingContext().getPersistentEntity(instance.getClass().getName()); if(domainClass != null) { if (domainClass.getMapping().getMappedForm().isAutowire()) { final ApplicationContext applicationContext = Holders.findApplicationContext(); if (applicationContext != null) { applicationContext .getAutowireCapableBeanFactory() .autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); } } } } catch (GrailsConfigurationException e) { // ignore, Mapping Context not initialized yet } } } } }
@Override public IdentityMapping createIdentityMapping(final ClassMapping classMapping) { final Mapping mappedForm = createMappedForm(classMapping.getEntity()); final Object identity = mappedForm.getIdentity(); final ValueGenerator generator; throw new DatastoreConfigurationException("Invalid id generation strategy for entity ["+classMapping.getEntity().getName()+"]: " + generatorName);