Exemplo n.º 1
0
        public static Ejb3Column[] BuildColumnFromAnnotation(
            ColumnAttribute[] anns,
            FormulaAttribute formulaAnn, Nullability nullability, IPropertyHolder propertyHolder,
            IPropertyData inferredData,
            IDictionary <string, Join> secondaryTables,
            ExtendedMappings mappings)
        {
            Ejb3Column[] columns;

            if (formulaAnn != null)
            {
                Ejb3Column formulaColumn = new Ejb3Column();
                formulaColumn.SetFormula(formulaAnn.Value);
                formulaColumn.SetImplicit(false);
                formulaColumn.Mappings       = mappings;
                formulaColumn.PropertyHolder = propertyHolder;
                formulaColumn.Bind();
                columns = new Ejb3Column[] { formulaColumn };
            }
            else
            {
                columns = BuildColumnFromAnnotation(anns,
                                                    nullability,
                                                    propertyHolder,
                                                    inferredData,
                                                    secondaryTables,
                                                    mappings);
            }
            return(columns);
        }
Exemplo n.º 2
0
        private static Ejb3Column[] BuildImplicitColumn(IPropertyData inferredData,
                                                        IDictionary <string, Join> secondaryTables,
                                                        IPropertyHolder propertyHolder, Nullability nullability,
                                                        ExtendedMappings mappings)
        {
            Ejb3Column[] columns;
            columns = new Ejb3Column[1];
            Ejb3Column column = new Ejb3Column();

            column.SetImplicit(false);
            //not following the spec but more clean
            if (nullability != Nullability.ForcedNull && inferredData.ClassOrElement.IsPrimitive &&
                !inferredData.Property.GetType().IsArray)         //TODO: IsArray in this way ???
            {
                column.SetNullable(false);
            }
            column.SetLength(DEFAULT_COLUMN_LENGTH);
            column.PropertyName   = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName);
            column.PropertyHolder = propertyHolder;
            column.SetJoins(secondaryTables);
            column.Mappings = mappings;
            column.Bind();
            columns[0] = column;
            return(columns);
        }
 public SecondaryTableSecondPass(EntityBinder entityBinder, IPropertyHolder propertyHolder,
                                 System.Type annotatedClass)
 {
     this.entityBinder = entityBinder;
     this.propertyHolder = propertyHolder;
     this.annotatedClass = annotatedClass;
 }
 public static bool TryGetValueAsObject(
     this IPropertyHolder propertyBag,
     string propertyName,
     out object value)
 {
     return(propertyBag.TryGetValue <object>(propertyName, out value));
 }
 public SecondaryTableSecondPass(EntityBinder entityBinder, IPropertyHolder propertyHolder,
                                 System.Type annotatedClass)
 {
     this.entityBinder   = entityBinder;
     this.propertyHolder = propertyHolder;
     this.annotatedClass = annotatedClass;
 }
 public static TValue GetValueOrDefault <TValue>(
     this IPropertyHolder propertyBag,
     string propertyName,
     TValue defaultValue)
 {
     return(propertyBag.TryGetValue <TValue>(propertyName, out var value)
                         ? value
                         : defaultValue);
 }
        private static GenerationMetaData GetGenMetaData(IPropertyHolder holder)
        {
            if (!holder.HasProperty("#GENERATION_META_DATA"))
            {
                holder.AddProperty("#GENERATION_META_DATA", new GenerationMetaData());
            }

            return(holder.GetPropertyAs <GenerationMetaData>("#GENERATION_META_DATA"));
        }
Exemplo n.º 8
0
 public static Ejb3JoinColumn BuildJoinColumn(PrimaryKeyJoinColumnAttribute pkJoinAnn,
                                              JoinColumnAttribute joinAnn,
                                              IKeyValue identifier,
                                              IDictionary <string, Join> joins,
                                              IPropertyHolder propertyHolder,
                                              ExtendedMappings mappings)
 {
     throw new NotImplementedException();
 }
		public static Ejb3JoinColumn BuildJoinColumn(PrimaryKeyJoinColumnAttribute pkJoinAnn,
									JoinColumnAttribute joinAnn, 
									IKeyValue identifier,
									IDictionary<string, Join> joins, 
									IPropertyHolder propertyHolder, 
									ExtendedMappings mappings)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 10
