|
|
@ -130,18 +130,17 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
// ----
|
|
|
|
// ----
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets an dbObject by primaryKey/s
|
|
|
|
/// Gets all dbObjects of class/table
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
/// <param name="classObject">Given object (marked with Db-attributes)</param>
|
|
|
|
/// <param name="classObject">Given object (marked with Db-attributes)</param>
|
|
|
|
/// <param name="whereClause">Custom where-clause params attached to query (SELECT * FROM tableName WHERE whereClause)</param>
|
|
|
|
|
|
|
|
/// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
|
|
|
|
/// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
|
|
|
|
public static List<T> GetListWithWhere<T>(Type classType, Func<string, List<Dictionary<string, object>>> queryExecutor, params object[] whereClause) where T : new()
|
|
|
|
public static List<T> GetList<T>(Type classType, Func<string, List<Dictionary<string, object>>> queryExecutor) where T : new()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Read dbObject - attribute
|
|
|
|
// Read dbObject - attribute
|
|
|
|
DbObject dbObject = ClassAction.Init(classType);
|
|
|
|
DbObject dbObject = ClassAction.Init(classType);
|
|
|
|
|
|
|
|
|
|
|
|
string query = QueryBuilder.SelectWithWhere(dbObject._tableName, whereClause); // Generate query
|
|
|
|
string query = QueryBuilder.SelectByAttribute(dbObject._tableName); // Generate query
|
|
|
|
List<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
|
|
|
|
List<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
|
|
|
|
|
|
|
|
|
|
|
|
List<T> objs = new List<T>() { };
|
|
|
|
List<T> objs = new List<T>() { };
|
|
|
@ -156,17 +155,29 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Resolves dbObject by primaryKey/s<pragma/>
|
|
|
|
/// Gets an dbObject by primaryKey/s
|
|
|
|
/// Object needs to have primaryKey/s set!
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
/// <param name="classObject">Given object (marked with Db-attributes)</param>
|
|
|
|
/// <param name="classObject">Given object (marked with Db-attributes)</param>
|
|
|
|
|
|
|
|
/// <param name="whereClause">Custom where-clause params attached to query (SELECT * FROM tableName WHERE whereClause)</param>
|
|
|
|
/// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
|
|
|
|
/// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
|
|
|
|
public static void ResolveByPrimaryKey<T>(T classObject, Func<string, List<Dictionary<string, object>>> queryExecutor)
|
|
|
|
public static List<T> GetListWithWhere<T>(Type classType, Func<string, List<Dictionary<string, object>>> queryExecutor, params object[] whereClause) where T : new()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string query = QueryBuilder.SelectByPrimaryKey(classObject); // Generate query
|
|
|
|
// Read dbObject - attribute
|
|
|
|
|
|
|
|
DbObject dbObject = ClassAction.Init(classType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string query = QueryBuilder.SelectWithWhere(dbObject._tableName, whereClause); // Generate query
|
|
|
|
List<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
|
|
|
|
List<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
|
|
|
|
FillObject(classObject, dataSet[0]); // Fill the object
|
|
|
|
|
|
|
|
|
|
|
|
List<T> objs = new List<T>() { };
|
|
|
|
|
|
|
|
foreach (Dictionary<string, object> data in dataSet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
T obj = new T(); // New object
|
|
|
|
|
|
|
|
FillObject(obj, data); // Fill it
|
|
|
|
|
|
|
|
objs.Add(obj); // Add to list
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return objs; // Return list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -199,7 +210,21 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
return objs; // Return list
|
|
|
|
return objs; // Return list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Resolves dbObject by primaryKey/s<pragma/>
|
|
|
|
|
|
|
|
/// Object needs to have primaryKey/s set!
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
|
|
/// <param name="classObject">Given object (marked with Db-attributes)</param>
|
|
|
|
|
|
|
|
/// <param name="queryExecutor">Function to handle query-calls - Has to return Dictionary[attributeName, attributeValue]</param>
|
|
|
|
|
|
|
|
public static void ResolveByPrimaryKey<T>(T classObject, Func<string, List<Dictionary<string, object>>> queryExecutor)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string query = QueryBuilder.SelectByPrimaryKey(classObject); // Generate query
|
|
|
|
|
|
|
|
List<Dictionary<string, object>> dataSet = queryExecutor(query); // Execute
|
|
|
|
|
|
|
|
FillObject(classObject, dataSet[0]); // Fill the object
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Resolves all foreignKeys with the database<pragma/>
|
|
|
|
/// Resolves all foreignKeys with the database<pragma/>
|
|
|
@ -224,7 +249,7 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|
|
|
// When its empty, get it
|
|
|
|
// When its empty, get it
|
|
|
|
if(foreignObject_value == null)
|
|
|
|
if(foreignObject_value == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreignObject_value = GetByPrimaryKey<T>(classType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor); ;
|
|
|
|
foreignObject_value = GetByPrimaryKey<T>(classType, foreignObjectAtt.foreignKeyAttribute.parentField.GetValue(classObject), queryExecutor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Recursive resolving
|
|
|
|
// Recursive resolving
|
|
|
|