Skip to content

Commit c8dade6

Browse files
committed
feat(col): add per-type shorthand classes in builder.col package
Each class in the new col package wraps a single ColumnType constant or factory method behind a concise name and a uniform of() / of(params) factory. Developers can use a wildcard import to write: import com.github.ezframework.javaquerybuilder.query.builder.col.*; .column("id", Int.of().notNull().autoIncrement()) .column("username", VarChar.of(64).notNull().unique()) .column("price", Decimal.of(10, 2)) .column("created_at", Timestamp.of()) instead of prefixing every type with ColumnType. Classes added (31 total): Fixed types: TinyInt, SmallInt, Int, BigInt, SqlFloat, SqlDouble, Real, Bool, Text, TinyText, MediumText, LongText, Clob, Blob, TinyBlob, MediumBlob, LongBlob, Date, Time, DateTime, Json, Serial, BigSerial, Uuid Parameterised types: Timestamp (overloaded of() / of(int)), VarChar, Char, Decimal, Numeric, Binary, VarBinary - SqlFloat / SqlDouble / Bool named to avoid shadowing java.lang types when the package is wildcard-imported - ColTypesTest: 34 tests covering all classes and modifier chaining
1 parent d771287 commit c8dade6

32 files changed

Lines changed: 1249 additions & 0 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code BIGINT}.
7+
*
8+
* <p>Delegates to {@link ColumnType#BIGINT}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("user_id", BigInt.of().notNull())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#BIGINT
18+
*/
19+
public final class BigInt {
20+
21+
/** Prevent instantiation. */
22+
private BigInt() {
23+
}
24+
25+
/**
26+
* Returns the {@code BIGINT} column type.
27+
*
28+
* @return a {@link ColumnType} representing {@code BIGINT}
29+
*/
30+
public static ColumnType of() {
31+
return ColumnType.BIGINT;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code BIGSERIAL} (auto-incrementing 8-byte integer; PostgreSQL).
7+
*
8+
* <p>Delegates to {@link ColumnType#BIGSERIAL}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("id", BigSerial.of())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#BIGSERIAL
18+
*/
19+
public final class BigSerial {
20+
21+
/** Prevent instantiation. */
22+
private BigSerial() {
23+
}
24+
25+
/**
26+
* Returns the {@code BIGSERIAL} column type.
27+
*
28+
* @return a {@link ColumnType} representing {@code BIGSERIAL}
29+
*/
30+
public static ColumnType of() {
31+
return ColumnType.BIGSERIAL;
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code BINARY(length)} (fixed-length binary string).
7+
*
8+
* <p>Delegates to {@link ColumnType#binary(int)}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("hash", Binary.of(32).notNull())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#binary(int)
18+
*/
19+
public final class Binary {
20+
21+
/** Prevent instantiation. */
22+
private Binary() {
23+
}
24+
25+
/**
26+
* Returns the {@code BINARY(length)} column type.
27+
*
28+
* @param length number of bytes; must be positive
29+
* @return a {@link ColumnType} representing {@code BINARY(length)}
30+
*/
31+
public static ColumnType of(final int length) {
32+
return ColumnType.binary(length);
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code BLOB} (binary large object).
7+
*
8+
* <p>Delegates to {@link ColumnType#BLOB}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("data", Blob.of())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#BLOB
18+
*/
19+
public final class Blob {
20+
21+
/** Prevent instantiation. */
22+
private Blob() {
23+
}
24+
25+
/**
26+
* Returns the {@code BLOB} column type.
27+
*
28+
* @return a {@link ColumnType} representing {@code BLOB}
29+
*/
30+
public static ColumnType of() {
31+
return ColumnType.BLOB;
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code BOOLEAN}.
7+
*
8+
* <p>Named {@code Bool} to avoid shadowing {@link java.lang.Boolean}.
9+
* Delegates to {@link ColumnType#BOOLEAN}. Use modifier methods on the
10+
* returned {@link ColumnType} to append column-level constraints:</p>
11+
*
12+
* <pre>{@code
13+
* .column("active", Bool.of().notNull().defaultValue("true"))
14+
* }</pre>
15+
*
16+
* @author EzFramework
17+
* @version 1.1.0
18+
* @see ColumnType#BOOLEAN
19+
*/
20+
public final class Bool {
21+
22+
/** Prevent instantiation. */
23+
private Bool() {
24+
}
25+
26+
/**
27+
* Returns the {@code BOOLEAN} column type.
28+
*
29+
* @return a {@link ColumnType} representing {@code BOOLEAN}
30+
*/
31+
public static ColumnType of() {
32+
return ColumnType.BOOLEAN;
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code CHAR(length)} (fixed-length character string).
7+
*
8+
* <p>Delegates to {@link ColumnType#charType(int)}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("country_code", Char.of(2).notNull())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#charType(int)
18+
*/
19+
public final class Char {
20+
21+
/** Prevent instantiation. */
22+
private Char() {
23+
}
24+
25+
/**
26+
* Returns the {@code CHAR(length)} column type.
27+
*
28+
* @param length number of characters; must be positive
29+
* @return a {@link ColumnType} representing {@code CHAR(length)}
30+
*/
31+
public static ColumnType of(final int length) {
32+
return ColumnType.charType(length);
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code CLOB} (character large object; standard SQL).
7+
*
8+
* <p>Delegates to {@link ColumnType#CLOB}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("report", Clob.of())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#CLOB
18+
*/
19+
public final class Clob {
20+
21+
/** Prevent instantiation. */
22+
private Clob() {
23+
}
24+
25+
/**
26+
* Returns the {@code CLOB} column type.
27+
*
28+
* @return a {@link ColumnType} representing {@code CLOB}
29+
*/
30+
public static ColumnType of() {
31+
return ColumnType.CLOB;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code DATE} (calendar date without time-of-day).
7+
*
8+
* <p>Delegates to {@link ColumnType#DATE}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("birth_date", Date.of().notNull())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#DATE
18+
*/
19+
public final class Date {
20+
21+
/** Prevent instantiation. */
22+
private Date() {
23+
}
24+
25+
/**
26+
* Returns the {@code DATE} column type.
27+
*
28+
* @return a {@link ColumnType} representing {@code DATE}
29+
*/
30+
public static ColumnType of() {
31+
return ColumnType.DATE;
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code DATETIME} (date and time without timezone;
7+
* MySQL / MariaDB / SQLite).
8+
*
9+
* <p>Delegates to {@link ColumnType#DATETIME}. Use modifier methods on the
10+
* returned {@link ColumnType} to append column-level constraints:</p>
11+
*
12+
* <pre>{@code
13+
* .column("scheduled_at", DateTime.of().notNull())
14+
* }</pre>
15+
*
16+
* @author EzFramework
17+
* @version 1.1.0
18+
* @see ColumnType#DATETIME
19+
*/
20+
public final class DateTime {
21+
22+
/** Prevent instantiation. */
23+
private DateTime() {
24+
}
25+
26+
/**
27+
* Returns the {@code DATETIME} column type.
28+
*
29+
* @return a {@link ColumnType} representing {@code DATETIME}
30+
*/
31+
public static ColumnType of() {
32+
return ColumnType.DATETIME;
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.ezframework.javaquerybuilder.query.builder.col;
2+
3+
import com.github.ezframework.javaquerybuilder.query.builder.ColumnType;
4+
5+
/**
6+
* Column type shorthand for {@code DECIMAL(precision, scale)}.
7+
*
8+
* <p>Delegates to {@link ColumnType#decimal(int, int)}. Use modifier methods on the
9+
* returned {@link ColumnType} to append column-level constraints:</p>
10+
*
11+
* <pre>{@code
12+
* .column("price", Decimal.of(10, 2).notNull())
13+
* }</pre>
14+
*
15+
* @author EzFramework
16+
* @version 1.1.0
17+
* @see ColumnType#decimal(int, int)
18+
*/
19+
public final class Decimal {
20+
21+
/** Prevent instantiation. */
22+
private Decimal() {
23+
}
24+
25+
/**
26+
* Returns the {@code DECIMAL(precision, scale)} column type.
27+
*
28+
* @param precision total number of significant digits; must be positive
29+
* @param scale number of digits after the decimal point; must be &ge; 0
30+
* @return a {@link ColumnType} representing {@code DECIMAL(precision, scale)}
31+
*/
32+
public static ColumnType of(final int precision, final int scale) {
33+
return ColumnType.decimal(precision, scale);
34+
}
35+
}

0 commit comments

Comments
 (0)