0
        private static Ejb3Column[] BuildColumnFromAnnotation(ColumnAttribute[] anns, Nullability nullability,
                                                              IPropertyHolder propertyHolder, IPropertyData inferredData,
                                                              IDictionary <string, Join> secondaryTables,
                                                              ExtendedMappings mappings)
        {
            ColumnAttribute[] actualCols     = anns;
            ColumnAttribute[] overriddenCols = propertyHolder.GetOverriddenColumn(StringHelper.Qualify(propertyHolder.Path, inferredData.PropertyName));

            if (overriddenCols != null)
            {
                //check for overridden first
                if (anns != null && overriddenCols.Length != anns.Length)
                {
                    throw new AnnotationException("AttributeOverride.column() should override all columns for now");
                }

                actualCols = overriddenCols.Length == 0 ? null : overriddenCols;
                log.DebugFormat("Column(s) overridden for property {0}", inferredData.PropertyName);
            }

            if (actualCols == null)
            {
                return(BuildImplicitColumn(inferredData, secondaryTables, propertyHolder, nullability, mappings));
            }

            int length = actualCols.Length;

            Ejb3Column[] columns = new Ejb3Column[length];
            for (int index = 0; index < length; index++)
            {
                ColumnAttribute col     = actualCols[index];
                String          sqlType = col.ColumnDefinition.Equals("") ? null : col.ColumnDefinition;
                Ejb3Column      column  = new Ejb3Column();
                column.SetImplicit(false);
                column.SetSqlType(sqlType);
                column.SetLength(col.Length);
                column.SetPrecision(col.Precision);
                column.SetScale(col.Scale);
                column.SetLogicalColumnName(col.Name);
                column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName);
                column.SetNullable(col.Nullable); //TODO force to not null if available? This is a (bad) user choice.
                column.SetUnique(col.Unique);
                column.SetInsertable(col.Insertable);
                column.SetUpdatable(col.Updatable);
                column.SetSecondaryTableName(col.Table);
                column.PropertyHolder = propertyHolder;
                column.SetJoins(secondaryTables);
                column.Mappings = mappings;
                column.Bind();
                columns[index] = column;
            }
            return(columns);
        }
 public static bool DeleteProperty(
     this IPropertyHolder propertyBag,
     string propertyName,
     Action <object, object> onDeleting         = null,
     Action <object, object> onDeleted          = null,
     Func <string, object> defaultValueProvider = null)
 {
     return(propertyBag.DeleteProperty(
                propertyName,
                onDeleting,
                onDeleted,
                defaultValueProvider));
 }
        public static TValue GetValueOrDefault <TValue>(
            this IPropertyHolder propertyBag,
            string propertyName,
            Func <TValue> defaultValueProvider)
        {
            if (defaultValueProvider == null)
            {
                throw new ArgumentNullException(nameof(defaultValueProvider));
            }

            return(propertyBag.TryGetValue <TValue>(propertyName, out var value)
                                ? value
                                : defaultValueProvider.Invoke());
        }
Exemplo n.º 13
0
        // TODO Little Problem here: Can't use T? since this would need a constraint to struct or class, which again wouldn't work fine with primitives
        public static T GetOrDefault <T>(IPropertyHolder holder, string name, T defaultValue = default, StringComparison comparisonType = StringComparison.Ordinal)
        {
            foreach (var value in from it
                     in holder.Properties
                     where it.Name.Text.Equals(name, comparisonType)
                     select it.Tag?.GetValue(typeof(T)))
            {
                if (value is T cast)
                {
                    return(cast);
                }
            }

            return(defaultValue);
        }
