Starting implementation of Dictionary and Language repositories and factories

This commit is contained in:
Morten@Thinkpad-X220
2012-10-08 13:14:59 -02:00
parent 60508a2327
commit 69f53b7dc5
11 changed files with 292 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Core.Models
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class DictionaryItem : Entity
public class DictionaryItem : Entity, IAggregateRoot
{
private Guid _parentId;
private string _itemKey;

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Core.Models
/// </summary>
[Serializable]
[DataContract(IsReference = true)]
public class Language : Entity
public class Language : Entity, IAggregateRoot
{
private string _isoCode;
private string _cultureName;

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Persistence;
namespace Umbraco.Core.Models.Rdbms
@@ -19,5 +20,8 @@ namespace Umbraco.Core.Models.Rdbms
[Column("key")]
public string Key { get; set; }
[ResultColumn]
public List<LanguageTextDto> LanguageTextDtos { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Core.Persistence.Factories
{
internal class DictionaryItemFactory : IEntityFactory<DictionaryItem, DictionaryDto>
{
#region Implementation of IEntityFactory<DictionaryItem,DictionaryDto>
public DictionaryItem BuildEntity(DictionaryDto dto)
{
throw new System.NotImplementedException();
}
public DictionaryDto BuildDto(DictionaryItem entity)
{
throw new System.NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,22 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Core.Persistence.Factories
{
internal class DictionaryTranslationFactory : IEntityFactory<DictionaryTranslation, LanguageTextDto>
{
#region Implementation of IEntityFactory<DictionaryTranslation,LanguageTextDto>
public DictionaryTranslation BuildEntity(LanguageTextDto dto)
{
throw new System.NotImplementedException();
}
public LanguageTextDto BuildDto(DictionaryTranslation entity)
{
throw new System.NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,22 @@
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
namespace Umbraco.Core.Persistence.Factories
{
internal class LanguageFactory : IEntityFactory<Language, LanguageDto>
{
#region Implementation of IEntityFactory<Language,LanguageDto>
public Language BuildEntity(LanguageDto dto)
{
throw new System.NotImplementedException();
}
public LanguageDto BuildDto(Language entity)
{
throw new System.NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Persistence.Repositories
{
internal class DictionaryRepository : PetaPocoRepositoryBase<int, DictionaryItem>, IDictionaryRepository
{
public DictionaryRepository(IUnitOfWork work) : base(work)
{
}
public DictionaryRepository(IUnitOfWork work, IRepositoryCacheProvider cache) : base(work, cache)
{
}
#region Overrides of RepositoryBase<int,DictionaryItem>
protected override DictionaryItem PerformGet(int id)
{
throw new NotImplementedException();
}
protected override IEnumerable<DictionaryItem> PerformGetAll(params int[] ids)
{
throw new NotImplementedException();
}
protected override IEnumerable<DictionaryItem> PerformGetByQuery(IQuery<DictionaryItem> query)
{
throw new NotImplementedException();
}
#endregion
#region Overrides of PetaPocoRepositoryBase<int,DictionaryItem>
protected override Sql GetBaseQuery(bool isCount)
{
var sql = new Sql();
sql.Select(isCount ? "COUNT(*)" : "*");
sql.From("cmsDictionary");
sql.InnerJoin("cmsLanguageText ON ([cmsDictionary].[id] = [cmsLanguageText].[UniqueId])");
return sql;
}
protected override Sql GetBaseWhereClause(object id)
{
var sql = new Sql();
sql.Where("[cmsDictionary].[id] = @Id", new { Id = id });
return sql;
}
protected override IEnumerable<string> GetDeleteClauses()
{
return new List<string>();
}
/// <summary>
/// Returns the Top Level Parent Guid Id
/// </summary>
protected override Guid NodeObjectTypeId
{
get { return new Guid("41c7638d-f529-4bff-853e-59a0c2fb1bde"); }
}
#endregion
#region Unit of Work Implementation
protected override void PersistNewItem(DictionaryItem entity)
{
throw new NotImplementedException();
}
protected override void PersistUpdatedItem(DictionaryItem entity)
{
throw new NotImplementedException();
}
protected override void PersistDeletedItem(DictionaryItem entity)
{
RecursiveDelete(entity.Key);
Database.Delete<LanguageTextDto>("WHERE UniqueId = @Id", new { Id = entity.Key});
Database.Delete<DictionaryDto>("WHERE id = @Id", new { Id = entity.Key });
}
private void RecursiveDelete(Guid parentId)
{
var list = Database.Fetch<DictionaryDto>("WHERE parent = @ParentId", new {ParentId = parentId});
foreach (var dto in list)
{
RecursiveDelete(dto.Id);
Database.Delete<LanguageTextDto>("WHERE UniqueId = @Id", new { Id = dto.Id });
Database.Delete<DictionaryDto>("WHERE id = @Id", new { Id = dto.Id });
}
}
#endregion
}
}

View File

@@ -0,0 +1,9 @@
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
internal interface IDictionaryRepository : IRepository<int, DictionaryItem>
{
}
}

View File

@@ -0,0 +1,9 @@
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface ILanguageRepository : IRepository<int, Language>
{
}
}

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Persistence.Repositories
{
internal class LanguageRepository : PetaPocoRepositoryBase<int, Language>, ILanguageRepository
{
public LanguageRepository(IUnitOfWork work) : base(work)
{
}
public LanguageRepository(IUnitOfWork work, IRepositoryCacheProvider cache) : base(work, cache)
{
}
#region Overrides of RepositoryBase<int,Language>
protected override Language PerformGet(int id)
{
throw new NotImplementedException();
}
protected override IEnumerable<Language> PerformGetAll(params int[] ids)
{
throw new NotImplementedException();
}
protected override IEnumerable<Language> PerformGetByQuery(IQuery<Language> query)
{
throw new NotImplementedException();
}
#endregion
#region Overrides of PetaPocoRepositoryBase<int,Language>
protected override Sql GetBaseQuery(bool isCount)
{
var sql = new Sql();
sql.Select(isCount ? "COUNT(*)" : "*");
sql.From("cmsLanguageText");
return sql;
}
protected override Sql GetBaseWhereClause(object id)
{
var sql = new Sql();
sql.Where("[cmsLanguageText].[id] = @Id", new { Id = id });
return sql;
}
protected override IEnumerable<string> GetDeleteClauses()
{
//NOTE: There is no constraint between the Language and cmsDictionary/cmsLanguageText tables (?)
var list = new List<string>
{
string.Format("DELETE FROM umbracoLanguage WHERE id = @Id")
};
return list;
}
protected override Guid NodeObjectTypeId
{
get { throw new NotImplementedException(); }
}
#endregion
#region Unit of Work Implementation
protected override void PersistNewItem(Language entity)
{
throw new NotImplementedException();
}
protected override void PersistUpdatedItem(Language entity)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -101,7 +101,10 @@
<Compile Include="Persistence\Factories\ContentFactory.cs" />
<Compile Include="Persistence\Factories\ContentTypeFactory.cs" />
<Compile Include="Persistence\Factories\DataTypeDefinitionFactory.cs" />
<Compile Include="Persistence\Factories\DictionaryItemFactory.cs" />
<Compile Include="Persistence\Factories\DictionaryTranslationFactory.cs" />
<Compile Include="Persistence\Factories\IEntityFactory.cs" />
<Compile Include="Persistence\Factories\LanguageFactory.cs" />
<Compile Include="Persistence\Factories\PropertyFactory.cs" />
<Compile Include="Persistence\Factories\PropertyGroupFactory.cs" />
<Compile Include="Persistence\Mappers\ModelDtoMapper.cs" />
@@ -112,12 +115,16 @@
<Compile Include="Persistence\Repositories\ContentRepository.cs" />
<Compile Include="Persistence\Repositories\ContentTypeRepository.cs" />
<Compile Include="Persistence\Repositories\DataTypeDefinitionRepository.cs" />
<Compile Include="Persistence\Repositories\DictionaryRepository.cs" />
<Compile Include="Persistence\Repositories\IContentRepository.cs" />
<Compile Include="Persistence\Repositories\IContentTypeRepository.cs" />
<Compile Include="Persistence\Repositories\IDataTypeDefinitionRepository.cs" />
<Compile Include="Persistence\Repositories\IDictionaryRepository.cs" />
<Compile Include="Persistence\Repositories\ILanguageRepository.cs" />
<Compile Include="Persistence\Repositories\IMacroRepository.cs" />
<Compile Include="Persistence\Repositories\IRepository.cs" />
<Compile Include="Persistence\Relators\TabPropertyTypeRelator.cs" />
<Compile Include="Persistence\Repositories\LanguageRepository.cs" />
<Compile Include="Persistence\Repositories\MacroRepository.cs" />
<Compile Include="Persistence\Repositories\PetaPocoRepositoryBase.cs" />
<Compile Include="Persistence\Repositories\RepositoryBase.cs" />