public static Type GetRootType(ICriteria criteria) { Type rootType = criteria.GetRootEntityTypeIfAvailable(); if (rootType != null) { return(rootType); } CriteriaImpl impl = GetRootCriteria(criteria); if (impl.Session == null) { throw new InvalidOperationException("Could not get root type on criteria that is not attached to a session"); } ISessionFactoryImplementor factory = impl.Session.Factory; IEntityPersister persister = factory.GetEntityPersister(impl.EntityOrClassName); if (persister == null) { throw new InvalidOperationException("Could not find entity named: " + impl.EntityOrClassName); } return(persister.GetMappedClass(EntityMode.Poco)); }
/// <summary> /// Get the id value from the owning entity key, usually the same as the key, but might be some /// other property, in the case of property-ref /// </summary> /// <param name="key">The collection owner key </param> /// <param name="session">The session from which the request is originating. </param> /// <returns> /// The collection owner's id, if it can be obtained from the key; /// otherwise, null is returned /// </returns> public virtual object GetIdOfOwnerOrNull(object key, ISessionImplementor session) { object ownerId = null; if (foreignKeyPropertyName == null) { ownerId = key; } else { IType keyType = GetPersister(session).KeyType; IEntityPersister ownerPersister = GetPersister(session).OwnerEntityPersister; // TODO: Fix this so it will work for non-POJO entity mode System.Type ownerMappedClass = ownerPersister.GetMappedClass(session.EntityMode); if (ownerMappedClass.IsAssignableFrom(keyType.ReturnedClass) && keyType.ReturnedClass.IsInstanceOfType(key)) { // the key is the owning entity itself, so get the ID from the key ownerId = ownerPersister.GetIdentifier(key, session.EntityMode); } else { // TODO: check if key contains the owner ID } } return(ownerId); }
private static System.Type GetRootType(DetachedCriteria criteria, ISession session) { ISessionFactoryImplementor factory = (ISessionFactoryImplementor)session.SessionFactory; IEntityPersister persister = factory.GetEntityPersister(criteria.EntityOrClassName); if (persister == null) { throw new InvalidOperationException("Could not find entity named: " + criteria.EntityOrClassName); } return(persister.GetMappedClass(EntityMode.Poco)); }
public static Type GetRootType(DetachedCriteria criteria, ISession session) { Type rootType = criteria.GetRootEntityTypeIfAvailable(); if (rootType != null) { return(rootType); } ISessionFactoryImplementor factory = (ISessionFactoryImplementor)session.SessionFactory; IEntityPersister persister = factory.GetEntityPersister(criteria.EntityOrClassName); if (persister == null) { throw new InvalidOperationException("Could not find entity named: " + criteria.EntityOrClassName); } return(persister.GetMappedClass(EntityMode.Poco)); }
private object[] GetPropertyValues(IEntityPersister persister, ICriteria criteria, ICriteriaQuery criteriaQuery) { System.Type type = _entity.GetType(); if (type == persister.GetMappedClass(GetEntityMode(criteria, criteriaQuery))) //not using anon object { return(persister.GetPropertyValues(_entity, GetEntityMode(criteria, criteriaQuery))); } var list = new List <object>(); for (int i = 0; i < persister.PropertyNames.Length; i++) { PropertyInfo pInfo = type.GetProperty(persister.PropertyNames[i]); if (pInfo != null) { list.Add(pInfo.GetValue(_entity, null)); } else { list.Add(null); //to maintain same order as PropertyNames list _excludedProperties.Add(persister.PropertyNames[i]); //exclude the properties that aren't in the anon object (duplicates ok) } } return(list.ToArray()); }
private void MarkInterceptorDirty(object entity, IEntityPersister persister, IEventSource source) { if (FieldInterceptionHelper.IsInstrumented(entity)) { IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, persister.GetMappedClass(source.EntityMode), null, null, source); interceptor.MarkDirty(); } }
private object[] GetPropertyValues(IEntityPersister persister, ICriteria criteria, ICriteriaQuery criteriaQuery) { System.Type type = _entity.GetType(); if(type == persister.GetMappedClass(GetEntityMode(criteria, criteriaQuery))) //not using anon object { return persister.GetPropertyValues(_entity, GetEntityMode(criteria, criteriaQuery)); } ArrayList list = new ArrayList(); for(int i = 0; i < persister.PropertyNames.Length; i++) { PropertyInfo pInfo = type.GetProperty(persister.PropertyNames[i]); if(pInfo != null) { list.Add(pInfo.GetValue(_entity, null)); } else { list.Add(null); //to maintain same order as PropertyNames list _excludedProperties.Add(persister.PropertyNames[i]); //exclude the properties that aren't in the anon object (duplicates ok) } } return list.ToArray(); }
private void MarkInterceptorDirty(object entity, IEntityPersister persister, IEventSource source) { if (FieldInterceptionHelper.IsInstrumented(entity)) { IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, persister.GetMappedClass(source.EntityMode), null, null, source); interceptor.MarkDirty(); } }