Exemplo n.º 14
0
        // TODO Little Problem here: Can't use T? since this would need a constraint to struct or class, which again wouldn't work fine with primitives
        public static T GetOrDefault <T>(IPropertyHolder holder, string name, T defaultValue = default, StringComparison comparisonType = StringComparison.Ordinal)
        {
            foreach (var prop in holder.Properties)
            {
                if (prop.Name.Text.Equals(name, comparisonType))
                {
                    var value = prop.Tag?.GetValue(typeof(T));
                    if (value is T cast)
                    {
                        return(cast);
                    }
                }
            }

            return(defaultValue);
        }
        public static TValue GetOrCreateValue <TValue>(
            this IPropertyHolder propertyBag,
            string propertyName,
            TValue newValue,
            Action <TValue> onCreated = null)
        {
            TValue actualNewValueProvider()
            {
                return(newValue);
            };

            return(propertyBag.GetOrCreateValue(
                       propertyName,
                       actualNewValueProvider,
                       onCreated));
        }
 public static bool SetValueAsObject(
     this IPropertyHolder propertyBag,
     string propertyName,
     object value,
     Action <object, object> onChanging          = null,
     Action <object, object> onChanged           = null,
     IEqualityComparer <object> equalityComparer = null,
     Func <string, object> defaultValueProvider  = null)
 {
     return(propertyBag.SetValue <object>(
                propertyName,
                value,
                onChanging,
                onChanged,
                equalityComparer,
                defaultValueProvider));
 }
Exemplo n.º 17
0
        public void FinalSecondaryTableBinding(IPropertyHolder propertyHolder)
        {
            /*
             * Those operations has to be done after the id definition of the persistence class.
             * ie after the properties parsing
             */
            var joins       = secondaryTables.Values.GetEnumerator();
            var joinColumns = secondaryTableJoins.Values.GetEnumerator();

            while (joins.MoveNext())
            {
                joinColumns.MoveNext();
                var uncastedColumn = joinColumns.Current;
                var join           = joins.Current;
                CreatePrimaryColumnsToSecondaryTable(uncastedColumn, propertyHolder, join);
            }
            mappings.AddJoins(persistentClass, secondaryTables);
        }
        public static TValue GetOrCreateValue <TValue>(
            this IPropertyHolder propertyBag,
            string propertyName,
            Func <TValue> newValueProvider,
            Action <TValue> onCreated = null)
        {
            if (newValueProvider == null)
            {
                throw new ArgumentNullException(nameof(newValueProvider));
            }

            TValue actualNewValueProvider()
            {
                return(newValueProvider.Invoke());
            };

            return(propertyBag.GetOrCreateValue(
                       propertyName,
                       actualNewValueProvider,
                       onCreated));
        }
Exemplo n.º 19
0
        private static Ejb3Column[] BuildColumnFromAnnotation(ColumnAttribute[] anns, Nullability nullability,
                                                              IPropertyHolder propertyHolder, IPropertyData inferredData,
                                                              IDictionary<string, Join> secondaryTables,
                                                              ExtendedMappings mappings)
        {
            ColumnAttribute[] actualCols = anns;
            ColumnAttribute[] overriddenCols = propertyHolder.GetOverriddenColumn(StringHelper.Qualify(propertyHolder.Path, inferredData.PropertyName));

            if (overriddenCols != null)
            {
                //check for overridden first
                if (anns != null && overriddenCols.Length != anns.Length)
                    throw new AnnotationException("AttributeOverride.column() should override all columns for now");

                actualCols = overriddenCols.Length == 0 ? null : overriddenCols;
                log.DebugFormat("Column(s) overridden for property {0}", inferredData.PropertyName);
            }

            if (actualCols == null)
                return BuildImplicitColumn(inferredData, secondaryTables, propertyHolder, nullability, mappings);

            int length = actualCols.Length;
            Ejb3Column[] columns = new Ejb3Column[length];
            for (int index = 0; index < length; index++)
            {
                ColumnAttribute col = actualCols[index];
                String sqlType = col.ColumnDefinition.Equals("") ? null : col.ColumnDefinition;
                Ejb3Column column = new Ejb3Column();
                column.SetImplicit(false);
                column.SetSqlType(sqlType);
                column.SetLength(col.Length);
                column.SetPrecision(col.Precision);
                column.SetScale(col.Scale);
                column.SetLogicalColumnName(col.Name);
                column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName);
                column.SetNullable(col.Nullable); //TODO force to not null if available? This is a (bad) user choice.
                column.SetUnique(col.Unique);
                column.SetInsertable(col.Insertable);
                column.SetUpdatable(col.Updatable);
                column.SetSecondaryTableName(col.Table);
                column.PropertyHolder = propertyHolder;
                column.SetJoins(secondaryTables);
                column.Mappings = mappings;
                column.Bind();
                columns[index] = column;
            }
            return columns;
        }
