📄 abstractentitypersister.cs
字号:
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;
}
protected abstract int[] SubclassColumnTableNumberClosure { get; }
protected abstract int[] SubclassFormulaTableNumberClosure { get; }
protected internal abstract int[] PropertyTableNumbersInSelect { get;}
protected internal abstract int[] PropertyTableNumbers { get;}
public virtual string DiscriminatorColumnName
{
get { return Discriminator_Alias; }
}
protected virtual string DiscriminatorFormulaTemplate
{
get { return null; }
}
public string[] RootTableKeyColumnNames
{
get { return rootTableKeyColumnNames; }
}
protected internal SqlCommandInfo[] SQLUpdateByRowIdStrings
{
get
{
if (sqlUpdateByRowIdString == null)
throw new AssertionFailure("no update by row id");
SqlCommandInfo[] result = new SqlCommandInfo[TableSpan + 1];
result[0] = sqlUpdateByRowIdString;
Array.Copy(sqlUpdateStrings, 0, result, 1, TableSpan);
return result;
}
}
protected internal SqlCommandInfo[] SQLLazyUpdateByRowIdStrings
{
get
{
if (sqlLazyUpdateByRowIdString == null)
throw new AssertionFailure("no update by row id");
SqlCommandInfo[] result = new SqlCommandInfo[TableSpan];
result[0] = sqlLazyUpdateByRowIdString;
for (int i = 1; i < TableSpan; i++)
result[i] = sqlLazyUpdateStrings[i];
return result;
}
}
protected SqlString SQLSnapshotSelectString
{
get { return sqlSnapshotSelectString; }
}
protected SqlString SQLLazySelectString
{
get { return sqlLazySelectString; }
}
/// <summary>
/// The queries that delete rows by id (and version)
/// </summary>
protected SqlCommandInfo[] SqlDeleteStrings
{
get { return sqlDeleteStrings; }
}
/// <summary>
/// The queries that insert rows with a given id
/// </summary>
protected SqlCommandInfo[] SqlInsertStrings
{
get { return sqlInsertStrings; }
}
/// <summary>
/// The queries that update rows by id (and version)
/// </summary>
protected SqlCommandInfo[] SqlUpdateStrings
{
get { return sqlUpdateStrings; }
}
protected internal SqlCommandInfo[] SQLLazyUpdateStrings
{
get { return sqlLazyUpdateStrings; }
}
/// <summary>
/// The query that inserts a row, letting the database generate an id
/// </summary>
/// <returns> The IDENTITY-based insertion query. </returns>
protected internal SqlCommandInfo SQLIdentityInsertString
{
get { return sqlIdentityInsertString; }
}
protected SqlString VersionSelectString
{
get { return sqlVersionSelectString; }
}
public bool IsBatchable
{
get
{
return
OptimisticLockMode == Versioning.OptimisticLock.None
|| (!IsVersioned && OptimisticLockMode == Versioning.OptimisticLock.Version);
//|| Factory.Settings.IsJdbcBatchVersionedData();
}
}
public virtual string[] QuerySpaces
{
get { return PropertySpaces; }
}
protected internal ISet<string> LazyProperties
{
get { return lazyProperties; }
}
public bool IsBatchLoadable
{
get { return batchSize > 1; }
}
public virtual string[] IdentifierColumnNames
{
get { return rootTableKeyColumnNames; }
}
protected int IdentifierColumnSpan
{
get { return identifierColumnSpan; }
}
public virtual string VersionColumnName
{
get { return versionColumnName; }
}
protected internal string VersionedTableName
{
get { return GetTableName(0); }
}
protected internal bool[] SubclassColumnLazyiness
{
get { return subclassColumnLazyClosure; }
}
protected internal bool[] SubclassFormulaLazyiness
{
get { return subclassFormulaLazyClosure; }
}
/// <summary>
/// We can't immediately add to the cache if we have formulas
/// which must be evaluated, or if we have the possibility of
/// two concurrent updates to the same item being merged on
/// the database. This can happen if (a) the item is not
/// versioned and either (b) we have dynamic update enabled
/// or (c) we have multiple tables holding the state of the
/// item.
/// </summary>
public bool IsCacheInvalidationRequired
{
get { return HasFormulaProperties || (!IsVersioned && (entityMetamodel.IsDynamicUpdate || TableSpan > 1)); }
}
public bool IsLazyPropertiesCacheable
{
get { return isLazyPropertiesCacheable; }
}
public virtual string RootTableName
{
get { return GetSubclassTableName(0); }
}
public virtual string[] RootTableIdentifierColumnNames
{
get { return RootTableKeyColumnNames; }
}
protected internal string[] PropertySubclassNames
{
get { return propertySubclassNames; }
}
protected string[][] SubclassPropertyFormulaTemplateClosure
{
get { return subclassPropertyFormulaTemplateClosure; }
}
protected IType[] SubclassPropertyTypeClosure
{
get { return subclassPropertyTypeClosure; }
}
protected string[][] SubclassPropertyColumnNameClosure
{
get { return subclassPropertyColumnNameClosure; }
}
protected string[] SubclassPropertyNameClosure
{
get { return subclassPropertyNameClosure; }
}
protected string[] SubclassPropertySubclassNameClosure
{
get { return subclassPropertySubclassNameClosure; }
}
protected string[] SubclassColumnClosure
{
get { return subclassColumnClosure; }
}
protected string[] SubclassColumnAliasClosure
{
get { return subclassColumnAliasClosure; }
}
protected string[] SubclassFormulaClosure
{
get { return subclassFormulaClosure; }
}
protected string[] SubclassFormulaTemplateClosure
{
get { return subclassFormulaTemplateClosure; }
}
protected string[] SubclassFormulaAliasClosure
{
get { return subclassFormulaAliasClosure; }
}
public string IdentitySelectString
{
get
{
if (identitySelectString == null)
identitySelectString =
Factory.Dialect.GetIdentitySelectString(GetTableName(0), GetKeyColumns(0)[0],
IdentifierType.SqlTypes(Factory)[0].DbType);
return identitySelectString;
}
}
private string RootAlias
{
get { return StringHelper.GenerateAlias(EntityName); }
}
public ISessionFactoryImplementor Factory
{
get { return factory; }
}
public EntityMetamodel EntityMetamodel
{
get { return entityMetamodel; }
}
public ICacheConcurrencyStrategy Cache
{
get { return cache; }
}
public ICacheEntryStructure CacheEntryStructure
{
get { return cacheEntryStructure; }
}
public IComparer VersionComparator
{
get { return IsVersioned ? VersionType.Comparator : null; }
}
public string EntityName
{
get { return entityMetamodel.Name; }
}
public EntityType EntityType
{
get { return entityMetamodel.EntityType; }
}
public virtual bool IsPolymorphic
{
get { return entityMetamodel.IsPolymorphic; }
}
public virtual bool IsInherited
{
get { return entityMetamodel.IsInherited; }
}
public virtual IVersionType VersionType
{
get { return LocateVersionType(); }
}
public virtual int VersionProperty
{
get { return entityMetamodel.VersionPropertyIndex; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -