초기커밋
This commit is contained in:
118
BrokerApiTest/DocQuery/UserTestEntityAttribute.cs
Normal file
118
BrokerApiTest/DocQuery/UserTestEntityAttribute.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using ServerCommon;
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
|
||||
using ThirdParty.Json.LitJson;
|
||||
|
||||
// EntityAttributeBase를 상속 받은 개체는 메모리에 사용될 내용임
|
||||
// 스토리지에 저장은 UsrTestDoc:DynamoDbDocBase에서 처리함
|
||||
public class UserTestEntityAttribute : EntityAttributeBase
|
||||
{
|
||||
[JsonProperty] public string UserId { get; set; } = string.Empty;
|
||||
[JsonProperty] public string Name { get; set; } = string.Empty;
|
||||
|
||||
public UserTestEntityAttribute(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override UserTestDoc onCreateDocBase()
|
||||
{
|
||||
return new UserTestDoc(UserId, Name);
|
||||
}
|
||||
|
||||
public override void onClear()
|
||||
{
|
||||
UserId = string.Empty;
|
||||
Name = string.Empty;
|
||||
getAttributeState().reset();
|
||||
}
|
||||
|
||||
public override async Task<(Result, DynamoDbDocBase?)> toDocBase(bool isForQuery = true)
|
||||
{
|
||||
var result = new Result();
|
||||
|
||||
//=====================================================================================
|
||||
// try_pending_doc은 없으면 새로 생성하고 초기화 한다.
|
||||
//=====================================================================================
|
||||
if (getTryPendingDocBase() is not UserTestDoc try_pending_doc)
|
||||
{
|
||||
var new_pending_doc = new UserTestDoc();
|
||||
var origin_doc = getOriginDocBase<UserTestEntityAttribute>();
|
||||
if (origin_doc is not null)
|
||||
{
|
||||
new_pending_doc.copyTimestampsFromOriginDocBase(origin_doc);
|
||||
}
|
||||
|
||||
setTryPendingDocBase(new_pending_doc);
|
||||
try_pending_doc = (getTryPendingDocBase() as UserTestDoc)!;
|
||||
NullReferenceCheckHelper.throwIfNull(try_pending_doc, () => $"try_pending_doc is null !!!");
|
||||
}
|
||||
|
||||
var to_copy_user_test_attrib = try_pending_doc.getAttrib<UserTestAttrib>();
|
||||
NullReferenceCheckHelper.throwIfNull(to_copy_user_test_attrib, () => $"to_copy_user_test_attrib is null !!!");
|
||||
to_copy_user_test_attrib.UserId = UserId;
|
||||
to_copy_user_test_attrib.Name = Name;
|
||||
|
||||
|
||||
// 읽기 용도가 아닌 경우
|
||||
if (false == isForQuery)
|
||||
{
|
||||
return (result, try_pending_doc);
|
||||
}
|
||||
|
||||
//=====================================================================================
|
||||
// Doc QueryType 반영
|
||||
//=====================================================================================
|
||||
(result, var to_query_doc) = await applyDoc4Query(try_pending_doc);
|
||||
return result.isFail() ? (result, null) : (result, to_query_doc);
|
||||
}
|
||||
|
||||
public override IEntityAttributeTransactor onNewEntityAttributeTransactor()
|
||||
{
|
||||
return new UserTestEntityAttributeTransactor(getOwner());
|
||||
}
|
||||
|
||||
public override EntityAttributeBase onCloned()
|
||||
{
|
||||
var owner = getOwner() as UserTestEntity;
|
||||
NullReferenceCheckHelper.throwIfNull(owner, () => $"owner is null !!!");
|
||||
|
||||
return new UserTestEntityAttribute(owner) { UserId = UserId, Name = Name };
|
||||
}
|
||||
|
||||
private class UserTestEntityAttributeTransactor : EntityAttributeTransactorBase<UserTestEntityAttribute>,
|
||||
ICopyEntityAttributeTransactorFromEntityAttribute
|
||||
{
|
||||
public UserTestEntityAttributeTransactor(EntityBase owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
||||
public bool copyEntityAttributeTransactorFromEntityAttribute(EntityAttributeBase? entityAttribute)
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
|
||||
var to_cast_string = nameof(UserTestEntityAttribute);
|
||||
|
||||
if (entityAttribute is not UserTestEntityAttribute copy_from_user_test_attribute)
|
||||
{
|
||||
err_msg =
|
||||
$"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_from_user_test_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 롤백을 위해 객체를 복사한다.
|
||||
if (getClonedEntityAttribute() is not UserTestEntityAttribute copy_to_user_test_attribute)
|
||||
{
|
||||
err_msg =
|
||||
$"Failed to copyEntityAttributeTransactorBaseFromEntityAttribute() !!!, copy_to_user_test_attribute is null :{to_cast_string}";
|
||||
Log.getLogger().error(err_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
copy_to_user_test_attribute.UserId = copy_from_user_test_attribute.UserId;
|
||||
copy_to_user_test_attribute.Name = copy_from_user_test_attribute.Name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user