mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Start TEngine3.0
Start TEngine3.0
This commit is contained in:
202
Luban/Luban.ClientServer/Templates/db/cs_async/bean.tpl
Normal file
202
Luban/Luban.ClientServer/Templates/db/cs_async/bean.tpl
Normal file
@@ -0,0 +1,202 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.convention_name}} { get; }
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} BrightDB.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : BrightDB.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => new BrightDB.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(BrightDB.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
61
Luban/Luban.ClientServer/Templates/db/cs_async/table.tpl
Normal file
61
Luban/Luban.ClientServer/Templates/db/cs_async/table.tpl
Normal file
@@ -0,0 +1,61 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> GetAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.GetAsync(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_define_type value_ttype}}> CreateIfNotExistAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
public static Task InsertAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.InsertAsync(key, value);
|
||||
}
|
||||
|
||||
public static Task RemoveAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public static Task PutAsync({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
return Table.PutAsync(key, value);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
16
Luban/Luban.ClientServer/Templates/db/cs_async/tables.tpl
Normal file
16
Luban/Luban.ClientServer/Templates/db/cs_async/tables.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<BrightDB.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<BrightDB.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
202
Luban/Luban.ClientServer/Templates/db/cs_sync/bean.tpl
Normal file
202
Luban/Luban.ClientServer/Templates/db/cs_sync/bean.tpl
Normal file
@@ -0,0 +1,202 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = "IReadOnly" + name
|
||||
}}
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public interface {{readonly_name}} {{if parent_def_type}}: IReadOnly{{x.parent_def_type.name}} {{end}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{db_cs_readonly_define_type field.ctype}} {{field.convention_name}} { get; }
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{x.cs_class_modifier}} class {{name}} : {{if parent_def_type}} {{x.parent}} {{else}} BrightDB.Transaction.TxnBeanBase {{end}}, {{readonly_name}}
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{db_cs_define_type field.ctype}} {{field.internal_name}};
|
||||
{{~end}}
|
||||
|
||||
public {{name}}()
|
||||
{
|
||||
{{~ for field in fields~}}
|
||||
{{if cs_need_init field.ctype}}{{db_cs_init_field field.internal_name field.ctype}} {{end}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{ctype = field.ctype}}
|
||||
{{~if has_setter ctype~}}
|
||||
|
||||
private sealed class {{field.log_type}} : BrightDB.Transaction.FieldLogger<{{name}}, {{db_cs_define_type ctype}}>
|
||||
{
|
||||
public {{field.log_type}}({{name}} self, {{db_cs_define_type ctype}} value) : base(self, value) { }
|
||||
|
||||
public override long FieldId => this._host.GetObjectId() + {{field.id}};
|
||||
|
||||
public override int TagId => FieldTag.{{tag_name ctype}};
|
||||
|
||||
public override void Commit() { this._host.{{field.internal_name}} = this.Value; }
|
||||
|
||||
|
||||
public override void WriteBlob(ByteBuf _buf)
|
||||
{
|
||||
{{cs_write_blob '_buf' 'this.Value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}}
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
if (txn == null) return {{field.internal_name}};
|
||||
var log = ({{field.log_type}})txn.GetField(this.GetObjectId() + {{field.id}});
|
||||
return log != null ? log.Value : {{field.internal_name}};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {{field.internal_name}};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new ArgumentNullException();
|
||||
{{~end~}}
|
||||
if (this.IsManaged)
|
||||
{
|
||||
var txn = BrightDB.Transaction.TransactionContext.ThreadStaticCtx;
|
||||
txn.PutField(this.GetObjectId() + {{field.id}}, new {{field.log_type}}(this, value));
|
||||
{{~if ctype.need_set_children_root}}
|
||||
value?.InitRoot(GetRoot());
|
||||
{{end}}
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.internal_name}} = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public {{db_cs_define_type ctype}} {{field.convention_name}} => {{field.internal_name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~if ctype.bean || ctype.element_type ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => {{field.internal_name}};
|
||||
{{~else if ctype.is_map~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{field.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
{{db_cs_readonly_define_type ctype}} {{readonly_name}}.{{field.convention_name}} => new BrightDB.Transaction.Collections.PReadOnlyMap<{{db_cs_readonly_define_type ctype.key_type}}, {{db_cs_readonly_define_type ctype.value_type}}, {{db_cs_define_type ctype.value_type}}>({{field.internal_name}});
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
public static void Serialize{{name}}(ByteBuf _buf, {{name}} x)
|
||||
{
|
||||
if (x == null) { _buf.WriteInt(0); return; }
|
||||
_buf.WriteInt(x.GetTypeId());
|
||||
x.Serialize(_buf);
|
||||
}
|
||||
|
||||
public static {{name}} Deserialize{{name}}(ByteBuf _buf)
|
||||
{
|
||||
{{name}} x;
|
||||
switch (_buf.ReadInt())
|
||||
{
|
||||
case 0 : return null;
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break;
|
||||
{{~end~}}
|
||||
default: throw new SerializationException();
|
||||
}
|
||||
x.Deserialize(_buf);
|
||||
return x;
|
||||
}
|
||||
{{~else~}}
|
||||
public override void Serialize(ByteBuf _buf)
|
||||
{
|
||||
_buf.WriteLong(this.GetObjectId());
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_cs_compatible_serialize '_buf' field.internal_name field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
public override void Deserialize(ByteBuf _buf)
|
||||
{
|
||||
this.SetObjectId(_buf.ReadLong());
|
||||
while(_buf.NotEmpty)
|
||||
{
|
||||
int _tag_ = _buf.ReadInt();
|
||||
switch (_tag_)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_cs_compatible_deserialize '_buf' field.internal_name field.ctype}} break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public const int __ID__ = {{x.id}};
|
||||
public override int GetTypeId() => __ID__;
|
||||
{{~end~}}
|
||||
|
||||
protected override void InitChildrenRoot(Bright.Storage.TKey root)
|
||||
{
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
UnsafeUtil.InitRoot({{field.internal_name}}, root);
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{{full_name}}{ "
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ "{{field.convention_name}}:" + {{cs_to_string field.convention_name field.ctype}} + ","
|
||||
{{~end~}}
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
66
Luban/Luban.ClientServer/Templates/db/cs_sync/table.tpl
Normal file
66
Luban/Luban.ClientServer/Templates/db/cs_sync/table.tpl
Normal file
@@ -0,0 +1,66 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
base_table_type = x.base_table_type
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace {{x.namespace_with_top_module}}
|
||||
{
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/// <summary>
|
||||
/// {{x.escape_comment}}
|
||||
/// </summary>
|
||||
{{~end~}}
|
||||
public sealed class {{name}}
|
||||
{
|
||||
public static {{base_table_type}} Table { get; } = new {{internal_table_type}}();
|
||||
|
||||
private class {{internal_table_type}} : {{base_table_type}}
|
||||
{
|
||||
public {{internal_table_type}}() : base({{x.table_uid}}, "{{x.full_name}}")
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} Get({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Get(key);
|
||||
}
|
||||
|
||||
public static {{db_cs_define_type value_ttype}} CreateIfNotExist({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.CreateIfNotExist(key);
|
||||
}
|
||||
|
||||
public static void Insert({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Insert(key, value);
|
||||
}
|
||||
|
||||
public static void Remove({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
Table.Remove(key);
|
||||
}
|
||||
|
||||
public static void Put({{db_cs_define_type key_ttype}} key, {{db_cs_define_type value_ttype}} value)
|
||||
{
|
||||
Table.Put(key, value);
|
||||
}
|
||||
|
||||
public static {{db_cs_readonly_define_type value_ttype}} Select({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.Select(key);
|
||||
}
|
||||
|
||||
public static ValueTask<{{db_cs_readonly_define_type value_ttype}}> SelectAsync({{db_cs_define_type key_ttype}} key)
|
||||
{
|
||||
return Table.SelectAsync<{{db_cs_readonly_define_type value_ttype}}>(key);
|
||||
}
|
||||
}
|
||||
}
|
16
Luban/Luban.ClientServer/Templates/db/cs_sync/tables.tpl
Normal file
16
Luban/Luban.ClientServer/Templates/db/cs_sync/tables.tpl
Normal file
@@ -0,0 +1,16 @@
|
||||
using Bright.Serialization;
|
||||
|
||||
namespace {{namespace}}
|
||||
{
|
||||
|
||||
public static class {{name}}
|
||||
{
|
||||
public static System.Collections.Generic.List<BrightDB.Transaction.TxnTable> TableList { get; } = new System.Collections.Generic.List<BrightDB.Transaction.TxnTable>
|
||||
{
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.Table,
|
||||
{{~end}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
157
Luban/Luban.ClientServer/Templates/db/typescript/bean.tpl
Normal file
157
Luban/Luban.ClientServer/Templates/db/typescript/bean.tpl
Normal file
@@ -0,0 +1,157 @@
|
||||
{{
|
||||
name = x.name
|
||||
full_name = x.full_name
|
||||
parent_def_type = x.parent_def_type
|
||||
fields = x.fields
|
||||
hierarchy_fields = x.hierarchy_fields
|
||||
is_abstract_type = x.is_abstract_type
|
||||
readonly_name = 'IReadOnly' + name
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export {{x.ts_class_modifier}} class {{name}} extends {{if parent_def_type}} {{x.parent}} {{else}} TxnBeanBase {{end}}{
|
||||
{{~ for field in fields~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{if is_abstract_type}}protected{{else}}private{{end}} {{field.internal_name}}: {{db_ts_define_type field.ctype}}
|
||||
{{~end}}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
{{~ for field in fields~}}
|
||||
{{db_ts_init_field field.internal_name_with_this field.log_type field.ctype }}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
{{~ for field in fields~}}
|
||||
{{~ctype = field.ctype~}}
|
||||
{{~if has_setter ctype~}}
|
||||
private static {{field.log_type}} = class extends FieldLoggerGeneric2<{{name}}, {{db_ts_define_type ctype}}> {
|
||||
constructor(self:{{name}}, value: {{db_ts_define_type ctype}}) { super(self, value) }
|
||||
|
||||
get fieldId(): number { return this.host.getObjectId() + {{field.id}} }
|
||||
|
||||
get tagId(): number { return FieldTag.{{tag_name ctype}} }
|
||||
|
||||
commit() { this.host.{{field.internal_name}} = this.value }
|
||||
|
||||
writeBlob(_buf: ByteBuf) {
|
||||
{{ts_write_blob '_buf' 'this.value' ctype}}
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{db_ts_define_type ctype}} {
|
||||
if (this.isManaged) {
|
||||
var txn = TransactionContext.current
|
||||
if (txn == null) return {{field.internal_name_with_this}}
|
||||
let log: any = txn.getField(this.getObjectId() + {{field.id}})
|
||||
return log != null ? log.value : {{field.internal_name_with_this}}
|
||||
} else {
|
||||
return {{field.internal_name_with_this}};
|
||||
}
|
||||
}
|
||||
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
set {{field.convention_name}}(value: {{db_ts_define_type ctype}}) {
|
||||
{{~if db_field_cannot_null~}}
|
||||
if (value == null) throw new Error()
|
||||
{{~end~}}
|
||||
if (this.isManaged) {
|
||||
let txn = TransactionContext.current!
|
||||
txn.putFieldLong(this.getObjectId() + {{field.id}}, new {{name}}.{{field.log_type}}(this, value))
|
||||
{{~if ctype.need_set_children_root~}}
|
||||
value?.initRoot(this.getRoot())
|
||||
{{~end~}}
|
||||
} else {
|
||||
{{field.internal_name_with_this}} = value
|
||||
}
|
||||
}
|
||||
|
||||
{{~else~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
get {{field.convention_name}}(): {{db_ts_define_type ctype}} { return {{field.internal_name_with_this}} }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if is_abstract_type~}}
|
||||
static serialize{{name}}Any(_buf: ByteBuf, x: {{name}}) {
|
||||
if (x == null) { _buf.WriteInt(0); return }
|
||||
_buf.WriteInt(x.getTypeId())
|
||||
x.serialize(_buf)
|
||||
}
|
||||
|
||||
deserialize{{name}}Any(_buf: ByteBuf): {{name}}{
|
||||
let x: {{name}}
|
||||
switch (_buf.ReadInt()) {
|
||||
{{~ for child in x.hierarchy_not_abstract_children~}}
|
||||
case {{child.full_name}}.__ID__: x = new {{child.full_name}}(); break
|
||||
{{~end~}}
|
||||
default: throw new Error()
|
||||
}
|
||||
x.deserialize(_buf)
|
||||
return x
|
||||
}
|
||||
{{~else~}}
|
||||
serialize(_buf: ByteBuf) {
|
||||
_buf.WriteNumberAsLong(this.getObjectId())
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{ _buf.WriteInt(FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT)); {{db_ts_compatible_serialize '_buf' field.internal_name_with_this field.ctype}} }
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
deserialize(_buf: ByteBuf) {
|
||||
this.setObjectId(_buf.ReadLongAsNumber())
|
||||
while(_buf.NotEmpty) {
|
||||
let _tag_ = _buf.ReadInt()
|
||||
switch (_tag_) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
case FieldTag.{{tag_name field.ctype}} | ({{field.id}} << FieldTag.TAG_SHIFT) : { {{db_ts_compatible_deserialize '_buf' field.internal_name_with_this field.ctype}}; break; }
|
||||
{{~end~}}
|
||||
default: { _buf.SkipUnknownField(_tag_); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static readonly __ID__ = {{x.id}}
|
||||
getTypeId(): number { return {{name}}.__ID__ }
|
||||
{{~end~}}
|
||||
|
||||
initChildrenRoot(root: TKey) {
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
{{~if need_set_children_root field.ctype~}}
|
||||
{{field.internal_name_with_this}}?.initRoot(root)
|
||||
{{~end~}}
|
||||
{{~end}}
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '{{full_name}}{ '
|
||||
{{~ for field in hierarchy_fields~}}
|
||||
+ '{{field.convention_name}}:' + {{ts_to_string ('this.' + field.convention_name) field.ctype}} + ','
|
||||
{{~end~}}
|
||||
+ '}'
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
71
Luban/Luban.ClientServer/Templates/db/typescript/table.tpl
Normal file
71
Luban/Luban.ClientServer/Templates/db/typescript/table.tpl
Normal file
@@ -0,0 +1,71 @@
|
||||
{{
|
||||
name = x.name
|
||||
key_ttype = x.key_ttype
|
||||
value_ttype = x.value_ttype
|
||||
internal_table_type = x.internal_table_type
|
||||
}}
|
||||
|
||||
{{x.typescript_namespace_begin}}
|
||||
class {{internal_table_type}} extends TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> {
|
||||
constructor() {
|
||||
super({{x.table_uid}}, '{{x.full_name}}')
|
||||
}
|
||||
|
||||
newValue(): {{db_ts_define_type value_ttype}} { return new {{db_ts_define_type value_ttype}}() }
|
||||
|
||||
serializeKey(buf: ByteBuf, key: {{db_ts_define_type key_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'key' key_ttype}}
|
||||
}
|
||||
|
||||
serializeValue(buf: ByteBuf, value: {{db_ts_define_type value_ttype}}) {
|
||||
{{db_ts_compatible_serialize_without_segment 'buf' 'value' value_ttype}}
|
||||
}
|
||||
|
||||
deserializeKey(buf: ByteBuf): {{db_ts_define_type key_ttype}} {
|
||||
let key: {{db_ts_define_type key_ttype}}
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'key' key_ttype}}
|
||||
return key
|
||||
}
|
||||
|
||||
deserializeValue(buf: ByteBuf): {{db_ts_define_type value_ttype}} {
|
||||
let value = new {{db_ts_define_type value_ttype}}()
|
||||
{{db_ts_compatible_deserialize_without_segment 'buf' 'value' value_ttype}}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
export class {{name}} {
|
||||
static readonly _table = new {{internal_table_type}}();
|
||||
static get table(): TxnTableGeneric<{{db_ts_define_type key_ttype}},{{db_ts_define_type value_ttype}}> { return this._table }
|
||||
|
||||
static getAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.getAsync(key);
|
||||
}
|
||||
|
||||
static createIfNotExistAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.createIfNotExistAsync(key);
|
||||
}
|
||||
|
||||
static insertAsync(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.insertAsync(key, value);
|
||||
}
|
||||
|
||||
static removeAsync(key: {{db_ts_define_type key_ttype}}): Promise<void> {
|
||||
return {{name}}._table.removeAsync(key);
|
||||
}
|
||||
|
||||
static put(key: {{db_ts_define_type key_ttype}}, value: {{db_ts_define_type value_ttype}}): Promise<void> {
|
||||
return {{name}}._table.putAsync(key, value);
|
||||
}
|
||||
|
||||
static selectAsync(key: {{db_ts_define_type key_ttype}}): Promise<{{db_ts_define_type value_ttype}}> {
|
||||
return {{name}}._table.selectAsync(key);
|
||||
}
|
||||
}
|
||||
|
||||
{{x.typescript_namespace_end}}
|
@@ -0,0 +1,8 @@
|
||||
|
||||
export class {{name}} {
|
||||
static readonly tableList: TxnTable[] = [
|
||||
{{~ for table in tables~}}
|
||||
{{table.full_name}}.table,
|
||||
{{~end}}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user