초기커밋
This commit is contained in:
180
GameServer/Contents/Friend/DbQuery/DBQAddFriend.cs
Normal file
180
GameServer/Contents/Friend/DbQuery/DBQAddFriend.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
using ServerCommon.BusinessLogDomain;
|
||||
using MetaAssets;
|
||||
|
||||
|
||||
namespace GameServer;
|
||||
|
||||
public class DBQAddFriend : QueryExecutorBase
|
||||
{
|
||||
private string m_my_combination_key_for_pk = string.Empty;
|
||||
private string m_my_combination_key_for_sk = string.Empty;
|
||||
private string m_friend_combination_key_for_pk = string.Empty;
|
||||
private string m_friend_combination_key_for_sk = string.Empty;
|
||||
|
||||
private FriendDoc m_my_doc = new();
|
||||
private string m_my_pk = string.Empty;
|
||||
private FriendDoc m_friend_doc = new();
|
||||
private string m_friend_pk = string.Empty;
|
||||
|
||||
private string m_my_guid = string.Empty;
|
||||
private string m_friend_guid = string.Empty;
|
||||
|
||||
public DBQAddFriend(string myGuid, string friendGuid)
|
||||
: base(typeof(DBQAddFriend).Name)
|
||||
{
|
||||
m_my_combination_key_for_pk = myGuid;
|
||||
m_my_combination_key_for_sk = friendGuid;
|
||||
m_friend_combination_key_for_pk = friendGuid;
|
||||
m_friend_combination_key_for_sk = myGuid;
|
||||
m_my_guid = myGuid;
|
||||
m_friend_guid = friendGuid;
|
||||
}
|
||||
|
||||
//===================================================================================================
|
||||
// DB 쿼리 직전에 준비해야 할 로직들을 작성한다.
|
||||
//===================================================================================================
|
||||
|
||||
public override Task<Result> onPrepareQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var player = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => "player is null !!!");
|
||||
|
||||
DateTime now = DateTimeHelper.Current;
|
||||
|
||||
m_my_doc = new FriendDoc();
|
||||
m_friend_doc = new FriendDoc();
|
||||
|
||||
var my_attrib = m_my_doc.getAttrib<FriendAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(my_attrib, () => "my_attrib is null !!!");
|
||||
|
||||
my_attrib.FriendGuid = m_friend_combination_key_for_pk;
|
||||
my_attrib.CreateTime = now;
|
||||
my_attrib.FolderName = ServerCommon.Constant.FRIEND_FOLDER_DEFUALT_NAME;
|
||||
my_attrib.IsNew = 1;
|
||||
|
||||
var friend_attrib = m_friend_doc.getAttrib<FriendAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(friend_attrib, () => "friend_attrib is null !!!");
|
||||
|
||||
friend_attrib.FriendGuid = m_my_combination_key_for_pk;
|
||||
friend_attrib.CreateTime = now;
|
||||
friend_attrib.FolderName = ServerCommon.Constant.FRIEND_FOLDER_DEFUALT_NAME;
|
||||
friend_attrib.IsNew = 1;
|
||||
|
||||
m_my_doc.setCombinationKeyForPKSK(m_my_combination_key_for_pk, m_my_combination_key_for_sk);
|
||||
m_friend_doc.setCombinationKeyForPKSK(m_friend_combination_key_for_pk, m_friend_combination_key_for_sk);
|
||||
|
||||
var my_error_code = m_my_doc.onApplyPKSK();
|
||||
var friend_error_code = m_friend_doc.onApplyPKSK();
|
||||
if (my_error_code.isFail() || friend_error_code.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to onApplyPKSK() !!! my_error_code : {my_error_code.toBasicString()}, friend_error_code : {friend_error_code.toBasicString()} - {player.toBasicString()}";
|
||||
result.setFail(my_error_code, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
m_my_pk = m_my_doc.getPK();
|
||||
m_friend_pk = m_friend_doc.getPK();
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
//===================================================================================================
|
||||
// onPrepareQuery()를 성공할 경우 호출된다.
|
||||
//===================================================================================================
|
||||
public override async Task<Result> onQuery()
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
var player = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(player, () => "player is null !!!");
|
||||
|
||||
var query_batch = getQueryBatch();
|
||||
NullReferenceCheckHelper.throwIfNull(query_batch, () => $"query_batch is null !!! - {player.toBasicString()}");
|
||||
|
||||
var db_connector = query_batch.getDynamoDbConnector();
|
||||
|
||||
(result, var my_document) = await m_my_doc.onCopyToDocument();
|
||||
if(result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to onCopyToDocument() !!! : {result.toBasicString()}, m_my_pk:{m_my_pk}, m_friend_pk:{m_friend_pk} - {toBasicString()}, {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
(result, var friend_document) = await m_friend_doc.onCopyToDocument();
|
||||
if (result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to onCopyToDocument() !!! : {result.toBasicString()}, m_my_pk:{m_my_pk}, m_friend_pk:{m_friend_pk} - {toBasicString()}, {player.toBasicString()}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
var table = db_connector.getTableByDoc(m_friend_doc);
|
||||
var my_docmument_ctx = new DynamoDbDocumentQueryContext(table.TableName, my_document, QueryType.Upsert);
|
||||
var my_friend_ctx = new DynamoDbDocumentQueryContext(table.TableName, friend_document, QueryType.Upsert);
|
||||
|
||||
(result, _) = await table.simpleTransactWriteWithDocument(new List<DynamoDbDocumentQueryContext>() { my_docmument_ctx, my_friend_ctx }, 2, query_batch.getTransId());
|
||||
if (result.isFail())
|
||||
{
|
||||
var err_msg = $"Failed to simpleTransactWrite !!! m_my_pk = {m_my_pk}, m_friend_pk = {m_friend_pk} - {toBasicString()}, {player.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.DynamoDbTransactException, err_msg);
|
||||
Log.getLogger().error(err_msg);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//===================================================================================================
|
||||
// DB 쿼리를 성공하고, doFnCommit()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//===================================================================================================
|
||||
public override Task onQueryResponseCommit()
|
||||
{
|
||||
//여기서 메모리 업데이트
|
||||
var owner = getOwner();
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => "owner is null !!!");
|
||||
|
||||
var friend_agent_action = owner.getEntityAction<FriendAgentAction>();
|
||||
NullReferenceCheckHelper.throwIfNull(friend_agent_action, () => "friend_agent_action is null !!!");
|
||||
|
||||
var friends = friend_agent_action.getFriends();
|
||||
|
||||
Friend friend = new(owner);
|
||||
var new_friend_attribue = friend.getEntityAttribute<FriendAttribute>();
|
||||
NullReferenceCheckHelper.throwIfNull(new_friend_attribue, () => "new_friend_attribue is null !!!");
|
||||
|
||||
var friend_attrib = m_friend_doc.getAttrib<FriendAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(friend_attrib, () => "friend_attrib is null !!!");
|
||||
|
||||
new_friend_attribue.UserGuid = m_my_guid;
|
||||
new_friend_attribue.FriendGuid = m_friend_guid;
|
||||
new_friend_attribue.CreateTime = friend_attrib.CreateTime;
|
||||
new_friend_attribue.FolderName = friend_attrib.FolderName;
|
||||
new_friend_attribue.IsNew = friend_attrib.IsNew;
|
||||
|
||||
friends.TryAdd(m_friend_guid, friend);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
//===================================================================================================
|
||||
// DB 쿼리를 실패하고, doFnRollback()가 QueryResultType.NotCalledQueryFunc를 반환할 경우 호출된다.
|
||||
//===================================================================================================
|
||||
public override Task onQueryResponseRollback(Result errorResult)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private new Player? getOwner() => getQueryBatch()?.getLogActor() as Player;
|
||||
}
|
||||
Reference in New Issue
Block a user