private List <TypedValue> GetParameterTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { IType type = GetElementType(criteria, criteriaQuery); if (type.IsComponentType) { List <TypedValue> list = new List <TypedValue>(); IAbstractComponentType actype = (IAbstractComponentType)type; IType[] types = actype.Subtypes; for (int i = 0; i < types.Length; i++) { for (int j = 0; j < _values.Length; j++) { object subval = _values[j] == null ? null : actype.GetPropertyValues(_values[j], EntityMode.Poco)[i]; list.Add(new TypedValue(types[i], subval, EntityMode.Poco)); } } return(list); } else { return(_values.Select(v => new TypedValue(type, v, EntityMode.Poco)).ToList()); } }
/// <summary> /// Check component nullability. Returns property path that break /// nullability or null if none /// </summary> /// <param name="value">component properties </param> /// <param name="compType">component not-nullable type </param> /// <returns> property path </returns> private string CheckComponentNullability(object value, IAbstractComponentType compType) { // will check current level if some of them are not null or sublevels if they exist bool[] nullability = compType.PropertyNullability; if (nullability != null) { //do the test object[] values = compType.GetPropertyValues(value, session.EntityMode); IType[] propertyTypes = compType.Subtypes; for (int i = 0; i < values.Length; i++) { object subvalue = values[i]; if (!nullability[i] && subvalue == null) { return(compType.PropertyNames[i]); } else if (subvalue != null) { string breakProperties = CheckSubElementsNullability(propertyTypes[i], subvalue); if (breakProperties != null) { return(BuildPropertyPath(compType.PropertyNames[i], breakProperties)); } } } } return(null); }
protected void AddComponentTypedValues(string path, object component, IAbstractComponentType type, IList list, ICriteria criteria, ICriteriaQuery criteriaQuery) { if (component != null) { string[] propertyNames = type.PropertyNames; IType[] subtypes = type.Subtypes; object[] values = type.GetPropertyValues(component, GetEntityMode(criteria, criteriaQuery)); for (int i = 0; i < propertyNames.Length; i++) { object value = values[i]; IType subtype = subtypes[i]; string subpath = StringHelper.Qualify(path, propertyNames[i]); if (IsPropertyIncluded(value, subpath, subtype)) { if (subtype.IsComponentType) { AddComponentTypedValues(subpath, value, (IAbstractComponentType)subtype, list, criteria, criteriaQuery); } else { AddPropertyTypedValue(value, subtype, list); } } } } }
protected override object ProcessComponent(object component, IAbstractComponentType componentType) { if (component == null) { return(null); } object[] values = componentType.GetPropertyValues(component, Session); IType[] types = componentType.Subtypes; bool substituteComponent = false; for (int i = 0; i < types.Length; i++) { object result = ProcessValue(values[i], types[i]); if (result != null) { substituteComponent = true; values[i] = result; } } if (substituteComponent) { componentType.SetPropertyValues(component, values); } return(null); }
public object GetIdentifier(object entity) { object id; if (entityMetamodel.IdentifierProperty.IsEmbedded) { id = entity; } else { if (idGetter == null) { if (identifierMapperType == null) { throw new HibernateException("The class has no identifier property: " + EntityName); } else { ComponentType copier = (ComponentType)entityMetamodel.IdentifierProperty.Type; id = copier.Instantiate(); copier.SetPropertyValues(id, identifierMapperType.GetPropertyValues(entity)); } } else { id = GetIdentifierPropertyValue(entity); } } return(id); }
private List <TypedValue> GetParameterTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { IType type = GetElementType(criteria, criteriaQuery); if (!type.IsComponentType) { return(_values.ToList(v => new TypedValue(type, v, false))); } List <TypedValue> list = new List <TypedValue>(); IAbstractComponentType actype = (IAbstractComponentType)type; var types = actype.Subtypes; foreach (var value in _values) { var propertyValues = value != null?actype.GetPropertyValues(value) : null; for (int ti = 0; ti < types.Length; ti++) { list.Add(new TypedValue(types[ti], propertyValues?[ti], false)); } } return(list); }
public override TypedValue[] GetTypedValues(ISessionFactoryImplementor sessionFactory, System.Type persistentClass, IDictionary aliasClasses) { ArrayList list = new ArrayList(); IType type = GetType(sessionFactory, persistentClass, _propertyName, aliasClasses); if (type.IsComponentType) { IAbstractComponentType actype = ( IAbstractComponentType )type; IType[] types = actype.Subtypes; for (int i = 0; i < types.Length; i++) { for (int j = 0; j < _values.Length; j++) { object subval = _values[j] == null ? null : actype.GetPropertyValues(_values[j])[i]; list.Add(new TypedValue(types[i], subval)); } } } else { for (int j = 0; j < _values.Length; j++) { list.Add(new TypedValue(type, _values[j])); } } return(( TypedValue[] )list.ToArray(typeof(TypedValue))); }
/// <summary> /// Visit a component. Dispatch each property to <see cref="ProcessValues"/> /// </summary> /// <param name="component"></param> /// <param name="componentType"></param> /// <returns></returns> internal virtual object ProcessComponent(object component, IAbstractComponentType componentType) { if (component != null) { ProcessValues(componentType.GetPropertyValues(component, session), componentType.Subtypes); } return(null); }
/// <summary> /// Visit a component. Dispatch each property to <see cref="ProcessValues"/> /// </summary> /// <param name="component"></param> /// <param name="componentType"></param> /// <returns></returns> internal virtual object ProcessComponent(object component, IAbstractComponentType componentType) { if (component != null) { ProcessValues(componentType.GetPropertyValues(component, session), componentType.Subtypes); } return null; }
/// <summary> /// Cascade an action to the child or children /// </summary> /// <param name="session"></param> /// <param name="child"></param> /// <param name="type"></param> /// <param name="action"></param> /// <param name="style"></param> /// <param name="cascadeTo"></param> /// <param name="anything"></param> private static void Cascade( ISessionImplementor session, object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, object anything) { if (child != null) { if (type.IsAssociationType) { if ((( IAssociationType )type).ForeignKeyType.CascadeNow(cascadeTo)) { if (type.IsEntityType || type.IsObjectType) { action.Cascade(session, child, anything); } else if (type.IsPersistentCollectionType) { CascadePoint cascadeVia; if (cascadeTo == CascadePoint.CascadeAfterInsertBeforeDelete) { cascadeVia = CascadePoint.CascadeAfterInsertBeforeDeleteViaCollection; } else { cascadeVia = cascadeTo; } PersistentCollectionType pctype = ( PersistentCollectionType )type; ICollectionPersister persister = session.Factory.GetCollectionPersister(pctype.Role); IType elemType = persister.ElementType; // cascade to current collection elements if (elemType.IsEntityType || elemType.IsObjectType || elemType.IsComponentType) { CascadeCollection(action, style, pctype, elemType, child, cascadeVia, session, anything); } } } } else if (type.IsComponentType) { IAbstractComponentType ctype = (( IAbstractComponentType )type); object[] children = ctype.GetPropertyValues(child, session); IType[] types = ctype.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = ctype.Cascade(i); if (componentPropertyStyle.DoCascade(action)) { Cascade(session, children[i], types[i], action, componentPropertyStyle, cascadeTo, anything); } } } } }
private void CascadeComponent(object parent, object child, IAbstractComponentType componentType, object anything) { object[] children = componentType.GetPropertyValues(child, eventSource); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = componentType.GetCascadeStyle(i); if (componentPropertyStyle.DoCascade(action)) { CascadeProperty(parent, children[i], types[i], componentPropertyStyle, anything, false); } } }
protected void AppendComponentCondition( String path, object component, IAbstractComponentType type, System.Type persistentClass, String alias, IDictionary aliasClasses, ISessionFactoryImplementor sessionFactory, SqlStringBuilder builder) { if (component != null) { String[] propertyNames = type.PropertyNames; object[] values = type.GetPropertyValues(component, null); IType[] subtypes = type.Subtypes; for (int i = 0; i < propertyNames.Length; i++) { String subpath = StringHelper.Qualify(path, propertyNames[i]); object value = values[i]; if (IsPropertyIncluded(value, subpath, subtypes[i])) { IType subtype = subtypes[i]; if (subtype.IsComponentType) { AppendComponentCondition( subpath, value, (IAbstractComponentType)subtype, persistentClass, alias, aliasClasses, sessionFactory, builder); } else { AppendPropertyCondition( subpath, value, persistentClass, alias, aliasClasses, sessionFactory, builder ); } } } } }
/// <summary> /// Return null if the argument is an "unsaved" entity (ie. /// one with no existing database row), or the input argument /// otherwise. This is how Hibernate avoids foreign key constraint /// violations. /// </summary> private object NullifyTransientReferences(object value, IType type) { if (value == null) { return(null); } else if (type.IsEntityType) { EntityType entityType = (EntityType)type; if (entityType.IsOneToOne) { return(value); } else { string entityName = entityType.GetAssociatedEntityName(); return(IsNullifiable(entityName, value) ? null : value); } } else if (type.IsAnyType) { return(IsNullifiable(null, value) ? null : value); } else if (type.IsComponentType) { IAbstractComponentType actype = (IAbstractComponentType)type; object[] subvalues = actype.GetPropertyValues(value, session); IType[] subtypes = actype.Subtypes; bool substitute = false; for (int i = 0; i < subvalues.Length; i++) { object replacement = NullifyTransientReferences(subvalues[i], subtypes[i]); if (replacement != subvalues[i]) { substitute = true; subvalues[i] = replacement; } } if (substitute) { actype.SetPropertyValues(value, subvalues); } return(value); } else { return(value); } }
public void SetIdentifier(object entity, object id) { if (entityMetamodel.IdentifierProperty.IsEmbedded) { if (entity != id) { IAbstractComponentType copier = (IAbstractComponentType)entityMetamodel.IdentifierProperty.Type; copier.SetPropertyValues(entity, copier.GetPropertyValues(id)); } } else if (idSetter != null) { SetIdentifierPropertyValue(entity, id); } }
public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery) { List <TypedValue> list = new List <TypedValue>(); IType type; if (_projection == null) { type = criteriaQuery.GetTypeUsingProjection(criteria, _propertyName); } else { IType[] types = _projection.GetTypes(criteria, criteriaQuery); if (types.Length != 1) { throw new QueryException("Cannot use projections that return more than a single column with InExpression"); } type = types[0]; list.AddRange(_projection.GetTypedValues(criteria, criteriaQuery)); } if (type.IsComponentType) { IAbstractComponentType actype = (IAbstractComponentType)type; IType[] types = actype.Subtypes; for (int i = 0; i < types.Length; i++) { for (int j = 0; j < _values.Length; j++) { object subval = _values[j] == null ? null : actype.GetPropertyValues(_values[j], EntityMode.Poco)[i]; list.Add(new TypedValue(types[i], subval, EntityMode.Poco)); } } } else { for (int j = 0; j < _values.Length; j++) { list.Add(new TypedValue(type, _values[j], EntityMode.Poco)); } } return(list.ToArray()); }
protected void AppendComponentCondition( String path, object component, IAbstractComponentType type, ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters, SqlStringBuilder builder) { if (component != null) { String[] propertyNames = type.PropertyNames; object[] values = type.GetPropertyValues(component, GetEntityMode(criteria, criteriaQuery)); IType[] subtypes = type.Subtypes; for (int i = 0; i < propertyNames.Length; i++) { String subpath = StringHelper.Qualify(path, propertyNames[i]); object value = values[i]; if (IsPropertyIncluded(value, subpath, subtypes[i])) { IType subtype = subtypes[i]; if (subtype.IsComponentType) { AppendComponentCondition( subpath, value, (IAbstractComponentType)subtype, criteria, criteriaQuery, enabledFilters, builder); } else { AppendPropertyCondition( subpath, value, criteria, criteriaQuery, enabledFilters, builder ); } } } } }
internal override object ProcessComponent(object component, IAbstractComponentType componentType) { if (component != null) { object[] values = componentType.GetPropertyValues(component, Session); IType[] types = componentType.Subtypes; bool substituteComponent = false; for (int i = 0; i < types.Length; i++) { System.Object result = ProcessValue(values[i], types[i]); if (result != null) { values[i] = result; substituteComponent = true; } } if (substituteComponent) { componentType.SetPropertyValues(component, values, Session.EntityMode); } } return null; }
private static TypedValue[] GetTypedValues(IType type, object value) { if (!type.IsComponentType) { return new[] { new TypedValue(type, value) } } ; IAbstractComponentType actype = (IAbstractComponentType)type; IType[] types = actype.Subtypes; var list = new TypedValue[types.Length]; var propertyValues = value == null ? null : actype.GetPropertyValues(value); for (int ti = 0; ti < types.Length; ti++) { list[ti] = new TypedValue(types[ti], propertyValues?[ti], false); } return(list); } }
protected void AppendComponentCondition( String path, object component, IAbstractComponentType type, ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters, SqlStringBuilder builder) { if (component != null) { String[] propertyNames = type.PropertyNames; object[] values = type.GetPropertyValues(component, GetEntityMode(criteria, criteriaQuery)); IType[] subtypes = type.Subtypes; for (int i = 0; i < propertyNames.Length; i++) { String subpath = StringHelper.Qualify(path, propertyNames[i]); object value = values[i]; if (IsPropertyIncluded(value, subpath, subtypes[i])) { IType subtype = subtypes[i]; if (subtype.IsComponentType) { AppendComponentCondition( subpath, value, (IAbstractComponentType) subtype, criteria, criteriaQuery, enabledFilters, builder); } else { AppendPropertyCondition( subpath, value, criteria, criteriaQuery, enabledFilters, builder ); } } } } }
protected void AddComponentTypedValues(string path, object component, IAbstractComponentType type, IList list, ICriteria criteria, ICriteriaQuery criteriaQuery) { if (component != null) { string[] propertyNames = type.PropertyNames; IType[] subtypes = type.Subtypes; object[] values = type.GetPropertyValues(component, GetEntityMode(criteria, criteriaQuery)); for (int i = 0; i < propertyNames.Length; i++) { object value = values[i]; IType subtype = subtypes[i]; string subpath = StringHelper.Qualify(path, propertyNames[i]); if (IsPropertyIncluded(value, subpath, subtype)) { if (subtype.IsComponentType) { AddComponentTypedValues(subpath, value, (IAbstractComponentType) subtype, list, criteria, criteriaQuery); } else { AddPropertyTypedValue(value, subtype, list); } } } } }
/// <summary> /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)" /> /// operation across a series of values, as long as the corresponding <see cref="IType"/> is an association. /// </summary> /// <param name="original">The source of the state</param> /// <param name="target">The target into which to replace the source values.</param> /// <param name="types">The value types</param> /// <param name="session">The originating session</param> /// <param name="owner">The entity "owning" the values</param> /// <param name="copyCache">A map representing a cache of already replaced state</param> /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param> /// <returns> The replaced state</returns> /// <remarks> /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociations" /> /// across the component subtypes but do not replace the component value itself. /// </remarks> public static object[] ReplaceAssociations(object[] original, object[] target, IType[] types, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) { object[] copied = new object[original.Length]; for (int i = 0; i < types.Length; i++) { if (Equals(LazyPropertyInitializer.UnfetchedProperty, original[i]) || Equals(BackrefPropertyAccessor.Unknown, original[i])) { copied[i] = target[i]; } else if (types[i].IsComponentType) { // need to extract the component values and check for subtype replacements... IAbstractComponentType componentType = (IAbstractComponentType)types[i]; IType[] subtypes = componentType.Subtypes; object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session); object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session); object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection); if (!componentType.IsAnyType && target[i] != null) { componentType.SetPropertyValues(target[i], componentCopy, session.EntityMode); } copied[i] = target[i]; } else if (!types[i].IsAssociationType) { copied[i] = target[i]; } else { copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection); } } return(copied); }
private void CascadeComponent(object parent, object child, IAbstractComponentType componentType, string componentPropertyName, object anything) { componentPathStack.Push(componentPropertyName); object[] children = componentType.GetPropertyValues(child, eventSource); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = componentType.GetCascadeStyle(i); string subPropertyName = componentType.PropertyNames[i]; if (componentPropertyStyle.DoCascade(action)) { CascadeProperty(parent, children[i], types[i], componentPropertyStyle, subPropertyName, anything, false); } } componentPathStack.Pop(); }
protected override object ProcessComponent(object component, IAbstractComponentType componentType) { if (component == null) { return null; } object[] values = componentType.GetPropertyValues(component, Session); IType[] types = componentType.Subtypes; bool substituteComponent = false; for (int i = 0; i < types.Length; i++) { object result = ProcessValue(values[i], types[i]); if (result != null) { substituteComponent = true; values[i] = result; } } if (substituteComponent) { componentType.SetPropertyValues(component, values); } return null; }
protected void AppendComponentCondition( String path, object component, IAbstractComponentType type, System.Type persistentClass, String alias, IDictionary aliasClasses, ISessionFactoryImplementor sessionFactory, SqlStringBuilder builder) { if( component != null ) { String[] propertyNames = type.PropertyNames; object[] values = type.GetPropertyValues( component, null ); IType[] subtypes = type.Subtypes; for( int i = 0; i < propertyNames.Length; i++ ) { String subpath = StringHelper.Qualify( path, propertyNames[ i ] ); object value = values[ i ]; if( IsPropertyIncluded( value, subpath, subtypes[ i ] ) ) { IType subtype = subtypes[ i ]; if( subtype.IsComponentType ) { AppendComponentCondition( subpath, value, (IAbstractComponentType)subtype, persistentClass, alias, aliasClasses, sessionFactory, builder ); } else { AppendPropertyCondition( subpath, value, persistentClass, alias, aliasClasses, sessionFactory, builder ); } } } } }
/// <summary> /// Check component nullability. Returns property path that break /// nullability or null if none /// </summary> /// <param name="value">component properties </param> /// <param name="compType">component not-nullable type </param> /// <returns> property path </returns> private string CheckComponentNullability(object value, IAbstractComponentType compType) { // will check current level if some of them are not null or sublevels if they exist bool[] nullability = compType.PropertyNullability; if (nullability != null) { //do the test object[] values = compType.GetPropertyValues(value, session.EntityMode); IType[] propertyTypes = compType.Subtypes; for (int i = 0; i < values.Length; i++) { object subvalue = values[i]; if (!nullability[i] && subvalue == null) { return compType.PropertyNames[i]; } else if (subvalue != null) { string breakProperties = CheckSubElementsNullability(propertyTypes[i], subvalue); if (breakProperties != null) { return BuildPropertyPath(compType.PropertyNames[i], breakProperties); } } } } return null; }
private void CascadeComponent(object child, IAbstractComponentType componentType, object anything) { object[] children = componentType.GetPropertyValues(child, eventSource); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { CascadeStyle componentPropertyStyle = componentType.GetCascadeStyle(i); if (componentPropertyStyle.DoCascade(action)) { CascadeProperty(children[i], types[i], componentPropertyStyle, anything, false); } } }