public NativeEntryEntityPersister(MappingContext mappingContext, PersistentEntity entity, Session session, ApplicationEventPublisher publisher) { super(mappingContext, entity, session, publisher); classMapping = entity.getMapping(); }
public ClassMapping getClassMapping() { return owner.getMapping(); } public T getMappedForm() {
public ClassMapping getClassMapping() { return owner.getMapping(); } public T getMappedForm() {
public NativeEntryEntityPersister(MappingContext mappingContext, PersistentEntity entity, Session session, ApplicationEventPublisher publisher, TPCacheAdapterRepository<T> cacheAdapterRepository) { super(mappingContext, entity, session, publisher, cacheAdapterRepository); classMapping = entity.getMapping(); }
@Override public String getIdentifierName() { return getIdentifierName(persistentEntity.getMapping()); }
@Override public void setIdentifier(Object id) { String idName = getIdentifierName(persistentEntity.getMapping()); setProperty(idName, id); }
@Override public void setIdentifierNoConversion(Object id) { String idName = getIdentifierName(persistentEntity.getMapping()); setPropertyNoConversion(idName, id); }
/** * 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 boolean isStateless(PersistentEntity entity) { Entity mappedForm = entity != null ? entity.getMapping().getMappedForm() : null; return isStateless() || (mappedForm != null && mappedForm.isStateless()); }
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); } }
@Override public Object getIdentifier() { String idName = getIdentifierName(persistentEntity.getMapping()); if (idName != null) { return getProperty(idName); } PersistentProperty identity = persistentEntity.getIdentity(); if(identity != null) { return getProperty(identity.getName()); } return null; }
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 } } } } }
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()); } }
public void afterLoad(final PersistentEntity entity, final EntityAccess ea, PostLoadEvent event) { activateDirtyChecking(ea); if (autowireEntities || ( entity != null && entity.getMapping().getMappedForm().isAutowire() )) { autowireBeanProperties(ea.getEntity()); } invokeEvent(EVENT_AFTER_LOAD, entity, ea, event); }
/** * @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; }
cascadeStrategy = CASCADE_ALL; else if(isCompositeIdProperty((Mapping) domainClass.getMapping().getMappedForm(), grailsProperty)) { cascadeStrategy = CASCADE_ALL;
final NativeEntryModifyingEntityAccess entityAccess = (NativeEntryModifyingEntityAccess) createEntityAccess(persistentEntity, obj, tmp); K k = readObjectIdentifier(entityAccess, persistentEntity.getMapping());