📄 abstractentitypersister.cs
字号:
public virtual bool IsVersioned
{
get { return entityMetamodel.IsVersioned; }
}
public virtual bool IsIdentifierAssignedByInsert
{
get { return entityMetamodel.IdentifierProperty.IsIdentifierAssignedByInsert; }
}
public virtual bool IsMutable
{
get { return entityMetamodel.IsMutable; }
}
public virtual bool IsAbstract
{
get { return entityMetamodel.IsAbstract; }
}
public virtual IIdentifierGenerator IdentifierGenerator
{
get { return entityMetamodel.IdentifierProperty.IdentifierGenerator; }
}
public virtual string RootEntityName
{
get { return entityMetamodel.RootName; }
}
public virtual IClassMetadata ClassMetadata
{
get { return this; }
}
public virtual string MappedSuperclass
{
get { return entityMetamodel.Superclass; }
}
public virtual bool IsExplicitPolymorphism
{
get { return entityMetamodel.IsExplicitPolymorphism; }
}
public string[] KeyColumnNames
{
get { return IdentifierColumnNames; }
}
public string Name
{
get { return EntityName; }
}
public bool IsCollection
{
get { return false; }
}
public IType Type
{
get { return entityMetamodel.EntityType; }
}
public bool IsSelectBeforeUpdateRequired
{
get { return entityMetamodel.IsSelectBeforeUpdate; }
}
public bool IsVersionPropertyGenerated
{
get { return IsVersioned && PropertyUpdateGenerationInclusions[VersionProperty] != ValueInclusion.None; }
}
public bool VersionPropertyInsertable
{
get { return IsVersioned && PropertyInsertability[VersionProperty]; }
}
public virtual string[] PropertyNames
{
get { return entityMetamodel.PropertyNames; }
}
public virtual IType[] PropertyTypes
{
get { return entityMetamodel.PropertyTypes; }
}
public bool[] PropertyLaziness
{
get { return entityMetamodel.PropertyLaziness; }
}
public virtual bool[] PropertyCheckability
{
get { return entityMetamodel.PropertyCheckability; }
}
public bool[] NonLazyPropertyUpdateability
{
get { return entityMetamodel.NonlazyPropertyUpdateability; }
}
public virtual bool[] PropertyInsertability
{
get { return entityMetamodel.PropertyInsertability; }
}
public ValueInclusion[] PropertyInsertGenerationInclusions
{
get { return entityMetamodel.PropertyInsertGenerationInclusions; }
}
public ValueInclusion[] PropertyUpdateGenerationInclusions
{
get { return entityMetamodel.PropertyUpdateGenerationInclusions; }
}
public virtual bool[] PropertyNullability
{
get { return entityMetamodel.PropertyNullability; }
}
public virtual bool[] PropertyVersionability
{
get { return entityMetamodel.PropertyVersionability; }
}
public virtual CascadeStyle[] PropertyCascadeStyles
{
get { return entityMetamodel.CascadeStyles; }
}
public virtual bool IsMultiTable
{
get { return false; }
}
public string TemporaryIdTableName
{
get { return temporaryIdTableName; }
}
public string TemporaryIdTableDDL
{
get { return temporaryIdTableDDL; }
}
protected int PropertySpan
{
get { return entityMetamodel.PropertySpan; }
}
public virtual string IdentifierPropertyName
{
get { return entityMetamodel.IdentifierProperty.Name; }
}
public virtual IType IdentifierType
{
get { return entityMetamodel.IdentifierProperty.Type; }
}
public int[] NaturalIdentifierProperties
{
get { return entityMetamodel.NaturalIdentifierProperties; }
}
public abstract string[][] ContraintOrderedTableKeyColumnClosure { get;}
public abstract IType DiscriminatorType { get;}
public abstract string[] ConstraintOrderedTableNameClosure { get;}
public abstract string DiscriminatorSQLValue { get;}
public abstract object DiscriminatorValue { get;}
public abstract string[] PropertySpaces { get;}
protected virtual void AddDiscriminatorToInsert(SqlInsertBuilder insert) { }
protected virtual void AddDiscriminatorToSelect(SelectFragment select, string name, string suffix) { }
public abstract string GetSubclassTableName(int j);
protected abstract string[] GetSubclassTableKeyColumns(int j);
protected abstract bool IsClassOrSuperclassTable(int j);
protected abstract int SubclassTableSpan { get; }
protected abstract int TableSpan { get; }
protected abstract bool IsTableCascadeDeleteEnabled(int j);
protected abstract string GetTableName(int table);
protected abstract string[] GetKeyColumns(int table);
protected abstract bool IsPropertyOfTable(int property, int table);
protected abstract int GetSubclassPropertyTableNumber(int i);
public abstract string FilterFragment(string alias);
protected internal virtual string DiscriminatorAlias
{
get { return Discriminator_Alias; }
}
protected virtual bool IsInverseTable(int j)
{
return false;
}
protected virtual bool IsNullableTable(int j)
{
return false;
}
protected virtual bool IsNullableSubclassTable(int j)
{
return false;
}
protected virtual bool IsInverseSubclassTable(int j)
{
return false;
}
public virtual bool IsSubclassEntityName(string entityName)
{
return entityMetamodel.SubclassEntityNames.Contains(entityName);
}
protected bool[] TableHasColumns
{
get { return tableHasColumns; }
}
protected bool IsInsertCallable(int j)
{
return insertCallable[j];
}
protected bool IsUpdateCallable(int j)
{
return updateCallable[j];
}
protected bool IsDeleteCallable(int j)
{
return deleteCallable[j];
}
protected virtual bool IsSubclassPropertyDeferred(string propertyName, string entityName)
{
return false;
}
protected virtual bool IsSubclassTableSequentialSelect(int table)
{
return false;
}
public virtual bool HasSequentialSelect
{
get { return false; }
}
/// <summary>
/// Decide which tables need to be updated
/// </summary>
/// <param name="dirtyProperties">The indices of all the entity properties considered dirty.</param>
/// <param name="hasDirtyCollection">Whether any collections owned by the entity which were considered dirty. </param>
/// <returns> Array of booleans indicating which table require updating. </returns>
/// <remarks>
/// The return here is an array of boolean values with each index corresponding
/// to a given table in the scope of this persister.
/// </remarks>
private bool[] GetTableUpdateNeeded(int[] dirtyProperties, bool hasDirtyCollection)
{
if (dirtyProperties == null)
{
return TableHasColumns; //for object that came in via update()
}
else
{
bool[] updateability = PropertyUpdateability;
int[] propertyTableNumbers = PropertyTableNumbers;
bool[] tableUpdateNeeded = new bool[TableSpan];
for (int i = 0; i < dirtyProperties.Length; i++)
{
int property = dirtyProperties[i];
int table = propertyTableNumbers[property];
tableUpdateNeeded[table] = tableUpdateNeeded[table] ||
(GetPropertyColumnSpan(property) > 0 && updateability[property]);
}
if (IsVersioned)
{
tableUpdateNeeded[0] = tableUpdateNeeded[0] ||
Versioning.IsVersionIncrementRequired(dirtyProperties, hasDirtyCollection,
PropertyVersionability);
}
return tableUpdateNeeded;
}
}
public virtual bool HasRowId
{
get { return rowIdName != null; }
}
protected internal virtual SqlString GenerateLazySelectString()
{
if (!entityMetamodel.HasLazyProperties)
return null;
HashedSet<int> tableNumbers = new HashedSet<int>();
List<int> columnNumbers = new List<int>();
List<int> formulaNumbers = new List<int>();
for (int i = 0; i < lazyPropertyNames.Length; i++)
{
// all this only really needs to consider properties
// of this class, not its subclasses, but since we
// are reusing code used for sequential selects, we
// use the subclass closure
int propertyNumber = GetSubclassPropertyIndex(lazyPropertyNames[i]);
int tableNumber = GetSubclassPropertyTableNumber(propertyNumber);
tableNumbers.Add(tableNumber);
int[] colNumbers = subclassPropertyColumnNumberClosure[propertyNumber];
for (int j = 0; j < colNumbers.Length; j++)
{
if (colNumbers[j] != -1)
{
columnNumbers.Add(colNumbers[j]);
}
}
int[] formNumbers = subclassPropertyFormulaNumberClosure[propertyNumber];
for (int j = 0; j < formNumbers.Length; j++)
{
if (formNumbers[j] != -1)
{
formulaNumbers.Add(formNumbers[j]);
}
}
}
if (columnNumbers.Count == 0 && formulaNumbers.Count == 0)
{
// only one-to-one is lazy fetched
return null;
}
return RenderSelect(ArrayHelper.ToIntArray(tableNumbers), columnNumbers.ToArray(), formulaNumbers.ToArray());
}
public virtual object InitializeLazyProperty(string fieldName, object entity, ISessionImplementor session)
{
object id = session.GetContextEntityIdentifier(entity);
EntityEntry entry = session.PersistenceContext.GetEntry(entity);
if (entry == null)
throw new HibernateException("entity is not associated with the session: " + id);
if (log.IsDebugEnabled)
{
log.Debug(
string.Format("initializing lazy properties of: {0}, field access: {1}",
MessageHelper.InfoString(this, id, Factory), fieldName));
}
if (HasCache)
{
CacheKey cacheKey = new CacheKey(id, IdentifierType, EntityName, session.EntityMode, Factory);
object ce = Cache.Get(cacheKey, session.Timestamp);
if (ce != null)
{
CacheEntry cacheEntry = (CacheEntry)CacheEntryStructure.Destructure(ce, factory);
if (!cacheEntry.AreLazyPropertiesUnfetched)
{
//note early exit here:
return InitializeLazyPropertiesFromCache(fieldName, entity, session, entry, cacheEntry);
}
}
}
return InitializeLazyPropertiesFromDatastore(fieldName, entity, session, id, entry);
}
private object InitializeLazyPropertiesFromDatastore(string fieldName, object entity, ISessionImplementor session, object id, EntityEntry entry)
{
if (!HasLazyProperties)
throw new AssertionFailure("no lazy properties");
log.Debug("initializing lazy properties from datastore");
try
{
object result = null;
IDbCommand ps = null;
IDataReader rs = null;
try
{
SqlString lazySelect = SQLLazySelectString;
if (lazySelect != null)
{
// null sql means that the only lazy properties
// are shared PK one-to-one associations which are
// handled differently in the Type#nullSafeGet code...
ps = session.Batcher.PrepareCommand(CommandType.Text, lazySelect, IdentifierType.SqlTypes(Factory));
IdentifierType.NullSafeSet(ps, id, 1, session);
rs = session.Batcher.ExecuteReader(ps);
rs.Read();
}
object[] snapshot = entry.LoadedState;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -