init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
215
Framework/Entities/Generic/EntityDBHelper.cs
Normal file
215
Framework/Entities/Generic/EntityDBHelper.cs
Normal file
|
@ -0,0 +1,215 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Kreta.Framework.Collections.Generic;
|
||||
|
||||
namespace Kreta.Framework.Entities.Generic
|
||||
{
|
||||
public abstract class EntityDBHelper<EntityType> : IEntityDBHelper<EntityType> //, IEntityDBHelper
|
||||
where EntityType : Kreta.Framework.Entities.Entity
|
||||
{
|
||||
protected abstract EntityType CreateEntityInstance();
|
||||
|
||||
#region IEntityDBHelper<EntityType> Members
|
||||
|
||||
public abstract string EmptyQueryCommandText
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract string DynamicQueryCommandText
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract IDictionary<string, string> DynamicColumns
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public SDA.DataProvider.SDACommand CreateEmptyQueryCommand()
|
||||
{
|
||||
return DAUtil.CreateCommand(EmptyQueryCommandText);
|
||||
}
|
||||
|
||||
public SDA.DataProvider.SDACommand CreateDynamicQueryCommand(ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
if (columns == null)
|
||||
{
|
||||
columns = new List<string>();
|
||||
}
|
||||
|
||||
var columnText = "";
|
||||
foreach (var column in DynamicColumns.Where(dc => (columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains(dc.Key))))
|
||||
{
|
||||
columnText += column.Value + ",";
|
||||
}
|
||||
|
||||
var queryCommandText = DynamicQueryCommandText.Replace("{COLUMNS}", columnText);
|
||||
return DAUtil.CreateCommand(queryCommandText);
|
||||
}
|
||||
|
||||
public abstract void LoadEntityFields(EntityType entity, SDA.DataProvider.SDADataReader reader, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
public abstract void LoadEntityFields(EntityType entity, SDA.DataProvider.SDADataReader reader);
|
||||
|
||||
public void LoadFromReader(EntityType entity, SDA.DataProvider.SDADataReader reader)
|
||||
{
|
||||
entity.ID = ((int)reader.GetDecimal(0));
|
||||
|
||||
LoadEntityFields(entity, reader);
|
||||
|
||||
int index = reader.FieldCount - 6;
|
||||
entity.Torolt = reader[index] != DBNull.Value && reader.GetBoolean(index);
|
||||
index++;
|
||||
entity.Serial = ((int)reader.GetDecimal(index++));
|
||||
entity.EntityCreated = DAUtil.ReadDateTime(reader, index++);
|
||||
entity.EntityCreator = reader[index] != DBNull.Value ? reader.GetInt32(index) : 0;
|
||||
index++;
|
||||
entity.EntityLastChanged = DAUtil.ReadDateTime(reader, index++);
|
||||
entity.EntityModifier = reader[index] != DBNull.Value ? reader.GetInt32(index) : new int?();
|
||||
|
||||
entity.SetLoaded();
|
||||
}
|
||||
|
||||
public void LoadFromReader(EntityType entity, SDA.DataProvider.SDADataReader reader, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
entity.ID = ((int)reader.GetDecimal(0));
|
||||
|
||||
LoadEntityFields(entity, reader, columnFilterMode, columns);
|
||||
|
||||
int index = reader.FieldCount - 6;
|
||||
entity.Torolt = reader[index] != DBNull.Value && reader.GetBoolean(index);
|
||||
index++;
|
||||
entity.Serial = ((int)reader.GetDecimal(index++));
|
||||
entity.EntityCreated = DAUtil.ReadDateTime(reader, index++);
|
||||
entity.EntityCreator = reader[index] != DBNull.Value ? reader.GetInt32(index) : 0;
|
||||
index++;
|
||||
entity.EntityLastChanged = DAUtil.ReadDateTime(reader, index++);
|
||||
entity.EntityModifier = reader[index] != DBNull.Value ? reader.GetInt32(index++) : new int?();
|
||||
entity.SetLoaded();
|
||||
}
|
||||
|
||||
public bool LoadEntityCollection(IEntityCollection<EntityType> collection, SDA.DataProvider.SDACommand command)
|
||||
{
|
||||
using (SDA.DataProvider.SDADataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
EntityType entity = CreateEntityInstance();
|
||||
LoadFromReader(entity, reader);
|
||||
((EntityCollection<EntityType>)collection).InternalAdd(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadEntityCollection(IEntityCollection<EntityType> collection, SDA.DataProvider.SDACommand command, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
using (SDA.DataProvider.SDADataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
EntityType entity = CreateEntityInstance();
|
||||
LoadFromReader(entity, reader, columnFilterMode, columns);
|
||||
((EntityCollection<EntityType>)collection).InternalAdd(entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadSingleEntity(EntityType entity, SDA.DataProvider.SDACommand command)
|
||||
{
|
||||
using (SDA.DataProvider.SDADataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
LoadFromReader(entity, reader);
|
||||
|
||||
if (reader.Read())
|
||||
{
|
||||
throw new Kreta.Framework.DataIntegrityException("Egyediség megsértése: " + entity.GetEntityName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadSingleEntity(EntityType entity, SDA.DataProvider.SDACommand command, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
using (SDA.DataProvider.SDADataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
LoadFromReader(entity, reader, columnFilterMode, columns);
|
||||
|
||||
if (reader.Read())
|
||||
{
|
||||
throw new Kreta.Framework.DataIntegrityException("Egyediség megsértése: " + entity.GetEntityName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadByPartnerId(EntityType entity, string filterText, int partnerId)
|
||||
{
|
||||
using (SDA.DataProvider.SDACommand command = CreateEmptyQueryCommand())
|
||||
{
|
||||
command.CommandText += filterText;
|
||||
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = partnerId;
|
||||
return LoadSingleEntity(entity, command, ColumnFilterMode.DEFAULT_ALLOWED, null);
|
||||
}
|
||||
}
|
||||
|
||||
public bool LoadByPartnerId(IEntityCollection<EntityType> collection, string filterText, int partnerId)
|
||||
{
|
||||
using (SDA.DataProvider.SDACommand command = CreateEmptyQueryCommand())
|
||||
{
|
||||
command.CommandText += filterText;
|
||||
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = partnerId;
|
||||
return LoadEntityCollection(collection, command, ColumnFilterMode.DEFAULT_ALLOWED, null);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void BindAttributes(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
public abstract void BindAssociations(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
public abstract void DynamicBindAttributes(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
public void CreateParameterBinding(SDA.DataProvider.SDACommand command, Dictionary<string, object> commandParameters)
|
||||
{
|
||||
if (commandParameters != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> kvp in commandParameters)
|
||||
{
|
||||
// mssql nem szereti parameter nevben a ":"-ot
|
||||
string pName = kvp.Key;
|
||||
if (pName.StartsWith(":"))
|
||||
{
|
||||
pName = pName.TrimStart(new char[] { ':' });
|
||||
}
|
||||
|
||||
if (kvp.Value.GetType() == typeof(int))
|
||||
{
|
||||
command.Parameters.Add(pName, SDA.DataProvider.SDADBType.Int).Value = Convert.ToInt32(kvp.Value);
|
||||
}
|
||||
if (kvp.Value.GetType() == typeof(string))
|
||||
{
|
||||
command.Parameters.Add(pName, SDA.DataProvider.SDADBType.String).Value = Convert.ToString(kvp.Value);
|
||||
}
|
||||
if (kvp.Value.GetType() == typeof(DateTime))
|
||||
{
|
||||
command.Parameters.Add(pName, SDA.DataProvider.SDADBType.DateTime).Value = Convert.ToDateTime(kvp.Value, LanguageContext.Current.RegionSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
107
Framework/Entities/Generic/EntityDataAccessor.cs
Normal file
107
Framework/Entities/Generic/EntityDataAccessor.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Kreta.Framework.Collections;
|
||||
using Kreta.Framework.Collections.Generic;
|
||||
|
||||
namespace Kreta.Framework.Entities.Generic
|
||||
{
|
||||
/// <summary>
|
||||
/// Entitások adatbázisműveleteit végző objektumának őse
|
||||
/// </summary>
|
||||
public abstract class EntityDataAccessor<EntityType> : IEntityDataAccessor<EntityType>, IEntityDataAccessor
|
||||
where EntityType : Kreta.Framework.Entities.Entity
|
||||
{
|
||||
|
||||
protected abstract IEntityDBHelper<EntityType> dbhelper
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Beállítja a létrehozóját egy entitásnak
|
||||
/// </summary>
|
||||
/// <param name="entity">A beállítandó entitás</param>
|
||||
protected void SetEntityCreator(EntityType entity, DateTime timestamp, int uniqueidentifier)
|
||||
{
|
||||
entity.EntityCreated = timestamp;
|
||||
entity.EntityCreator = uniqueidentifier;
|
||||
//entity.EntitySubsCreator = UserContext.Instance.SubstituteEmployeePrintName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Beállítja a módosítóját egy entitásnak
|
||||
/// </summary>
|
||||
/// <param name="entity">A beállítandó entitás</param>
|
||||
protected void SetEntityModifier(EntityType entity, DateTime timestamp, int uniqueidentifier)
|
||||
{
|
||||
entity.EntityLastChanged = timestamp;
|
||||
entity.EntityModifier = uniqueidentifier;
|
||||
//entity.EntitySubsLastModifier = UserContext.Instance.SubstituteEmployeePrintName;
|
||||
}
|
||||
|
||||
#region ISDAEntityDataAccessor<EntityType> Members
|
||||
|
||||
public abstract bool LoadEntity(EntityType entity, int entityId);
|
||||
|
||||
public virtual bool FilteredLoadEntity(EntityType entity, int entityId, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
return LoadEntity(entity, entityId);
|
||||
}
|
||||
|
||||
public abstract void LoadWithFilter(IEntityCollection<EntityType> collection, string filter, Dictionary<string, object> commandParameters);
|
||||
|
||||
public virtual void LoadWithFilter(IEntityCollection<EntityType> collection, string filter, ColumnFilterMode columnFilterMode, IEnumerable<string> columns, Dictionary<string, object> commandParameters)
|
||||
{
|
||||
LoadWithFilter(collection, filter, commandParameters);
|
||||
}
|
||||
|
||||
public abstract void InsertEntity(EntityType entity);
|
||||
|
||||
public abstract bool UpdateEntity(EntityType entity);
|
||||
|
||||
public abstract bool UpdateAssociations(EntityType entity);
|
||||
|
||||
public abstract void DeleteEntity(EntityType entity, bool logikai = true);
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEntityDataAccessor Members
|
||||
|
||||
bool IEntityDataAccessor.LoadEntity(Entity entity, int entityId)
|
||||
{
|
||||
return LoadEntity((EntityType)entity, entityId);
|
||||
}
|
||||
|
||||
bool IEntityDataAccessor.FilteredLoadEntity(Entity entity, int entityId, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
||||
{
|
||||
return FilteredLoadEntity((EntityType)entity, entityId, columnFilterMode, columns);
|
||||
}
|
||||
|
||||
void IEntityDataAccessor.LoadWithFilter(IEntityCollection collection, string filter, Dictionary<string, object> commandParameters)
|
||||
{
|
||||
LoadWithFilter((IEntityCollection<EntityType>)collection, filter, commandParameters);
|
||||
}
|
||||
|
||||
void IEntityDataAccessor.InsertEntity(Entity entity)
|
||||
{
|
||||
InsertEntity((EntityType)entity);
|
||||
}
|
||||
|
||||
bool IEntityDataAccessor.UpdateEntity(Entity entity)
|
||||
{
|
||||
return UpdateEntity((EntityType)entity);
|
||||
}
|
||||
|
||||
bool IEntityDataAccessor.UpdateAssociations(Entity entity)
|
||||
{
|
||||
return UpdateAssociations((EntityType)entity);
|
||||
}
|
||||
|
||||
void IEntityDataAccessor.DeleteEntity(Entity entity, bool logikai)
|
||||
{
|
||||
DeleteEntity((EntityType)entity, logikai);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
39
Framework/Entities/Generic/IEntityDBHelper.cs
Normal file
39
Framework/Entities/Generic/IEntityDBHelper.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Framework.Collections.Generic;
|
||||
|
||||
namespace Kreta.Framework.Entities.Generic
|
||||
{
|
||||
public interface IEntityDBHelper<EntityType>
|
||||
where EntityType : Kreta.Framework.Entities.Entity
|
||||
{
|
||||
string EmptyQueryCommandText { get; }
|
||||
|
||||
SDA.DataProvider.SDACommand CreateEmptyQueryCommand();
|
||||
|
||||
SDA.DataProvider.SDACommand CreateDynamicQueryCommand(ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
void LoadEntityFields(EntityType entity, SDA.DataProvider.SDADataReader reader, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
void LoadFromReader(EntityType entity, SDA.DataProvider.SDADataReader reader, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
bool LoadEntityCollection(IEntityCollection<EntityType> collection, SDA.DataProvider.SDACommand command);
|
||||
|
||||
bool LoadEntityCollection(IEntityCollection<EntityType> collection, SDA.DataProvider.SDACommand command, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
bool LoadSingleEntity(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
bool LoadSingleEntity(EntityType entity, SDA.DataProvider.SDACommand command, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
bool LoadByPartnerId(EntityType entity, string filterText, int partnerId);
|
||||
|
||||
bool LoadByPartnerId(IEntityCollection<EntityType> collection, string filterText, int partnerId);
|
||||
|
||||
void BindAttributes(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
void DynamicBindAttributes(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
void BindAssociations(EntityType entity, SDA.DataProvider.SDACommand command);
|
||||
|
||||
void CreateParameterBinding(SDA.DataProvider.SDACommand command, Dictionary<string, object> commandParameters);
|
||||
}
|
||||
}
|
75
Framework/Entities/Generic/IEntityDataAccessor.cs
Normal file
75
Framework/Entities/Generic/IEntityDataAccessor.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Framework.Collections.Generic;
|
||||
|
||||
namespace Kreta.Framework.Entities.Generic
|
||||
{
|
||||
/// <summary>
|
||||
/// Entitások adatbázisműveleteit végző objektumának felülete.
|
||||
/// </summary>
|
||||
public interface IEntityDataAccessor<EntityType>
|
||||
where EntityType : Kreta.Framework.Entities.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// Betölti egy entitás állapotát az adatbázisból.
|
||||
/// </summary>
|
||||
/// <param name="entity">A betöltendő entitás</param>
|
||||
/// <param name="entityId">Az entitás adatbázisbeli azonosítója</param>
|
||||
/// <returns>True, ha sikeres; egyébként false</returns>
|
||||
bool LoadEntity(EntityType entity, int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// Oszlopszűrten beltölti egy entitás állapotát az adatbázisból
|
||||
/// </summary>
|
||||
/// <param name="entity">A betöltendő entitás</param>
|
||||
/// <param name="entityId">Az entitás adatbázisbeli azonosítója</param>
|
||||
/// <param name="columnFilterMode">A szűrés módja, megengedő vagy tiltó</param>
|
||||
/// <param name="columns">A szűrendő oszlopok felsorolása</param>
|
||||
/// <returns>True, ha sikeres; egyébként False</returns>
|
||||
bool FilteredLoadEntity(EntityType entity, int entityId, ColumnFilterMode columnFilterMode, IEnumerable<string> columns);
|
||||
|
||||
/// <summary>
|
||||
/// Betölt egy entitás listát a megadott szűrő feltétellel.
|
||||
/// </summary>
|
||||
/// <param name="collection">A feltöltendő lista</param>
|
||||
/// <param name="filter">A szűrő SQL töredék</param>
|
||||
/// <param name="commandParameters">a szűrőben megadott paraméterek commandBinding atalakitasa</param>
|
||||
void LoadWithFilter(IEntityCollection<EntityType> collection, string filter, Dictionary<string, object> commandParameters);
|
||||
|
||||
/// <summary>
|
||||
/// Oszlopszűrten betölt egy entitás listát a megadott szűrő feltétellel.
|
||||
/// </summary>
|
||||
/// <param name="collection">A feltöltendő lista</param>
|
||||
/// <param name="filter">A szűrő SQL töredék</param>
|
||||
/// <param name="columnFilterMode">A szűrés módja, megengedő vagy tiltó</param>
|
||||
/// <param name="columns">A szűrendő oszlopok felsorolása</param>
|
||||
/// <param name="commandParameters">a szűrőben megadott paraméterek commandBinding atalakitasa</param>
|
||||
void LoadWithFilter(IEntityCollection<EntityType> collection, string filter, ColumnFilterMode columnFilterMode, IEnumerable<string> columns, Dictionary<string, object> commandParameters);
|
||||
|
||||
/// <summary>
|
||||
/// Létrehoz egy új entitás példányt az adatbázisban.
|
||||
/// </summary>
|
||||
/// <param name="entity">A létrehozandó entitás</param>
|
||||
void InsertEntity(EntityType entity);
|
||||
|
||||
/// <summary>
|
||||
/// Módosít egy entitás példányt az adatbázisban.
|
||||
/// </summary>
|
||||
/// <param name="entity">A módosítandó entitás</param>
|
||||
/// <returns>True, ha sikeres; egyébként false</returns>
|
||||
bool UpdateEntity(EntityType entity);
|
||||
|
||||
/// <summary>
|
||||
/// Módosítja egy entitás példány asszociációs kapcsolómezőit az adatbázisban.
|
||||
/// </summary>
|
||||
/// <param name="entity">A módosítandó entitás</param>
|
||||
/// <returns>True, ha sikeres; egyébként false</returns>
|
||||
bool UpdateAssociations(EntityType entity);
|
||||
|
||||
/// <summary>
|
||||
/// Töröl egy entitás példányt az adatbázisból.
|
||||
/// </summary>
|
||||
/// <param name="entity">A törlendő entitás</param>
|
||||
/// <param name="logikai">Logikai törlés (Archiv flag)</param>
|
||||
void DeleteEntity(EntityType entity, bool logikai = true);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue