public Contract(Plan plan, string customerName, string type) { plans = new IESI.HashedSet<Plan>(); if (plan != null) { plans.Add(plan); plan.Contracts.Add(this); } this.customerName = customerName; this.type = type; variations = new List<ContractVariation>(); subcontracts = new IESI.HashedSet<Contract>(); parties = new IESI.HashedSet<Party>(); infos = new IESI.HashedSet<Info>(); }
protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) { this.factory = factory; this.cache = cache; isLazyPropertiesCacheable = persistentClass.IsLazyPropertiesCacheable; cacheEntryStructure = factory.Settings.IsStructuredCacheEntriesEnabled ? (ICacheEntryStructure)new StructuredCacheEntry(this) : (ICacheEntryStructure)new UnstructuredCacheEntry(); entityMetamodel = new EntityMetamodel(persistentClass, factory); if (persistentClass.HasPocoRepresentation) { //TODO: this is currently specific to pojos, but need to be available for all entity-modes foreach (Subclass subclass in persistentClass.SubclassIterator) { entityNameBySubclass[subclass.MappedClass] = subclass.EntityName; } } batchSize = persistentClass.BatchSize.HasValue ? persistentClass.BatchSize.Value : factory.Settings.DefaultBatchFetchSize; hasSubselectLoadableCollections = persistentClass.HasSubselectLoadableCollections; propertyMapping = new BasicEntityPropertyMapping(this); #region IDENTIFIER identifierColumnSpan = persistentClass.Identifier.ColumnSpan; rootTableKeyColumnNames = new string[identifierColumnSpan]; identifierAliases = new string[identifierColumnSpan]; rowIdName = persistentClass.RootTable.RowId; loaderName = persistentClass.LoaderName; // TODO NH: Not safe cast to Column int i = 0; foreach (Column col in persistentClass.Identifier.ColumnIterator) { rootTableKeyColumnNames[i] = col.GetQuotedName(factory.Dialect); identifierAliases[i] = col.GetAlias(factory.Dialect, persistentClass.RootTable); i++; } #endregion #region VERSION if (persistentClass.IsVersioned) { foreach (Column col in persistentClass.Version.ColumnIterator) { versionColumnName = col.GetQuotedName(factory.Dialect); break; //only happens once } } else { versionColumnName = null; } #endregion #region WHERE STRING sqlWhereString = !string.IsNullOrEmpty(persistentClass.Where) ? "( " + persistentClass.Where + ") " : null; sqlWhereStringTemplate = sqlWhereString == null ? null : Template.RenderWhereStringTemplate(sqlWhereString, factory.Dialect, factory.SQLFunctionRegistry); #endregion #region PROPERTIES // NH: see consistence with the implementation on EntityMetamodel where we are disabling lazy-properties for no lazy entities bool lazyAvailable = IsInstrumented(EntityMode.Poco) && entityMetamodel.IsLazy; int hydrateSpan = entityMetamodel.PropertySpan; propertyColumnSpans = new int[hydrateSpan]; propertySubclassNames = new string[hydrateSpan]; propertyColumnAliases = new string[hydrateSpan][]; propertyColumnNames = new string[hydrateSpan][]; propertyColumnFormulaTemplates = new string[hydrateSpan][]; propertyUniqueness = new bool[hydrateSpan]; propertySelectable = new bool[hydrateSpan]; propertyColumnUpdateable = new bool[hydrateSpan][]; propertyColumnInsertable = new bool[hydrateSpan][]; ISet thisClassProperties = new HashedSet(); lazyProperties = new IESI.HashedSet<string>(); List<string> lazyNames = new List<string>(); List<int> lazyNumbers = new List<int>(); List<IType> lazyTypes = new List<IType>(); List<string[]> lazyColAliases = new List<string[]>(); i = 0; bool foundFormula = false; foreach (Property prop in persistentClass.PropertyClosureIterator) { thisClassProperties.Add(prop); int span = prop.ColumnSpan; propertyColumnSpans[i] = span; propertySubclassNames[i] = prop.PersistentClass.EntityName; string[] colNames = new string[span]; string[] colAliases = new string[span]; string[] templates = new string[span]; int k = 0; foreach (ISelectable thing in prop.ColumnIterator) { colAliases[k] = thing.GetAlias(factory.Dialect, prop.Value.Table); if (thing.IsFormula) { foundFormula = true; templates[k] = thing.GetTemplate(factory.Dialect, factory.SQLFunctionRegistry); } else { colNames[k] = thing.GetTemplate(factory.Dialect, factory.SQLFunctionRegistry); } k++; } propertyColumnNames[i] = colNames; propertyColumnFormulaTemplates[i] = templates; propertyColumnAliases[i] = colAliases; if (lazyAvailable && prop.IsLazy) { lazyProperties.Add(prop.Name); lazyNames.Add(prop.Name); lazyNumbers.Add(i); lazyTypes.Add(prop.Value.Type); lazyColAliases.Add(colAliases); } propertyColumnUpdateable[i] = prop.Value.ColumnUpdateability; propertyColumnInsertable[i] = prop.Value.ColumnInsertability; propertySelectable[i] = prop.IsSelectable; propertyUniqueness[i] = prop.Value.IsAlternateUniqueKey; i++; } hasFormulaProperties = foundFormula; lazyPropertyColumnAliases = lazyColAliases.ToArray(); lazyPropertyNames = lazyNames.ToArray(); lazyPropertyNumbers = lazyNumbers.ToArray(); lazyPropertyTypes = lazyTypes.ToArray(); #endregion #region SUBCLASS PROPERTY CLOSURE List<string> columns = new List<string>(); List<bool> columnsLazy = new List<bool>(); List<string> aliases = new List<string>(); List<string> formulas = new List<string>(); List<string> formulaAliases = new List<string>(); List<string> formulaTemplates = new List<string>(); List<bool> formulasLazy = new List<bool>(); List<IType> types = new List<IType>(); List<string> names = new List<string>(); List<string> classes = new List<string>(); List<string[]> templates2 = new List<string[]>(); List<string[]> propColumns = new List<string[]>(); List<FetchMode> joinedFetchesList = new List<FetchMode>(); List<CascadeStyle> cascades = new List<CascadeStyle>(); List<bool> definedBySubclass = new List<bool>(); List<int[]> propColumnNumbers = new List<int[]>(); List<int[]> propFormulaNumbers = new List<int[]>(); List<bool> columnSelectables = new List<bool>(); List<bool> propNullables = new List<bool>(); foreach (Property prop in persistentClass.SubclassPropertyClosureIterator) { names.Add(prop.Name); classes.Add(prop.PersistentClass.EntityName); bool isDefinedBySubclass = !thisClassProperties.Contains(prop); definedBySubclass.Add(isDefinedBySubclass); propNullables.Add(prop.IsOptional || isDefinedBySubclass); //TODO: is this completely correct? types.Add(prop.Type); string[] cols = new string[prop.ColumnSpan]; string[] forms = new string[prop.ColumnSpan]; int[] colnos = new int[prop.ColumnSpan]; int[] formnos = new int[prop.ColumnSpan]; int l = 0; bool lazy = prop.IsLazy && lazyAvailable; foreach (ISelectable thing in prop.ColumnIterator) { if (thing.IsFormula) { string template = thing.GetTemplate(factory.Dialect, factory.SQLFunctionRegistry); formnos[l] = formulaTemplates.Count; colnos[l] = -1; formulaTemplates.Add(template); forms[l] = template; formulas.Add(thing.GetText(factory.Dialect)); formulaAliases.Add(thing.GetAlias(factory.Dialect)); formulasLazy.Add(lazy); } else { string colName = thing.GetTemplate(factory.Dialect, factory.SQLFunctionRegistry); colnos[l] = columns.Count; //before add :-) formnos[l] = -1; columns.Add(colName); cols[l] = colName; aliases.Add(thing.GetAlias(factory.Dialect, prop.Value.Table)); columnsLazy.Add(lazy); columnSelectables.Add(prop.IsSelectable); } l++; } propColumns.Add(cols); templates2.Add(forms); propColumnNumbers.Add(colnos); propFormulaNumbers.Add(formnos); joinedFetchesList.Add(prop.Value.FetchMode); cascades.Add(prop.CascadeStyle); } subclassColumnClosure = columns.ToArray(); subclassColumnAliasClosure = aliases.ToArray(); subclassColumnLazyClosure = columnsLazy.ToArray(); subclassColumnSelectableClosure = columnSelectables.ToArray(); subclassFormulaClosure = formulas.ToArray(); subclassFormulaTemplateClosure = formulaTemplates.ToArray(); subclassFormulaAliasClosure = formulaAliases.ToArray(); subclassFormulaLazyClosure = formulasLazy.ToArray(); subclassPropertyNameClosure = names.ToArray(); subclassPropertySubclassNameClosure = classes.ToArray(); subclassPropertyTypeClosure = types.ToArray(); subclassPropertyNullabilityClosure = propNullables.ToArray(); subclassPropertyFormulaTemplateClosure = templates2.ToArray(); subclassPropertyColumnNameClosure = propColumns.ToArray(); subclassPropertyColumnNumberClosure = propColumnNumbers.ToArray(); subclassPropertyFormulaNumberClosure = propFormulaNumbers.ToArray(); subclassPropertyCascadeStyleClosure = cascades.ToArray(); subclassPropertyFetchModeClosure = joinedFetchesList.ToArray(); propertyDefinedOnSubclass = definedBySubclass.ToArray(); #endregion // Handle any filters applied to the class level filterHelper = new FilterHelper(persistentClass.FilterMap, factory.Dialect, factory.SQLFunctionRegistry); temporaryIdTableName = persistentClass.TemporaryIdTableName; temporaryIdTableDDL = persistentClass.TemporaryIdTableDDL; }