Exemplo n.º 20
0
        public static Ejb3Column[] BuildColumnFromAnnotation(
            ColumnAttribute[] anns,
            FormulaAttribute formulaAnn, Nullability nullability, IPropertyHolder propertyHolder,
            IPropertyData inferredData,
            IDictionary<string, Join> secondaryTables,
            ExtendedMappings mappings)
        {
            Ejb3Column[] columns;

            if (formulaAnn != null)
            {
                Ejb3Column formulaColumn = new Ejb3Column();
                formulaColumn.SetFormula(formulaAnn.Value);
                formulaColumn.SetImplicit(false);
                formulaColumn.Mappings = mappings;
                formulaColumn.PropertyHolder = propertyHolder;
                formulaColumn.Bind();
                columns = new Ejb3Column[] {formulaColumn};
            }
            else
            {
                columns = BuildColumnFromAnnotation(anns,
                                                    nullability,
                                                    propertyHolder,
                                                    inferredData,
                                                    secondaryTables,
                                                    mappings);
            }
            return columns;
        }
Exemplo n.º 21
0
        /// <summary>
        /// A non null propertyHolder means than we process the Pk creation without delay
        /// </summary>
        /// <param name="secondaryTable"></param>
        /// <param name="joinTable"></param>
        /// <param name="propertyHolder"></param>
        /// <param name="noDelayInPkColumnCreation"></param>
        /// <returns></returns>
        private Join AddJoin(SecondaryTableAttribute secondaryTable,
                             JoinTableAttribute joinTable,
                             IPropertyHolder propertyHolder,
                             bool noDelayInPkColumnCreation)
        {
            Join join = new Join();

            join.PersistentClass = persistentClass;
            string schema;
            string catalog;
            string table;
            string realTable;

            System.Persistence.UniqueConstraintAttribute[] uniqueConstraintsAnn;
            if (secondaryTable != null)
            {
                schema               = secondaryTable.Schema;
                catalog              = secondaryTable.Catalog;
                table                = secondaryTable.Name;
                realTable            = mappings.NamingStrategy.TableName(table);      //always an explicit table name
                uniqueConstraintsAnn = secondaryTable.UniqueConstraints;
            }
            else if (joinTable != null)
            {
                schema               = joinTable.Schema;
                catalog              = joinTable.Catalog;
                table                = joinTable.Name;
                realTable            = mappings.NamingStrategy.TableName(table);      //always an explicit table name
                uniqueConstraintsAnn = joinTable.UniqueConstraints;
            }
            else
            {
                throw new AssertionFailure("Both JoinTable and SecondaryTable are null");
            }

            var uniqueConstraints = new List <string[]>(uniqueConstraintsAnn == null ? 0 : uniqueConstraintsAnn.Length);

            if (uniqueConstraintsAnn != null && uniqueConstraintsAnn.Length != 0)
            {
                foreach (UniqueConstraintAttribute uc in uniqueConstraintsAnn)
                {
                    uniqueConstraints.Add(uc.ColumnNames);
                }
            }
            Table tableMapping = TableBinder.FillTable(
                schema,
                catalog,
                realTable,
                table, false, uniqueConstraints, null, null, mappings);

            //no check constraints available on joins
            join.Table = tableMapping;

            //somehow keep joins() for later.
            //Has to do the work later because it needs persistentClass id!
            object joinColumns = null;

            //get the appropriate pk columns
            if (secondaryTable != null)
            {
                joinColumns = secondaryTable.PkJoinColumns;
            }
            else if (joinTable != null)
            {
                joinColumns = joinTable.JoinColumns;
            }
            log.InfoFormat("Adding secondary table to entity {0} -> {1}", persistentClass.EntityName, join.Table.Name);

            TableAttribute matchingTable = FindMatchingComplimentTableAnnotation(join);

            if (matchingTable != null)
            {
                join.IsSequentialSelect = FetchMode.Join != matchingTable.Fetch;
                join.IsInverse          = matchingTable.IsInverse;
                join.IsOptional         = matchingTable.IsOptional;
                if (!BinderHelper.IsDefault(matchingTable.SqlInsert.Sql))
                {
                    join.SetCustomSQLInsert(matchingTable.SqlInsert.Sql.Trim(),
                                            matchingTable.SqlInsert.Callable,
                                            ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlInsert.Check.ToString().ToLower()));
                }
                if (!BinderHelper.IsDefault(matchingTable.SqlUpdate.Sql))
                {
                    join.SetCustomSQLUpdate(matchingTable.SqlUpdate.Sql.Trim(),
                                            matchingTable.SqlUpdate.Callable,
                                            ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlUpdate.Check.ToString().ToLower())
                                            );
                }
                if (!BinderHelper.IsDefault(matchingTable.SqlDelete.Sql))
                {
                    join.SetCustomSQLDelete(matchingTable.SqlDelete.Sql.Trim(),
                                            matchingTable.SqlDelete.Callable,
                                            ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlDelete.Check.ToString().ToLower())
                                            );
                }
            }
            else
            {
                //default
                join.IsSequentialSelect = false;
                join.IsInverse          = false;
                join.IsOptional         = false;         //perhaps not quite per-spec, but a Good Thing anyway
            }

            if (noDelayInPkColumnCreation)
            {
                CreatePrimaryColumnsToSecondaryTable(joinColumns, propertyHolder, join);
            }
            else
            {
                secondaryTables.Add(table, join);
                secondaryTableJoins.Add(table, joinColumns);
            }
            return(join);
        }
