{"id":22281747,"url":"https://github.com/xjodoin/torpedoquery","last_synced_at":"2025-04-05T23:05:01.268Z","repository":{"id":1711655,"uuid":"2441239","full_name":"xjodoin/torpedoquery","owner":"xjodoin","description":"Type safe Hibernate query builder (HQL)","archived":false,"fork":false,"pushed_at":"2025-03-01T03:12:35.000Z","size":1467,"stargazers_count":82,"open_issues_count":8,"forks_count":21,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-29T22:04:00.700Z","etag":null,"topics":["hibernate","hql","j2ee","java","java-8","java-library","jpa","query-builder"],"latest_commit_sha":null,"homepage":"torpedoquery.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xjodoin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/contributing.md","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":"2011-09-23T01:09:41.000Z","updated_at":"2025-03-01T03:08:46.000Z","dependencies_parsed_at":"2023-11-24T19:30:47.813Z","dependency_job_id":"7c993ff8-9964-40ee-8217-09d131a84b19","html_url":"https://github.com/xjodoin/torpedoquery","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xjodoin%2Ftorpedoquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xjodoin%2Ftorpedoquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xjodoin%2Ftorpedoquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xjodoin%2Ftorpedoquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xjodoin","download_url":"https://codeload.github.com/xjodoin/torpedoquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411226,"owners_count":20934653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["hibernate","hql","j2ee","java","java-8","java-library","jpa","query-builder"],"created_at":"2024-12-03T16:21:35.555Z","updated_at":"2025-04-05T23:05:01.238Z","avatar_url":"https://github.com/xjodoin.png","language":"Java","funding_links":["https://tidelift.com/security"],"categories":["数据库开发"],"sub_categories":[],"readme":"TorpedoQuery\n============\n\n## Status\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.torpedoquery/org.torpedoquery/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.torpedoquery/org.torpedoquery)\n[![license](https://img.shields.io/github/license/xjodoin/torpedoquery.svg)](https://github.com/xjodoin/torpedoquery/blob/master/LICENSE)\n\n\n\n\nSimple and powerful query builder for your project. Can be use with any existing Hibernate or JPA application.  \nStop wasting your time to maintain complex HQL queries and start today with the new generation of query builder.\n\n**Torpedo Query Quick Start Guide**\n\n**Step 1:** **Set Up Your Environment**\n\nStart by importing the necessary classes from the Torpedo Query library. This will enable you to use the query methods directly.\n```java\nimport static org.torpedoquery.jpa.Torpedo.*;\n```\n\n**Step 2:** **Simple Select Query**\n\nA basic query retrieves all columns for the Entity rows. This can be compared to SQL's `SELECT *`.\n```java\nEntity entity = from(Entity.class);\norg.torpedoquery.jpa.Query\u003cEntity\u003e selectQuery = select(entity);\n```\n\n**Step 3:** **Scalar Queries**\n\nScalar queries return specific columns rather than the entire row. This is useful when you only need particular data points.\n```java\nEntity entity = from(Entity.class);\norg.torpedoquery.jpa.Query\u003cString\u003e scalarQuery = select(entity.getCode());\n```\n\n**Step 4:** **Executing Your Query**\n\nAfter constructing your query, execute it using an `EntityManager` to retrieve results. Here, we're getting a list of entities.\n```java\nEntity entity = from(Entity.class);\norg.torpedoquery.jpa.Query\u003cEntity\u003e selectQuery = select(entity);\nList\u003cEntity\u003e entityList = selectQuery.list(entityManager);\n```\n\n**Step 5:** **Adding Conditions**\n\nQueries can be filtered using conditions. Here, we're querying entities with a specific code.\n```java\nEntity entity = from(Entity.class);\nwhere(entity.getCode()).eq(\"mycode\");\norg.torpedoquery.jpa.Query\u003cEntity\u003e conditionalQuery = select(entity);\n```\nThe `.eq(\"mycode\")` is equivalent to SQL's `WHERE code = 'mycode'`.\n\n**Step 6:** **Joining Entities**\n\nTorpedo Query supports joining tables. Here's how you can create an inner join between `Entity` and its associated `SubEntity`.\n```java\nEntity entity = from(Entity.class);\nSubEntity subEntity = innerJoin(entity.getSubEntities());\norg.torpedoquery.jpa.Query\u003cString[]\u003e joinQuery = select(entity.getCode(), subEntity.getName());\n```\nThe result will be a combination of `entity.getCode()` and `subEntity.getName()` for each matching row.\n\n**Step 7:** **Grouping Conditions**\n\nComplex conditions can be grouped together using logical operations like `and` \u0026 `or`.\n```java\nEntity fromEntity = from(Entity.class);\nOnGoingLogicalCondition groupedCondition = condition(fromEntity.getCode()).eq(\"test\")\n                                               .or(fromEntity.getCode()).eq(\"test2\");\nwhere(fromEntity.getName()).eq(\"test\").and(groupedCondition);\nQuery\u003cEntity\u003e groupedSelect = select(fromEntity);\n```\nHere, we're selecting entities where the name equals \"test\" and the code is either \"test\" or \"test2\".\n\n---\n\nRemember, always refer to the official documentation of Torpedo Query for a comprehensive understanding and best practices. This guide is meant to get you started quickly, but the library offers much more flexibility and depth.\n\n\n#### How to Improve It ####\n\nCreate your own fork of [xjodoin/torpedoquery](https://github.com/xjodoin/torpedoquery)\n\nTo share your changes, [submit a pull request](https://github.com/xjodoin/torpedoquery/pull/new/master).\n\nDon't forget to add new units tests on your change.\n\n\n#### License ####\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n  \n## Security contact information\n\nTo report a security vulnerability, please use the\n[Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxjodoin%2Ftorpedoquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxjodoin%2Ftorpedoquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxjodoin%2Ftorpedoquery/lists"}