|
| 1 | +# JavaQueryBuilder – Project Guidelines |
| 2 | + |
| 3 | +## Code Style |
| 4 | + |
| 5 | +Enforced by Checkstyle ([checkstyle.xml](checkstyle.xml)) — runs automatically on `mvn validate`. Violations fail the build. |
| 6 | + |
| 7 | +- **Indentation**: 4 spaces; no tabs |
| 8 | +- **Line length**: max 120 characters |
| 9 | +- **Trailing whitespace**: none allowed |
| 10 | +- **Imports**: grouped (`java`, `javax`, `org`, `com`), no star imports, ordered and separated by blank line |
| 11 | +- **Braces**: required on all blocks (`NeedBraces`), same-line opening (`LeftCurly`) |
| 12 | +- **Complexity**: cyclomatic complexity ≤ 10 per method; method body ≤ 60 lines; class fan-out ≤ 20 |
| 13 | +- **Magic numbers**: flag literals other than `-1, 0, 1, 2` outside field declarations and annotations |
| 14 | +- **`FinalLocalVariable`**: declare local variables `final` whenever they are not reassigned |
| 15 | +- Test classes (`*Test.java`): Javadoc and complexity rules are suppressed via [suppressions.xml](suppressions.xml) |
| 16 | + |
| 17 | +### JavaDoc Requirements |
| 18 | + |
| 19 | +All public API classes, interfaces, enums, and their methods must have complete Javadoc: |
| 20 | + |
| 21 | +```java |
| 22 | +/** |
| 23 | + * One clear summary sentence ending with a period. |
| 24 | + * |
| 25 | + * @param column the column name to filter on |
| 26 | + * @param value the value to compare against |
| 27 | + * @return this builder instance for chaining |
| 28 | + * @throws IllegalArgumentException if column is null or blank |
| 29 | + */ |
| 30 | +public QueryBuilder whereEquals(String column, Object value) { … } |
| 31 | +``` |
| 32 | + |
| 33 | +- `@author` and `@version` required on type-level Javadoc |
| 34 | +- `@param` required for every parameter, `@return` for every non-void method |
| 35 | +- `@throws` required for every checked and declared unchecked exception |
| 36 | +- First sentence must be a meaningful summary — no generic openers like `"A {@code X} is a …"` |
| 37 | + |
| 38 | +## Architecture |
| 39 | + |
| 40 | +Package `com.github.ezframework.javaquerybuilder.query`: |
| 41 | + |
| 42 | +| Class / Type | Role | |
| 43 | +|---|---| |
| 44 | +| `QueryBuilder` | Fluent builder for SELECT queries; returns a `Query` | |
| 45 | +| `DeleteBuilder`, `InsertBuilder`, `UpdateBuilder` | Fluent builders for DML statements | |
| 46 | +| `Query` | Immutable data holder (columns, conditions, limit, offset, …) | |
| 47 | +| `Condition` / `ConditionEntry` | Per-field condition (operator + value) with in-memory match support | |
| 48 | +| `Operator` | Enum of 14 comparison operators (`EQ`, `LIKE`, `BETWEEN`, …) | |
| 49 | +| `Connector` | `AND` / `OR` enum for joining conditions | |
| 50 | +| `sql.SqlDialect` | Strategy: `STANDARD`, `MYSQL`, `SQLITE` | |
| 51 | +| `sql.AbstractSqlDialect` | Base SQL rendering logic | |
| 52 | + |
| 53 | +**Key conventions**: |
| 54 | +- Builder methods **always return `this`** (or the builder type) for fluent chaining. |
| 55 | +- All SQL values must go through the parameterized SQL path — never concatenate user input into SQL strings. |
| 56 | +- `Operator` is the single source of truth for supported operators; add new operators there first. |
| 57 | + |
| 58 | +## Build and Test |
| 59 | + |
| 60 | +```bash |
| 61 | +# Full build: checkstyle → compile → test → JaCoCo report → coverage check → package |
| 62 | +mvn clean verify |
| 63 | + |
| 64 | +# Checkstyle only |
| 65 | +mvn checkstyle:check |
| 66 | + |
| 67 | +# Tests only (skips coverage threshold) |
| 68 | +mvn test |
| 69 | + |
| 70 | +# Coverage report (generated after mvn verify or mvn test) |
| 71 | +open target/site/jacoco/index.html |
| 72 | +``` |
| 73 | + |
| 74 | +**Coverage target**: 80% instruction coverage enforced by JaCoCo on `mvn verify`. New code must maintain or improve coverage. |
| 75 | + |
| 76 | +## Conventions |
| 77 | + |
| 78 | +- Fluent builder methods use verb prefixes: `where*`, `orderBy`, `groupBy`, `select`, `from` |
| 79 | +- `OR` variants are named `orWhere*` — the first condition in a builder always uses `AND` as connector |
| 80 | +- Exception hierarchy: `QueryBuilderException` → `QueryException` / `QueryRenderException` in `query.exception` |
| 81 | +- Test class names match source class names with `Test` suffix and live in the same sub-package under `src/test/` |
| 82 | + |
| 83 | +## Packaging and Distribution |
| 84 | + |
| 85 | +- **GitHub Packages**: published automatically on GitHub Release creation via [.github/workflows/publish.yml](.github/workflows/publish.yml) |
| 86 | +- **JitPack**: available at `https://jitpack.io/#EzFramework/JavaQueryBuilder`; build config in [jitpack.yml](jitpack.yml) |
| 87 | +- Both `-sources.jar` and `-javadoc.jar` are attached to every release |
0 commit comments