초기커밋
This commit is contained in:
184
ServerCommon/Entity/DbQuery/DBQEntityReadToAttribute.cs
Normal file
184
ServerCommon/Entity/DbQuery/DBQEntityReadToAttribute.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Amazon.DynamoDBv2;
|
||||
using Amazon.DynamoDBv2.Model;
|
||||
using Amazon.DynamoDBv2.DocumentModel;
|
||||
using Amazon.Runtime;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
using SESSION_ID = System.Int32;
|
||||
using META_ID = System.UInt32;
|
||||
using ENTITY_GUID = System.String;
|
||||
using ACCOUNT_ID = System.String;
|
||||
using OWNER_GUID = System.String;
|
||||
using USER_GUID = System.String;
|
||||
using CHARACTER_GUID = System.String;
|
||||
using ITEM_GUID = System.String;
|
||||
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class DBQEntityReadToAttribute<TDoc> : QueryExecutorBase
|
||||
where TDoc : DynamoDbDocBase, new()
|
||||
{
|
||||
private EntityBase m_owner_of_entity_attribute;
|
||||
|
||||
private string m_combination_key_for_pk = string.Empty;
|
||||
private string m_combination_key_for_sk = string.Empty;
|
||||
|
||||
private string m_pk = string.Empty;
|
||||
private string m_sk = string.Empty;
|
||||
|
||||
private readonly List<DynamoDbDocBase> m_to_read_doc_bases = new();
|
||||
private readonly List<Type> m_copy_to_target_entity_attribute_types;
|
||||
|
||||
public DBQEntityReadToAttribute( EntityBase ownerOfEntityAttribute
|
||||
, string combinationKeyForPK, Type[] copyToTargetEnityAttributeTypes)
|
||||
: base(typeof(DBQEntityReadToAttribute<TDoc>).Name)
|
||||
{
|
||||
m_owner_of_entity_attribute = ownerOfEntityAttribute;
|
||||
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
m_copy_to_target_entity_attribute_types = copyToTargetEnityAttributeTypes.ToList<Type>();
|
||||
}
|
||||
|
||||
public DBQEntityReadToAttribute( EntityBase ownerOfEntityAttribute
|
||||
, string combinationKeyForPK, string combinationKeyForSK, Type[] copyToTargetEnityAttributeTypes)
|
||||
: base(typeof(DBQEntityReadToAttribute<TDoc>).Name)
|
||||
{
|
||||
m_owner_of_entity_attribute = ownerOfEntityAttribute;
|
||||
|
||||
m_combination_key_for_pk = combinationKeyForPK;
|
||||
m_combination_key_for_sk = combinationKeyForSK;
|
||||
m_copy_to_target_entity_attribute_types = copyToTargetEnityAttributeTypes.ToList<Type>();
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onPrepareQuery()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
(result, var primary_key) = await DynamoDBDocBaseHelper.makePrimaryKey<TDoc>(m_combination_key_for_pk, m_combination_key_for_sk);
|
||||
if(result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to makePrimaryKey<TDoc>() !!! : {result.toBasicString()}, {typeof(TDoc).Name} - {toBasicString()}, {owner.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
NullReferenceCheckHelper.throwIfNull(primary_key, () => $"primary_key is null !!! - {owner.toBasicString()}");
|
||||
|
||||
m_pk = primary_key.PK;
|
||||
m_sk = primary_key.SK;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
var query_batch = getQueryBatch();
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {owner.toBasicString()}");
|
||||
|
||||
var server_logic = ServerLogicApp.getServerLogicApp();
|
||||
var dynamo_db_connector = query_batch.getDynamoDbConnector();
|
||||
|
||||
QueryOperationConfig? query_config = null;
|
||||
if (true == m_sk.isNullOrWhiteSpace())
|
||||
{
|
||||
query_config = dynamo_db_connector.makeQueryConfigForReadByPKSK(m_pk);
|
||||
}
|
||||
else
|
||||
{
|
||||
query_config = dynamo_db_connector.makeQueryConfigForReadByPKSK(m_pk, m_sk);
|
||||
}
|
||||
|
||||
(result, var read_docs) = await dynamo_db_connector.simpleQueryDocTypesWithQueryOperationConfig<TDoc>(query_config, eventTid: query_batch.getTransId());
|
||||
if(result.isFail())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var msg = $"{this.getTypeName()} : readCount:{read_docs.Count}, isUseTransact:{query_batch.isUseTransact} - TransId:{query_batch.getTransId()}";
|
||||
Log.getLogger().info(msg);
|
||||
|
||||
foreach ( var read_doc in read_docs )
|
||||
{
|
||||
foreach (var target_entity_attribute_type in m_copy_to_target_entity_attribute_types)
|
||||
{
|
||||
var target_entity_attribute_base = getOwnerOfEntityAttribute().getOriginEntityAttribute(target_entity_attribute_type);
|
||||
if (null == target_entity_attribute_base)
|
||||
{
|
||||
err_msg = $"Not found Target getOriginEntityAttribute() !!!"
|
||||
+ $" : to:{target_entity_attribute_type.Name}, from:{typeof(TDoc).Name}, ownerOfAttribute:{getOwnerOfEntityAttribute().toBasicString()}"
|
||||
+ $" - {toBasicString()}, {owner.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.EntityAttributeNotFound, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return result;
|
||||
}
|
||||
|
||||
result = await ServerBase.DataCopyHelper.copyEntityAttributeFromDocs(target_entity_attribute_base, new List<DynamoDbDocBase>() { read_doc });
|
||||
if (result.isFail())
|
||||
{
|
||||
err_msg = $"Failed to copyEntityAttributeFromDocs() !!! : {result.toBasicString()}, ownerOfAttribute:{getOwnerOfEntityAttribute().toBasicString()}"
|
||||
+ $" - {toBasicString()}, {owner.toBasicString()}";
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
m_to_read_doc_bases.Add(read_doc);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<DynamoDbDocBase> getToReadDocBases() => m_to_read_doc_bases;
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseCommit()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//=====================================================================================
|
||||
public override async Task onQueryResponseRollback(Result errorResult)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
public EntityBase getOwnerOfEntityAttribute() => m_owner_of_entity_attribute;
|
||||
}
|
||||
Reference in New Issue
Block a user