Module is.codion.framework.domain
Interface Column<T>
- Type Parameters:
T- the column value type
- All Superinterfaces:
Attribute<T>,ColumnConditions<T>
An
Attribute representing a table column.
Columns are attributes that map directly to database table columns, providing type-safe
access to column values and enabling query condition creation. They extend the base
Attribute interface with column-specific functionality for database operations.
Columns are declared in the domain API, and defined in the domain model:
interface Track {
EntityType TYPE = DOMAIN.entityType("chinook.track");
// Column definitions
Column<Long> ID = TYPE.longColumn("id");
Column<String> NAME = TYPE.stringColumn("name");
Column<String> COMPOSER = TYPE.stringColumn("composer");
Column<Integer> MILLISECONDS = TYPE.integerColumn("milliseconds");
Column<Integer> RATING = TYPE.integerColumn("rating");
Column<BigDecimal> UNITPRICE = TYPE.bigDecimalColumn("unitprice");
}
EntityDefinition track() {
return Track.TYPE.as()
.attributes(
Track.ID.as()
.primaryKey()
.generator(Generator.identity()),
Track.NAME.as()
.column()
.caption("Name")
.nullable(false)
.maximumLength(200),
Track.COMPOSER.as()
.column()
.caption("Composer")
.maximumLength(220),
Track.MILLISECONDS.as()
.column()
.caption("Duration")
.nullable(false),
Track.RATING.as()
.column()
.caption("Rating")
.nullable(false)
.defaultValue(5)
.range(1, 10),
Track.UNITPRICE.as()
.column()
.caption("Price")
.nullable(false)
.minimum(0)
.fractionDigits(2))
.build();
}
Columns inherit from ColumnConditions to provide condition creation methods:
// Query condition usage (inherited from ColumnConditions)
List<Entity> bachTracks = connection.select(
Track.COMPOSER.equalTo("Johann Sebastian Bach"));
List<Entity> loveSongs = connection.select(
Track.NAME.likeIgnoreCase("%love%"));
List<Entity> longTracks = connection.select(
Track.MILLISECONDS.greaterThanOrEqualTo(600_000));
List<Entity> expensiveTracks = connection.select(
Track.UNITPRICE.greaterThan(BigDecimal.valueOf(0.99)));
// Complex conditions
List<Entity> liveAlbums = connection.select(and(
Album.ARTIST_FK.in(artists),
Album.TITLE.likeIgnoreCase("%live%")));
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceProvidesColumnDefinition.Builderinstances.static interfaceConverts to and from SQL values, such as integers being used to represent booleans in a database.static interfaceGenerates column values for entities on insert.Nested classes/interfaces inherited from interface is.codion.framework.domain.entity.attribute.Attribute
Attribute.AttributeDefiner<T>, Attribute.DataType<T> -
Method Summary
Modifier and TypeMethodDescriptionas()as(ColumnTemplate<T> template) Returns aColumnDefinition.Builderfor this column, configured by the given template.static <T> Column<T> column(EntityType entityType, String name, TypeReference<T> typeReference) Creates a newColumn, associated with the given entityType.static <T> Column<T> column(EntityType entityType, String name, Class<T> type) Creates a newColumn, associated with the given entityType.Methods inherited from interface is.codion.framework.domain.entity.attribute.Attribute
as, entityType, name, typeMethods inherited from interface is.codion.framework.domain.entity.condition.ColumnConditions
between, betweenExclusive, equalTo, equalToIgnoreCase, equalToIgnoreCase, greaterThan, greaterThanOrEqualTo, in, in, inIgnoreCase, inIgnoreCase, isNotNull, isNull, lessThan, lessThanOrEqualTo, like, likeIgnoreCase, notBetween, notBetweenExclusive, notEqualTo, notEqualToIgnoreCase, notEqualToIgnoreCase, notIn, notIn, notInIgnoreCase, notInIgnoreCase, notLike, notLikeIgnoreCase
-
Method Details
-
as
Column.ColumnDefiner<T> as()- Specified by:
asin interfaceAttribute<T>- Returns:
- a
Column.ColumnDefinerfor this column
-
as
Returns aColumnDefinition.Builderfor this column, configured by the given template.Customer.LASTNAME.as(REQUIRED_SEARCHABLE) .maximumLength(20);The template is applied first, any subsequent configuration overriding it.
Note that a column has
Attribute.as(AttributeTemplate)as well, so the template must be typed, an inline lambda being ambiguous between the two.- Parameters:
template- the column template- Returns:
- a
ColumnDefinition.Builderconfigured by the given template
-
column
Creates a newColumn, associated with the given entityType.- Type Parameters:
T- the column type- Parameters:
entityType- the entityType owning this columnname- the column nametypeReference- theTypeReferencerepresenting the column value type- Returns:
- a new
Column
-
column
Creates a newColumn, associated with the given entityType.- Type Parameters:
T- the column type- Parameters:
entityType- the entityType owning this columnname- the column nametype- the class representing the column value type- Returns:
- a new
Column
-