Exemplo n.º 22
0
 public static string GetRelativePath(IPropertyHolder propertyHolder, string propertyName)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 23
0
        //public void FirstLevelSecondaryTablesBinding(SecondaryTable secTable, SecondaryTables secTables)
        //{
        //    if (secTables != null)
        //    {
        //        //loop through it
        //        for (SecondaryTable tab : secTables.value())
        //        {
        //            addJoin( tab, null, null, false );
        //        }
        //    }
        //    else
        //    {
        //        if ( secTable != null ) addJoin( secTable, null, null, false );
        //    }
        //}

        /// <summary>
        /// Used for @*ToMany @JoinTable
        /// </summary>
        public Join AddJoin(JoinTableAttribute joinTable, IPropertyHolder holder, bool noDelayInPkColumnCreation)
        {
            return(AddJoin(null, joinTable, holder, noDelayInPkColumnCreation));
        }
Exemplo n.º 24
0
 public UserManager(IPropertyHolder properties, ILocker locker)
 {
     this.properties = properties.ThrowIfNull(nameof(properties));
     this.locker     = locker.ThrowIfNull(nameof(locker));
 }
Exemplo n.º 25
0
		public void FinalSecondaryTableBinding(IPropertyHolder propertyHolder)
		{
			/*
			 * Those operations has to be done after the id definition of the persistence class.
			 * ie after the properties parsing
			 */
			var joins = secondaryTables.Values.GetEnumerator();
			var joinColumns = secondaryTableJoins.Values.GetEnumerator();

			while (joins.MoveNext())
			{
				joinColumns.MoveNext();
				var uncastedColumn = joinColumns.Current;
				var join = joins.Current;
				CreatePrimaryColumnsToSecondaryTable(uncastedColumn, propertyHolder, join);
			}
			mappings.AddJoins(persistentClass, secondaryTables);
		}
Exemplo n.º 26
0
		public void SetHolder(IPropertyHolder holder)
		{
			this.holder = holder;
		}
Exemplo n.º 27
0
		//public void FirstLevelSecondaryTablesBinding(SecondaryTable secTable, SecondaryTables secTables) 
		//{
		//    if (secTables != null) 
		//    {
		//        //loop through it
		//        for (SecondaryTable tab : secTables.value()) 
		//        {
		//            addJoin( tab, null, null, false );
		//        }
		//    }
		//    else 
		//    {
		//        if ( secTable != null ) addJoin( secTable, null, null, false );
		//    }
		//}

		/// <summary>
		/// Used for @*ToMany @JoinTable
		/// </summary>
		public Join AddJoin(JoinTableAttribute joinTable, IPropertyHolder holder, bool noDelayInPkColumnCreation)
		{
			return AddJoin(null, joinTable, holder, noDelayInPkColumnCreation);
		}
Exemplo n.º 28
0
		private void CreatePrimaryColumnsToSecondaryTable(object uncastedColumn, IPropertyHolder propertyHolder, Join join)
		{
			Ejb3JoinColumn[] ejb3JoinColumns;
			PrimaryKeyJoinColumnAttribute[] pkColumnsAnn = null;
			JoinColumnAttribute[] joinColumnsAnn = null;
			if (uncastedColumn is PrimaryKeyJoinColumnAttribute[])
			{
				pkColumnsAnn = (PrimaryKeyJoinColumnAttribute[])uncastedColumn;
			}
			if (uncastedColumn is JoinColumnAttribute[])
			{
				joinColumnsAnn = (JoinColumnAttribute[])uncastedColumn;
			}
			if (pkColumnsAnn == null && joinColumnsAnn == null)
			{
				ejb3JoinColumns = new Ejb3JoinColumn[1];
				ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
						null,
						null,
						persistentClass.Identifier,
						secondaryTables,
						propertyHolder, mappings
				);
			}
			else
			{
				int nbrOfJoinColumns = pkColumnsAnn != null ?
						pkColumnsAnn.Length :
						joinColumnsAnn.Length;
				if (nbrOfJoinColumns == 0)
				{
					ejb3JoinColumns = new Ejb3JoinColumn[1];
					ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
							null,
							null,
							persistentClass.Identifier,
							secondaryTables,
							propertyHolder, mappings
					);
				}
				else
				{
					ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
					if (pkColumnsAnn != null)
					{
						for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
						{
							ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
									pkColumnsAnn[colIndex],
									null,
									persistentClass.Identifier,
									secondaryTables,
									propertyHolder, mappings
							);
						}
					}
					else
					{
						for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
						{
							ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
									null,
									joinColumnsAnn[colIndex],
									persistentClass.Identifier,
									secondaryTables,
									propertyHolder, mappings
							);
						}
					}
				}
			}

			foreach (Ejb3JoinColumn joinColumn in ejb3JoinColumns)
			{
				joinColumn.ForceNotNull();
			}
			BindJoinToPersistentClass(join, ejb3JoinColumns);
		}
Exemplo n.º 29
0
		/// <summary>
		/// A non null propertyHolder means than we process the Pk creation without delay
		/// </summary>
		/// <param name="secondaryTable"></param>
		/// <param name="joinTable"></param>
		/// <param name="propertyHolder"></param>
		/// <param name="noDelayInPkColumnCreation"></param>
		/// <returns></returns>
		private Join AddJoin(SecondaryTableAttribute secondaryTable,
			JoinTableAttribute joinTable,
			IPropertyHolder propertyHolder,
			bool noDelayInPkColumnCreation)
		{
			Join join = new Join();
			join.PersistentClass = persistentClass;
			string schema;
			string catalog;
			string table;
			string realTable;

			System.Persistence.UniqueConstraintAttribute[] uniqueConstraintsAnn;
			if (secondaryTable != null)
			{
				schema = secondaryTable.Schema;
				catalog = secondaryTable.Catalog;
				table = secondaryTable.Name;
				realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name
				uniqueConstraintsAnn = secondaryTable.UniqueConstraints;
			}
			else if (joinTable != null)
			{
				schema = joinTable.Schema;
				catalog = joinTable.Catalog;
				table = joinTable.Name;
				realTable = mappings.NamingStrategy.TableName(table); //always an explicit table name
				uniqueConstraintsAnn = joinTable.UniqueConstraints;
			}
			else
			{
				throw new AssertionFailure("Both JoinTable and SecondaryTable are null");
			}

			var uniqueConstraints = new List<string[]>(uniqueConstraintsAnn == null ? 0 : uniqueConstraintsAnn.Length);
			if (uniqueConstraintsAnn != null && uniqueConstraintsAnn.Length != 0)
			{
				foreach (UniqueConstraintAttribute uc in uniqueConstraintsAnn)
				{
					uniqueConstraints.Add(uc.ColumnNames);
				}
			}
			Table tableMapping = TableBinder.FillTable(
					schema,
					catalog,
					realTable,
					table, false, uniqueConstraints, null, null, mappings);
			//no check constraints available on joins
			join.Table = tableMapping;

			//somehow keep joins() for later.
			//Has to do the work later because it needs persistentClass id!
			object joinColumns = null;
			//get the appropriate pk columns
			if (secondaryTable != null)
			{
				joinColumns = secondaryTable.PkJoinColumns;
			}
			else if (joinTable != null)
			{
				joinColumns = joinTable.JoinColumns;
			}
			log.InfoFormat("Adding secondary table to entity {0} -> {1}", persistentClass.EntityName, join.Table.Name);

			TableAttribute matchingTable = FindMatchingComplimentTableAnnotation(join);

			if (matchingTable != null)
			{
				join.IsSequentialSelect = FetchMode.Join != matchingTable.Fetch;
				join.IsInverse = matchingTable.IsInverse;
				join.IsOptional = matchingTable.IsOptional;
				if (!BinderHelper.IsDefault(matchingTable.SqlInsert.Sql))
				{
					join.SetCustomSQLInsert(matchingTable.SqlInsert.Sql.Trim(),
							matchingTable.SqlInsert.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlInsert.Check.ToString().ToLower()));
				}
				if (!BinderHelper.IsDefault(matchingTable.SqlUpdate.Sql))
				{
					join.SetCustomSQLUpdate(matchingTable.SqlUpdate.Sql.Trim(),
							matchingTable.SqlUpdate.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlUpdate.Check.ToString().ToLower())
					);
				}
				if (!BinderHelper.IsDefault(matchingTable.SqlDelete.Sql))
				{
					join.SetCustomSQLDelete(matchingTable.SqlDelete.Sql.Trim(),
							matchingTable.SqlDelete.Callable,
							ExecuteUpdateResultCheckStyle.Parse(matchingTable.SqlDelete.Check.ToString().ToLower())
					);
				}
			}
			else
			{
				//default
				join.IsSequentialSelect = false;
				join.IsInverse = false;
				join.IsOptional = false; //perhaps not quite per-spec, but a Good Thing anyway
			}

			if (noDelayInPkColumnCreation)
			{
				CreatePrimaryColumnsToSecondaryTable(joinColumns, propertyHolder, join);
			}
			else
			{
				secondaryTables.Add(table, join);
				secondaryTableJoins.Add(table, joinColumns);
			}
			return join;
		}
 public static object GetValueAsObject(
     this IPropertyHolder propertyBag,
     string propertyName)
 {
     return(propertyBag.GetValue <object>(propertyName));
 }
