[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6ACP4DQ8F7D4X38QE4XK8V1":3,"skill-same:01M6ACP4DQ8F7D4X38QE4XK8V1":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":17,"categories":18,"keywords":29,"publishedAt":32,"linkOnly":33,"markdownContent":34,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":41,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":7,"updatedAt":44,"install":45,"resources":58},"01M6ACP4DQ8F7D4X38QE4XK8V1","manage-java-patterns","Java 模式管理",null,"","apache\u002Fofbiz-plugins","apache","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F47359?v=4","01M6AC83E6K4FDKK7HZ8WNMQKE","The Apache Software Foundation","01M6ACMJJ1Q4WYATY4GXZ2FAVD",178,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-java-patterns\u002FSKILL.md",[19,24],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TQZN6R52WBJ9H8NRMQM","软件开发工程师","PROFESSION","适用职业",{"categoryNo":25,"categoryName":26,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BT7QVANT4709358VEJK53E","代码实现","SCENARIO","使用场景",[30,31],"java","manage java patterns","2026-11-10 10:12:30",false,"\u003C!--\nLicensed to the Apache Software Foundation (ASF) under one\nor more contributor license agreements.  See the NOTICE file\ndistributed with this work for additional information\nregarding copyright ownership.  The ASF licenses this file\nto you under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance\nwith the License.  You may obtain a copy of the License at\n\nhttp:\u002F\u002Fwww.apache.org\u002Flicenses\u002FLICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an\n\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, either express or implied.  See the License for the\nspecific language governing permissions and limitations\nunder the License.\n-->\n\n---\nname: manage-java-patterns\ndescription: |-\n  - Foundational OFBiz Java coding patterns.\n  - Architectural roles (Helper, Worker, Reader) and domain logic structure.\n  - Shared standards for logging, security, data retrieval, and validation.\n  - Prerequisite for manage-java and manage-java-events.\n---\n\n# Skill: manage-java-patterns\n## Goal\nEstablish a consistent foundation for all OFBiz Java development. This skill standardizes cross-cutting concerns—including architectural roles (Helpers, Workers, Readers), logging, exception handling, localization, and high-performance data patterns—to ensure code is secure, maintainable, and idiomatic. It is the primary reference for developing or refactoring any Java-based business logic, data access, or service orchestration.\n\n## Triggers\n**ALWAYS** read this skill when:\n- Creating or modifying **any** Java code in an OFBiz component, especially architectural roles like **Helpers**, **Workers**, or **Readers**.\n- Designing data retrieval, persistence logic, or service orchestration.\n- Implementing UI messaging, logging, or localized error handling in Java.\n\n## Core Architectural Roles\nUse these patterns when **designing class boundaries** and deciding how to structure your domain logic vs. utility logic:\n\n> [!IMPORTANT]\n> **Check and Re-use First**: Before writing new logic, ALWAYS search for existing classes in the component or framework (e.g., `OrderReadHelper`, `ProductWorker`). Re-use or extend existing methodology instead of creating redundant one-offs.\n\n- **Helper Pattern (`Helper`, `ReadHelper`)**:\n    - **Purpose**: Stateful domain-specific wrapper around a primary `GenericValue`.\n    - **Structure**: Constructor takes primary `GenericValue`. Best practice: Dual constructor with `Delegator` + `id`.\n    - **Example**: `OrderReadHelper` (See Examples).\n- **Worker Pattern (`Worker`)**:\n    - **Purpose**: Static utility class for stateless logic (calculations, checks).\n    - **Structure**: Private constructor. All methods are `public static`.\n    - **Example**: `ProductWorker` (See Examples).\n\n---\n\n## Rules & Procedures (Shared Patterns)\nUse these patterns for **implementing data retrieval**, batch writes, and handling framework types like `GenericValue`, `Delegator`, or `Timestamp`. These are the **\"Shared Standards\"** for all OFBiz Java code:\n\n### Data & Persistence\n- **Standard Retrieval (`EntityQuery`)**: \n    - **Preferred**: `EntityQuery.use(delegator).from(\"Entity\").where(...).queryOne();`\n    - **PK Shortcut**: Use `delegator.findOne(entity, pkMap, useCache)` ONLY if you have the full PK map and are explicit about `useCache`.\n- **Related Records (`getRelated`)**: Always include a sort list (e.g., `UtilMisc.toList(\"seqId\")`) to avoid nondeterministic results.\n- **Optimization**:\n    - **Fields**: Use `.select(\"field1\", \"field2\")` to reduce memory footprint.\n    - **Date-Effective**: Use `.filterByDate()` correctly for temporal entities.\n    - **Pagination**: Use `EntityFindOptions` (`setMaxRows`, `setOffset`) for large lists.\n    - **Caching**: Use `.cache(true)` for reference data (Types\u002FStatuses); `.cache(false)` for transactional freshness.\n- **Creation Strategy**:\n    - **System IDs**: Use `delegator.createSetNextSeqId(gv)`.\n    - **Known PKs**: Use `delegator.makeValue(entity, fieldMap)` + `delegator.create(gv)`.\n- **Batch Processing**: Use `delegator.storeAll(List)` in loops. For large sets, use the **Large Set Chunking** pattern (See Examples).\n\n### Framework Utilities\n- **Safe List Handling (`EntityUtil`)**: Always use `EntityUtil.getFirst(list)` to avoid `IndexOutOfBoundsException`. Use `EntityUtil.filterByDate()` and `EntityUtil.orderBy()` for in-memory manipulation.\n- **Collection Builders (`UtilMisc`)**: Always use `UtilMisc.toMap(...)` and `UtilMisc.toList(...)` for concise, standard instantiation.\n- **Date & Timestamps**: Always use `UtilDateTime`. \n    - **Current**: `UtilDateTime.nowTimestamp()`. \n    - **Parsing**: Never use `Timestamp.valueOf(String)`; use locale-aware parsing utilities instead.\n- **Mandatory TRIMMING**: Always trim incoming `String` parameters using `UtilValidate.isEmpty()` \u002F `String.trim()` before logic or persistence.\n\n### Communication & Error Handling\n- **Logging Standard**: Always define `private static final String MODULE = MyClass.class.getName();`.\n    - **PII Warning**: Never log passwords, tokens, or personal identifiers.\n- **Localization**: Only localize text at the user boundary (Events\u002FServices). Use `UtilProperties.getMessage(resource, key, locale)`.\n- **Exception Strategy**: Helpers\u002FWorkers should **throw** checked exceptions. Services\u002FEvents should **catch** and map them to localized user-friendly errors. Always catch-all `Exception` at the top level to prevent crashes.\n- **Service Invocation**: Always include `userLogin`, `locale`, and `timeZone` in the context. (See Examples).\n\n---\n\n## Guardrails\n- **Naming**: Ensure suffixes `Helper` or `Worker` are used appropriately.\n- **Statelessness**: Workers and Service\u002FEvent methods **MUST** be stateless.\n- **Thread Safety**: Never use non-final static variables for request\u002Fservice state.\n- **Helper Scope**: Helpers should not hold `LocalDispatcher` references unless orchestrating services.\n- **Null Safety**: `UtilValidate.isEmpty()` is for Strings\u002FCollections; use `null` checks for `GenericValue`.\n\n---\n\n## Bad Practices & Anti-patterns\nAvoid these common pitfalls that lead to memory leaks, performance degradation, or data inconsistency.\n\n### Anti-pattern: The \"Loop-of-Death\"\n**Pitfall**: Calling `delegator.create()` or `gv.store()` inside a loop for a large number of records. This creates a massive transaction overhead and can lead to timeouts.\n- **❌ Bad (Sequential Writes)**:\n  ```java\n  for (GenericValue item : items) {\n      item.set(\"statusId\", \"COMPLETED\");\n      item.store(); \u002F\u002F Individual DB hit per iteration\n  }\n  ```\n- **✅ Good (Batch Write)**: \n  ```java\n  \u002F\u002F Collect and store all at once\n  delegator.storeAll(items); \n  ```\n\n### Anti-pattern: Silent Mutation (Missing `.store()`)\n**Pitfall**: Mutating a `GenericValue` object retrieved from the database and assuming it auto-saves. Unlike Hibernate, OFBiz `GenericValue` objects are snapshots.\n- **❌ Bad**:\n  ```java\n  GenericValue product = EntityQuery.use(delegator).from(\"Product\").where(\"productId\", id).queryOne();\n  product.set(\"productName\", newName);\n  \u002F\u002F Missing product.store() - change is lost!\n  ```\n- **✅ Good**: \n  ```java\n  product.set(\"productName\", newName);\n  product.store();\n  ```\n\n### Anti-pattern: The Unclosed `EntityListIterator`\n**Pitfall**: Failing to close an `EntityListIterator` (ELI). This leaves database cursors open, eventually exhausting the connection pool.\n- **❌ Bad**:\n  ```java\n  EntityListIterator eli = EntityQuery.use(delegator).from(\"OrderHeader\").queryIterator();\n  while (eli.next() != null) { ... }\n  \u002F\u002F ELI never closed!\n  ```\n- **✅ Good (Try-with-resources)**: \n  ```java\n  try (EntityListIterator eli = EntityQuery.use(delegator).from(\"OrderHeader\").queryIterator()) {\n      while (eli.next() != null) { ... }\n  } \u002F\u002F Automatically closed\n  ```\n\n### Anti-pattern: In-Memory Filtering Overkill\n**Pitfall**: Fetching a massive list into memory using `queryList()` and then filtering it using Java streams or loops, instead of letting the database do its job.\n- **❌ Bad**:\n  ```java\n  List\u003CGenericValue> allOrders = EntityQuery.use(delegator).from(\"OrderHeader\").queryList();\n  List\u003CGenericValue> activeOrders = allOrders.stream()\n      .filter(o -> \"ORDER_APPROVED\".equals(o.getString(\"statusId\")))\n      .collect(Collectors.toList());\n  ```\n- **✅ Good**: \n  ```java\n  List\u003CGenericValue> activeOrders = EntityQuery.use(delegator).from(\"OrderHeader\")\n          .where(\"statusId\", \"ORDER_APPROVED\").queryList();\n  ```\n\n---\n\n## Common Code Patterns (Examples)\n\n### Helper Pattern (Dual Constructors)\n```java\npublic class MyOrderHelper {\n    private GenericValue orderHeader;\n    private Delegator delegator;\n\n    public MyOrderHelper(GenericValue orderHeader) { \n        this.orderHeader = orderHeader; \n        this.delegator = orderHeader.getDelegator();\n    }\n\n    public MyOrderHelper(Delegator delegator, String orderId) throws GenericEntityException {\n        this.delegator = delegator;\n        this.orderHeader = EntityQuery.use(delegator).from(\"OrderHeader\")\n                .where(\"orderId\", orderId).queryOne();\n    }\n\n    public List\u003CGenericValue> getValidItems(boolean useCache) throws GenericEntityException {\n        if (orderHeader == null) return Collections.emptyList();\n        return orderHeader.getRelated(\"OrderItem\", null, UtilMisc.toList(\"itemSeqId\"), useCache);\n    }\n}\n```\n\n### Batch Writes & Large Set Chunking\n```java\nfinal int CHUNK = 500;\nList\u003CGenericValue> buffer = new ArrayList\u003C>(CHUNK);\n\ntry (EntityListIterator eli = EntityQuery.use(delegator)\n        .from(\"OrderItem\")\n        .where(\"statusId\", \"ITEM_APPROVED\")\n        .queryIterator()) {\n\n    GenericValue gv;\n    while ((gv = eli.next()) != null) {\n        \u002F\u002F mutate gv\n        buffer.add(gv);\n\n        if (buffer.size() >= CHUNK) {\n            delegator.storeAll(buffer);\n            buffer.clear();\n        }\n    }\n    if (!buffer.isEmpty()) delegator.storeAll(buffer);\n}\n```\n\n### Standard Service Invocation Context\n```java\nMap\u003CString, Object> ctx = UtilMisc.toMap(\n  \"userLogin\", userLogin,\n  \"locale\", locale,\n  \"timeZone\", timeZone,\n  \"productId\", productId\n);\nMap\u003CString, Object> res = dispatcher.runSync(\"myService\", ctx);\nif (ServiceUtil.isError(res)) {\n    return ServiceUtil.returnError(ServiceUtil.getErrorMessage(res));\n}\n```\n",{},"trunk","6c6c27710443de03e9247605d33a2e2f5bc3d1e2","ai-agent-skills\u002Fmanage-java-patterns",222,"https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins","https:\u002F\u002Fofbiz.apache.org\u002F","https:\u002F\u002Fgithub.com\u002Fapache","https:\u002F\u002Fwww.apache.org\u002F","2026-11-12 22:04:06",{"source":9,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add apache\u002Fofbiz-plugins --skill manage-java-patterns",{"tool":51,"command":52},"bunx","bunx skills add apache\u002Fofbiz-plugins --skill manage-java-patterns",{"tool":54,"command":55},"pnpm","pnpm dlx skills add apache\u002Fofbiz-plugins --skill manage-java-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-java-patterns\u002FSKILL.md",true,[],[60,72,84,98,112,126],{"skillNo":61,"name":62,"nameZh":63,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":64,"categories":65,"keywords":70,"publishedAt":32},"01M6ACQSN90YKJZ92MQ52D9R8H","prepush-readiness","推送前就绪检查","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fprepush-readiness\u002FSKILL.md",[66,67],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":68,"categoryName":69,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BR5V701HCN066VEP7H4812","代码仓库协作管理",[71],"prepush readiness",{"skillNo":73,"name":74,"nameZh":75,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":76,"categories":77,"keywords":82,"publishedAt":32},"01M6ACQPR1WRA751V4DXVC3AHF","manage-webapps","Web 应用管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-webapps\u002FSKILL.md",[78,79],{"categoryNo":20,"categoryName":21,"taxonomyType":22,"taxonomyTypeDesc":23},{"categoryNo":80,"categoryName":81,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BWKS60NTYJHFE9FQSXGDKS","低代码应用开发",[83],"manage webapps",{"skillNo":85,"name":86,"nameZh":87,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":88,"categories":89,"keywords":96,"publishedAt":32},"01M6ACQMCX8Z7NY2CE08NCV6ND","manage-themes","主题管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-themes\u002FSKILL.md",[90,93],{"categoryNo":91,"categoryName":92,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TQMKHSMFVQHR2KYAEVN","界面设计师",{"categoryNo":94,"categoryName":95,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BRASNPVNJVQQJ4KZX8XM5D","前端开发与界面实现",[97],"manage themes",{"skillNo":99,"name":100,"nameZh":101,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":102,"categories":103,"keywords":110,"publishedAt":32},"01M6ACQHYN20AFWF6TKK4RGQ8A","manage-tests","测试管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-tests\u002FSKILL.md",[104,107],{"categoryNo":105,"categoryName":106,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQGD5WG86P4AQ5GPSSKBFR","测试工程师",{"categoryNo":108,"categoryName":109,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BQJH394GT47X57A9Q8G7HX","测试与质量保障",[111],"manage tests",{"skillNo":113,"name":114,"nameZh":115,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":116,"categories":117,"keywords":124,"publishedAt":32},"01M6ACQFRMW7R45YD3HRAXPGWF","manage-templates","模板管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-templates\u002FSKILL.md",[118,121],{"categoryNo":119,"categoryName":120,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BQ6TK1MPB82068236GSXDE","文档处理",{"categoryNo":122,"categoryName":123,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8BQ6TPH3VQWKQZXV7EPF8VZ","办公行政人员",[125],"manage templates",{"skillNo":127,"name":128,"nameZh":129,"description":7,"descriptionZh":8,"repositoryFullName":9,"ownerLogin":10,"ownerAvatarUrl":11,"ownerAccountNo":12,"ownerDisplayName":13,"repositoryNo":14,"starsCount":15,"licenseSpdxId":16,"licenseFileUrl":7,"sourceHtmlUrl":130,"categories":131,"keywords":138,"publishedAt":32},"01M6ACQCSSDZQMD8VX2K3WRR93","manage-strategies","策略管理","https:\u002F\u002Fgithub.com\u002Fapache\u002Fofbiz-plugins\u002Fblob\u002Ftrunk\u002Fai-agent-skills\u002Fmanage-strategies\u002FSKILL.md",[132,135],{"categoryNo":133,"categoryName":134,"taxonomyType":27,"taxonomyTypeDesc":28},"01M8BTXF8K9DFQC4T4TXVH0NMZ","策略与托管设置管理",{"categoryNo":136,"categoryName":137,"taxonomyType":22,"taxonomyTypeDesc":23},"01M8C6RQ852C9AEJFCBGG1YA7S","IT 管理员",[139],"manage strategies"]