{"id":19435934,"url":"https://github.com/ralscha/constgen","last_synced_at":"2025-04-24T21:30:44.696Z","repository":{"id":54276129,"uuid":"43112503","full_name":"ralscha/constgen","owner":"ralscha","description":"Constant Generator","archived":false,"fork":false,"pushed_at":"2025-03-20T03:14:59.000Z","size":362,"stargazers_count":3,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T11:36:30.573Z","etag":null,"topics":["annotation-processor","java"],"latest_commit_sha":null,"homepage":null,"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/ralscha.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":"2015-09-25T06:01:19.000Z","updated_at":"2025-03-20T03:15:02.000Z","dependencies_parsed_at":"2023-01-30T19:15:57.050Z","dependency_job_id":"d3217090-e531-4444-8427-9d1e1fcdc8b3","html_url":"https://github.com/ralscha/constgen","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fconstgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fconstgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fconstgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralscha%2Fconstgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralscha","download_url":"https://codeload.github.com/ralscha/constgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250712878,"owners_count":21475093,"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":["annotation-processor","java"],"created_at":"2024-11-10T15:08:28.934Z","updated_at":"2025-04-24T21:30:44.285Z","avatar_url":"https://github.com/ralscha.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## constgen\n\n![Test Status](https://github.com/ralscha/constgen/workflows/test/badge.svg)\n\n## Overview\n\n*constgen* is a Java Annotation Processor that scans for classes annotated with ```org.springframework.data.mongodb.core.mapping.Document``` or\n```org.mongodb.morphia.annotations.Entity```. For every annotated class *constgen* creates an additional Java class with the name **C***classname*. This new class contains class variables for every field from the origin class.\n\n\n## Example\n*Source class*\n```\n@Document\npublic class User {\n\tprivate String id;\n\tprivate String email;\n\tprivate String passwordResetToken;\n\tprivate Date passwordResetTokenValidUntil;\n\tprivate boolean deleted;\n}\n```\n\n*Generated class*\n```\npublic final class CUser {\n  public static final String deleted = \"deleted\";  \n  public static final String email = \"email\";\n  public static final String id = \"id\";   \n  public static final String passwordResetToken = \"passwordResetToken\";\n  public static final String passwordResetTokenValidUntil = \"passwordResetTokenValidUntil\";   \n}\n```\n\n## Use Case\n\nWhen you write queries with Morphia or Spring Data MongoDB you need to specify the fields with String parameters.\nIf you have a typo in a field name MongoDB will not complain because it is schemaless. \nThe C classes help you to make this process a little less error prone. In an IDE you will have code completion and it is more refactor friendly. When somebody removes or renames a field you will immediately see compiler errors. \n\n*With String*\n```\n\tUser user = mongoTemplate.findAndModify(\n\t\t\tQuery.query(Criteria.where(\"email\").is(\"test@test.com\")\n\t\t\t                    .and(\"deleted\").is(false)),\n\t\t\tUpdate.update(\"passwordResetTokenValidUntil\", new Date())\n\t\t\t      .set(\"passwordResetToken\", \"test_token\"),\n\t\t\tFindAndModifyOptions.options().returnNew(true), User.class);\n```\t\t\n\n*With C class*\t\t\n```\t\t\n\tUser user = this.mongoTemplate.findAndModify(\n\t\t\tQuery.query(Criteria.where(CUser.email).is(\"test@test.com\")\n\t\t\t                    .and(CUser.deleted).is(false)),\n\t\t\tUpdate.update(CUser.passwordResetTokenValidUntil, new Date())\n\t\t\t\t  .set(CUser.passwordResetToken, token),\n\t\t\tFindAndModifyOptions.options().returnNew(true), User.class);\n```\n\n\n## Features\n\n*constgen* ...\n  * requires Java 8 to run.\n  * scans for classes annotated with ```org.springframework.data.mongodb.core.mapping.Document``` or ```org.mongodb.morphia.annotations.Entity```.\n  * ignores ```transient``` fields.\n  * ignores ```static``` fields.\n  * ignores fields annotated with ```org.springframework.data.annotation.Transient``` or ```org.mongodb.morphia.annotations.Transient```.\n  * takes into account the annotations ```org.springframework.data.mongodb.core.mapping.Field``` and ```org.mongodb.morphia.annotations.Property``` and uses the value of the annotation as value for the String constant. \n\n\n## Maven\n\nTo activate the annotation processor you add the library as a dependency to your pom.xml. \nconstgen does not need to present at runtime so the dependency can be marked as optional \nand will not be included in an jar or war. \n```\n\t\u003cdependency\u003e\n\t\t\u003cgroupId\u003ech.rasc\u003c/groupId\u003e\n\t\t\u003cartifactId\u003econstgen\u003c/artifactId\u003e\n\t\t\u003cversion\u003e1.0.3\u003c/version\u003e\n\t\t\u003coptional\u003etrue\u003c/optional\u003e\n\t\u003c/dependency\u003e\n```\nInstead of ```\u003coptional\u003etrue\u003c/optional\u003e``` the provided scope ```\u003cscope\u003eprovided\u003c/scope\u003e``` can be specified. \nIt has the same effect and marks the library as a compile-time only dependency. \n\nThe [immutable](http://immutables.github.io) project has a good description \non how to [use annotation processors in Eclipse and IntelliJ](http://immutables.github.io/apt.html).\n\nThe Spring Boot Maven plugin includes dependencies that are optional or scope provided in the final jar. \nTo exclude constgen you need to add an exclude configuration.\n```\n\t\u003cplugin\u003e\n\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n\t\t\u003cconfiguration\u003e\n\t\t\t\u003cexcludes\u003e\n\t\t\t\t\u003cexclude\u003e\n\t\t\t\t\t\u003cgroupId\u003ech.rasc\u003c/groupId\u003e\n\t\t\t\t\t\u003cartifactId\u003econstgen\u003c/artifactId\u003e\n\t\t\t\t\u003c/exclude\u003e\n\t\t\t\u003c/excludes\u003e\n\t\t\u003c/configuration\u003e\n\t\u003c/plugin\u003e\n```\n\n## Changelog\n\n### 1.0.3 - January 30, 2016\n  * Resolves issue [#1](https://github.com/ralscha/constgen/issues/1)\n\n### 1.0.2 - November 22, 2015\n  * Do not ignore transient fields. Spring Data Mongo stores these fields.\n  * Support annotations (Field and Transient) from [bsoncodec-apt](https://github.com/ralscha/bsoncodec-apt)\n\n### 1.0.1 - October 29, 2015\n  * Ignore static fields\n  * Generate code the correct way with JavaFileObject\n\n### 1.0.0 - September 26, 2015\n  * Initial release\n\n\n## License\nCode released under [the Apache license](http://www.apache.org/licenses/).\n\n\n## Links\n  * [Spring Data MongoDB](http://projects.spring.io/spring-data-mongodb/)\n  * [Morphia](https://github.com/mongodb/morphia)\n  * [bsoncodec-apt](https://github.com/ralscha/bsoncodec-apt)\n  * [Mongo Java Driver](https://github.com/mongodb/mongo-java-driver)\n  * [MongoDB](https://www.mongodb.org/)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralscha%2Fconstgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralscha%2Fconstgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralscha%2Fconstgen/lists"}