Permalink
Browse files

Cleanup code of UnionSubclassEntityPersister

  • Loading branch information...
1 parent 16f53ed commit c5839fdcbcbbb11f3d4d7c2a5e6e6ef17064d4ee @hazzik hazzik committed Oct 13, 2012
@@ -35,17 +35,17 @@ public override sealed string ToString()
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
- string entityName = criteriaQuery.GetEntityName(criteria, propertyName);
- string actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
- string sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName);
+ var entityName = criteriaQuery.GetEntityName(criteria, propertyName);
+ var actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
+ var sqlAlias = criteriaQuery.GetSQLAlias(criteria, propertyName);
- ISessionFactoryImplementor factory = criteriaQuery.Factory;
- IQueryableCollection collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory);
+ var factory = criteriaQuery.Factory;
+ var collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory);
- string[] collectionKeys = collectionPersister.KeyColumnNames;
- string[] ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames;
+ var collectionKeys = collectionPersister.KeyColumnNames;
+ var ownerKeys = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames;
- StringBuilder innerSelect = new StringBuilder();
+ var innerSelect = new StringBuilder();
innerSelect.Append("(select 1 from ")
.Append(collectionPersister.TableName)
.Append(" where ")
@@ -60,15 +60,15 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
innerSelect.Append(")");
- return new SqlString(new string[] {ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString()});
+ return new SqlString(new object[] {ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString()});
}
protected IQueryableCollection GetQueryableCollection(string entityName, string actualPropertyName,
- ISessionFactoryImplementor factory)
+ ISessionFactoryImplementor factory)
{
- IPropertyMapping ownerMapping = (IPropertyMapping) factory.GetEntityPersister(entityName);
- IType type = ownerMapping.ToType(actualPropertyName);
+ var ownerMapping = (IPropertyMapping) factory.GetEntityPersister(entityName);
+ var type = ownerMapping.ToType(actualPropertyName);
if (!type.IsCollectionType)
{
throw new MappingException(
@@ -35,9 +35,7 @@ public class UnionSubclassEntityPersister : AbstractEntityPersister
// TABLE
- tableName =
- persistentClass.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName,
- factory.Settings.DefaultSchemaName);
+ tableName = persistentClass.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
#region Custom SQL
@@ -125,28 +123,27 @@ public class UnionSubclassEntityPersister : AbstractEntityPersister
if (IsMultiTable)
{
- int idColumnSpan = IdentifierColumnSpan;
- List<string> tableNames = new List<string>();
- List<string[]> keyColumns = new List<string[]>();
+ var tableNames = new List<string>();
+ var keyColumns = new List<string[]>();
if (!IsAbstract)
{
tableNames.Add(tableName);
keyColumns.Add(IdentifierColumnNames);
}
- foreach (Table tab in persistentClass.SubclassTableClosureIterator)
+ foreach (var tab in persistentClass.SubclassTableClosureIterator)
{
if (!tab.IsAbstractUnionTable)
{
string _tableName =
tab.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
tableNames.Add(_tableName);
- List<string> key = new List<string>(idColumnSpan);
- foreach (Column column in tab.PrimaryKey.ColumnIterator)
- key.Add(column.GetQuotedName(factory.Dialect));
+ var names = tab.PrimaryKey.ColumnIterator
+ .Select(column => column.GetQuotedName(factory.Dialect))
+ .ToArray();
- keyColumns.Add(key.ToArray());
- }
+ keyColumns.Add(names);
+ }
}
constraintOrderedTableNames = tableNames.ToArray();
@@ -322,22 +319,20 @@ protected string GenerateSubquery(PersistentClass model, IMapping mapping)
}
}
- StringBuilder buf = new StringBuilder().Append("( ");
- IEnumerable<PersistentClass> siter =
- new JoinedEnumerable<PersistentClass>(new SingletonEnumerable<PersistentClass>(model),
- new SafetyEnumerable<PersistentClass>(model.SubclassIterator));
+ var buf = new StringBuilder("( ");
- foreach (PersistentClass clazz in siter)
+ var persistentClasses = PersistentClasses(model);
+ foreach (var clazz in persistentClasses)
{
- Table table = clazz.Table;
+ var table = clazz.Table;
if (!table.IsAbstractUnionTable)
{
buf.Append("select ");
- foreach (Column col in columns)
+ foreach (var col in columns)
{
if (!table.ContainsColumn(col))
{
- SqlType sqlType = col.GetSqlTypeCode(mapping);
+ var sqlType = col.GetSqlTypeCode(mapping);
buf.Append(dialect.GetSelectClauseNullString(sqlType)).Append(" as ");
}
buf.Append(col.Name);
@@ -360,6 +355,13 @@ protected string GenerateSubquery(PersistentClass model, IMapping mapping)
return buf.Append(" )").ToString();
}
+ private static IEnumerable<PersistentClass> PersistentClasses(PersistentClass model)
+ {
+ yield return model;
+ foreach (var subclass in model.SubclassIterator)
+ yield return subclass;
+ }
+
protected override string[] GetSubclassTableKeyColumns(int j)
{
if (j != 0)

0 comments on commit c5839fd

Please sign in to comment.