Exemplo n.º 31
0
        private void CreatePrimaryColumnsToSecondaryTable(object uncastedColumn, IPropertyHolder propertyHolder, Join join)
        {
            Ejb3JoinColumn[] ejb3JoinColumns;
            PrimaryKeyJoinColumnAttribute[] pkColumnsAnn   = null;
            JoinColumnAttribute[]           joinColumnsAnn = null;
            if (uncastedColumn is PrimaryKeyJoinColumnAttribute[])
            {
                pkColumnsAnn = (PrimaryKeyJoinColumnAttribute[])uncastedColumn;
            }
            if (uncastedColumn is JoinColumnAttribute[])
            {
                joinColumnsAnn = (JoinColumnAttribute[])uncastedColumn;
            }
            if (pkColumnsAnn == null && joinColumnsAnn == null)
            {
                ejb3JoinColumns    = new Ejb3JoinColumn[1];
                ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
                    null,
                    null,
                    persistentClass.Identifier,
                    secondaryTables,
                    propertyHolder, mappings
                    );
            }
            else
            {
                int nbrOfJoinColumns = pkColumnsAnn != null ?
                                       pkColumnsAnn.Length :
                                       joinColumnsAnn.Length;
                if (nbrOfJoinColumns == 0)
                {
                    ejb3JoinColumns    = new Ejb3JoinColumn[1];
                    ejb3JoinColumns[0] = Ejb3JoinColumn.BuildJoinColumn(
                        null,
                        null,
                        persistentClass.Identifier,
                        secondaryTables,
                        propertyHolder, mappings
                        );
                }
                else
                {
                    ejb3JoinColumns = new Ejb3JoinColumn[nbrOfJoinColumns];
                    if (pkColumnsAnn != null)
                    {
                        for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
                        {
                            ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
                                pkColumnsAnn[colIndex],
                                null,
                                persistentClass.Identifier,
                                secondaryTables,
                                propertyHolder, mappings
                                );
                        }
                    }
                    else
                    {
                        for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++)
                        {
                            ejb3JoinColumns[colIndex] = Ejb3JoinColumn.BuildJoinColumn(
                                null,
                                joinColumnsAnn[colIndex],
                                persistentClass.Identifier,
                                secondaryTables,
                                propertyHolder, mappings
                                );
                        }
                    }
                }
            }

            foreach (Ejb3JoinColumn joinColumn in ejb3JoinColumns)
            {
                joinColumn.ForceNotNull();
            }
            BindJoinToPersistentClass(join, ejb3JoinColumns);
        }
Exemplo n.º 32
0
 private static Ejb3Column[] BuildImplicitColumn(IPropertyData inferredData,
                                                 IDictionary<string, Join> secondaryTables,
                                                 IPropertyHolder propertyHolder, Nullability nullability,
                                                 ExtendedMappings mappings)
 {
     Ejb3Column[] columns;
     columns = new Ejb3Column[1];
     Ejb3Column column = new Ejb3Column();
     column.SetImplicit(false);
     //not following the spec but more clean
     if (nullability != Nullability.ForcedNull  && inferredData.ClassOrElement.IsPrimitive
             && !inferredData.Property.GetType().IsArray ) //TODO: IsArray in this way ???
     {
         column.SetNullable(false);
     }
     column.SetLength(DEFAULT_COLUMN_LENGTH);
     column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName);
     column.PropertyHolder = propertyHolder;
     column.SetJoins(secondaryTables);
     column.Mappings = mappings;
     column.Bind();
     columns[0] = column;
     return columns;
 }
 public PropertyCoordinator(IPropertyHolder holder,
                            IPropertyManager manager)
 {
     _holder  = holder;
     _manager = manager;
 }
Exemplo n.º 34
0
 public PropertyCoordinator(IPropertyHolder holder,
     IPropertyManager manager)
 {
     _holder = holder;
     _manager = manager;
 }
Exemplo n.º 35
0
 public abstract void Map(IPropertyHolder src, object dst);
Exemplo n.º 36
0
 public static Lazy <T> GetOrDefaultLazy <T>(IPropertyHolder holder, string name, T defaultValue = default,
                                             StringComparison comparisonType = StringComparison.Ordinal) =>
Exemplo n.º 37
0
 public override void Map(IPropertyHolder src, object dst)
 {
     // TODO
 }
Exemplo n.º 38
0
 public void SetHolder(IPropertyHolder holder)
 {
     this.holder = holder;
 }
Exemplo n.º 39
0
 public static string GetRelativePath(IPropertyHolder propertyHolder, string propertyName)
 {
     throw new System.NotImplementedException();
 }