{"id":21954413,"url":"https://github.com/the-red-pixel/kraitudao","last_synced_at":"2026-04-24T21:32:01.350Z","repository":{"id":106017530,"uuid":"121346198","full_name":"the-red-pixel/KraitUDAO","owner":"the-red-pixel","description":"超轻量级统一数据访问对象框架","archived":false,"fork":false,"pushed_at":"2019-02-03T17:41:48.000Z","size":286,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-09T06:02:33.805Z","etag":null,"topics":["configuration","dao","database","kucro3"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/the-red-pixel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-13T06:15:13.000Z","updated_at":"2019-04-27T08:12:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f9013ad-992d-45aa-9232-8828d24bfb1f","html_url":"https://github.com/the-red-pixel/KraitUDAO","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/the-red-pixel/KraitUDAO","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-red-pixel%2FKraitUDAO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-red-pixel%2FKraitUDAO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-red-pixel%2FKraitUDAO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-red-pixel%2FKraitUDAO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/the-red-pixel","download_url":"https://codeload.github.com/the-red-pixel/KraitUDAO/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-red-pixel%2FKraitUDAO/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","dao","database","kucro3"],"created_at":"2024-11-29T07:18:31.146Z","updated_at":"2026-04-24T21:32:01.330Z","avatar_url":"https://github.com/the-red-pixel.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KraitUDAO\n\u003e Krait Universal Data Access Object  \n\u003e 超轻量级统一数据管理框架\n\n## 数据对象类型\n\n### 唯一数据对象 (UniqueDataObject)\n\n只含有一个主键值对象的数据对象(在数据存储介质中只能存在一个此主键值对应的数据条目)。  \n使用```@com.theredpixelteam.kraitudao.annotations.Unique```来注解数据对象类来表示该类所声明的数据对象为唯一数据对象（两种数据对象类型的注解不允许同时出现），如下：\n```Java\n@Unique\npublic class Example {\n    // ... your declarations here\n}\n```\n而其主键必须使用```@com.theredpixelteam.kraitudao.annotations.Key```注解  \n并且规定唯一数据对象中只含有一个主键，不允许出现副键。故以下两种注解：\n\n- ```@com.theredpixelteam.kraitudao.annotations.PrimaryKey```\n- ```@com.theredpixelteam.kraitudao.annotations.SecondaryKey```   \n\n中的任何一种都不允许出现在一个唯一数据对象类中。如下：\n```Java\n@Unique\npublic class Example {\n    @Key // 不另取名称，主键值在存储介质中即名为 \"exampleKey\"\n    private int exampleKey;\n    \n    // ... other declarations here\n}\n```\n其中键值名称可以重新定义，如下：\n```Java\n@Unique\npublic class Example {\n    @Key(\"KEY\") // 不另取名称为 \"KEY\"\n    private int exampleKey;\n    \n    // ... other declarations here\n}\n```\n值对象必须使用```@com.theredpixelteam.kraitudao.annotations.Value```注解，一个简单的唯一数据对象类应为如下形式：\n```Java\n@Unique\npublic class Example {\n    @Key\n    private int exampleKey;\n    \n    @Value\n    private int exampleValue;\n}\n```\n同样，值对象也可以重新定义名称：\n```Java\n@Unique\npublic class Example {\n    @Key(\"KEY\") 更名为 \"KEY\"\n    private int exampleKey;\n    \n    @Value(\"VALUE\") // 更名为 \"VALUE\"\n    private int exampleValue;\n}\n```\n\n### 可重复数据对象 (MultipleDataObject)\n包含有一个主键值对象并且可以包含多个副键值对象的数据对象（在存储介质中一个主键值可以对应多个数据条目，而这些数据条目是跟据副键值来区分的，副键值不一定需要具有索引作用）  \n使用```@com.theredpixelteam.kraitudao.annotations.Multiple```来注解数据对象类l来表示该类所声明的数据对象为可重复数据对象（两种数据对象类型的注解不允许同时出现），如下：\n```Java\n@Multiple\npublic class Example {\n    // ... your declarations here\n}\n```\n可重复数据对象支持一个主键对象与多个副键值对象，用以下其中一个来注解域：\n\n- ```@com.theredpixelteam.kraitudao.annotations.PrimaryKey```\n- ```@com.theredpixelteam.kraitudao.annotations.SecondaryKey``` \n\n并且可以有多个```@SecondaryKey```注解的域而只允许且必须有一个```@PrimaryKey```注解的域。不允许使用```@com.theredpixelteam.kraitudao.annotations.Key```来注解任何域。如下：\n```Java\n@Multiple\npublic class Example {\n    @PrimaryKey\n    private int primaryKey;\n    \n    @SecondaryKey\n    priavte int secondaryKey1;\n    \n    @SecondaryKey\n    private int secondaryKey2;\n    \n    // ... other declarations here\n}\n```\n并且所有键与副键值都可以重新命名：\n```Java\n@Multiple\npublic class Example {\n    @PrimaryKey(\"KEY0\") // 更名为 \"KEY0\"\n    private int primaryKey;\n    \n    @SecondaryKey(\"KEY1\") // 更名为 \"KEY1\"\n    priavte int secondaryKey1;\n    \n    @SecondaryKey(\"KEY2\") // 更名为 \"KEY2\"\n    private int secondaryKey2;\n    \n    // ... other declarations here\n}\n```\n值对象必须使用```@com.theredpixelteam.kraitudao.annotations.Value```注解，使用规则与上文相同。\n\n## 值与键值对象的命名\n\n- 所有键值与键都默认使用其对应的域的名称，并且都是可以通过修改注解来重新命名的。  \n- 所有值与键值对象的名称并不强制大小写敏感，这与框架的具体实现方式相关，因此不建议使用字母相同且仅有大小写不相同的名称。\n- 请不要使用中文名称以导致各种奇怪的问题。\n\n## 原生数据\n通常情况下，原生数据包括以下类型：\n\n- boolean *(java.lang.Boolean)*\n- byte *(java.lang.Byte)*\n- short *(java.lang.Short)*\n- char *(java.lang.Character)*\n- int *(java.lang.Integer)*\n- long *(java.lang.Long)*\n- float *(java.lang.Float)*\n- double *(java.lang.Double)*\n- java.lang.String\n- java.math.BigDecimal\n\n原生数据即不需要通过任何的处理，直接、必须由具体实现支持的，可以直接或以某种形式存储入存储介质中而不需要使用者预处理的数据类型。 本数据结构框架同时要求具体实现对于非原生数据的支持，但需要使用者指定处理方式，详见下文。\n\n## 非原生数据类型的处理\n对于非原生数据结构，需要使用者指定将其拆解为原生数据的方式，才能将其存储进存储介质之中。而使用者指定的这一方式我们称其为```ExpandRule```（扩展规则）。\n\n### 内建扩展规则\n\n未完待续\n\n### 类全局扩展规则\n\n未完待续\n\n### 域扩展规则\n\n未完待续\n\n## 数据对象类继承\n\n对于数据对象类，我们允许继承关系的存在，并且我们相信因此数据对象类的设计与操作会更加灵活。为了保证最少的误操作可能性，我们对继承的声明进行了严格的规定，大部分继承关系都需要注解声明。  \n假设我们有一个唯一数据对象类，如下（可重复数据对象类的规定与下文的说明都相同，并且下文的说明都将基于这个例子）：\n```Java\n@Unique\npublic class House {\n    @Key\n    private int Lady;\n    \n    @Value\n    private int Tom;\n    \n    private int Jerry;\n}\n```\n\n你可能发现我们的小老鼠**Jerry**没有被标注为值对象，不要着急！下文它会发挥它的作用。  \n有一天，**Tom**决定今天一定要抓住**Jerry**，趁**Jerry**不在家，**Tom**叫来了他的好朋友**Butch**，这时候家里便多了一只猫**Butch**。这时候我们不需要对我们的房子大动干戈，要表示多了一只猫的情况，我们只需要继承```House```即可，就像这样：\n```Java\n@Inheritance // 不要忘记这个！\n@Unique\npublic class HouseWith2Cats extends House {\n    @Value\n    public int Butch;\n}\n```\n\n这时候我们的数据对象里就包含了```Tom```和```Butch```两个值对象了。  \n这个时候**Jerry**回来了，但是**Jerry**在这个房子里的地位是毫无疑问的，不需要重新声明，只需要像这样即可：\n```Java\n@Inheritance // 千万不要忘记这个！\n@Unique\n@InheriteValue(field = \"Jerry\" /*, name = \"foo\" */) // 你要是想的话，也可以给Jerry改个名字\npublic class HouseWith2CatsAnd1Mouse extends HouseWith2Cats {\n    // 不需要其它操作\n}\n```\n\n此时我们的数据对象里就包含了```Tom```,```Butch```和```Jerry```三个值对象了。  \n**注意：使用```@InheriteValue```,```@InheriteKey```,```@InheritePrimaryKey```,```@InheriteSecondaryKey```时，对于继承的域的扫描方式，使用标准注解解析规则(```StandardDataObjectInterpreter```)时，规定如果存在继承关系，且没有使用其他参数，则从当前类向超类扫描，找到第一个符合名称的域为止。若没有找到，则会抛出解析错误。**\n\n### 附加参数\n\n* **```source``` 用来指定域所在的类，若该类不存在此域，或此类不在继承关系中，则抛出解析错误。**  \n例如：\n```Java\npublic class ExampleA {\n    private int value;\n}\n\npublic class ExampleB extends ExampleA {\n    private int value;\n}\n\n@Unique\n@InheriteValue(field = \"value\", source = ExampleA.class)\npublic class Example extends ExampleB {\n    @Key\n    private int key;\n}\n```\n如果我们置```source = ExampleA.class```，则继承的值域为```ExampleA```中的```value```，否则由于自下向上扫描的机制，继承的值域为```ExampleB```中的```value```。而若```ExampleA```中不存在```value```域，则会抛出解析错误。\n\n* **```strict``` 如果置```strict = true```则会严格检查继承关系中的```@Inheritance```注解，反之不严格检查。**  \n例如如下继承关系：\n```Java\npublic class ExampleBase {\n    private int value;\n}\n\n@Unique\n@InheriteValue(field = \"value\" /*, strict = false*/)\npublic class Example extends ExampleBase {\n    // ...\n}\n```\n在这种情况下，如果我们置```strict = true```：\n```Java\n@Unique\n@InheriteValue(field = \"value\", strict = true)\npublic class Example extends Example Base {\n    // ...\n}\n```\n则会抛出解析错误，由于域```value```存在于父类```ExampleBase```中，但```Exmaple```并没有使用```@Inheritance```进行标注，并且父类并不是一个标准的数据对象类。简言之，在```strict = true```时，如果扫描域时，正在扫描的类没有被```@Inheritance```注解，则扫描过程会在当前被扫描的类停止，若```strict = false```（默认）则会继续扫描。  \n以下示例中就不会因此抛出解析错误：\n```Java\n@Unique\npublic class ExampleA {\n    @Key\n    private int key;\n    \n    private int value;\n}\n\n@Unique\n@Inheritance\n@InheriteValue(field = \"value\", strict = true)\npublic class Example {\n    // ...\n}\n```\n\n未完待续","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-red-pixel%2Fkraitudao","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-red-pixel%2Fkraitudao","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-red-pixel%2Fkraitudao/lists"}