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); }
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 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")); }
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(); }
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()); }
// 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); }
// 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)); }
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)); }
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 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; }
/// <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 string GetRelativePath(IPropertyHolder propertyHolder, string propertyName) { throw new System.NotImplementedException(); }
//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)); }
public UserManager(IPropertyHolder properties, ILocker locker) { this.properties = properties.ThrowIfNull(nameof(properties)); this.locker = locker.ThrowIfNull(nameof(locker)); }
public void SetHolder(IPropertyHolder holder) { this.holder = holder; }
//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); }
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); }
/// <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)); }
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; }
public abstract void Map(IPropertyHolder src, object dst);
public static Lazy <T> GetOrDefaultLazy <T>(IPropertyHolder holder, string name, T defaultValue = default, StringComparison comparisonType = StringComparison.Ordinal) =>
public override void Map(IPropertyHolder src, object dst) { // TODO }