Package st.orm

Interface Projection<ID>

Type Parameters:
ID - the type of the projection's primary key, or Void if the projection has no primary key.
All Superinterfaces:
Data

public interface Projection<ID> extends Data
Marker interface for record-based projections.

Usage examples:

Define a projection record based on the basket_summary_view view, with a basket_id primary key.

Java:


 @DbTable("basket_summary_view")
 record BasketSummary(@PK @FK Basket basket, int itemCount, BigDecimal totalPrice) implements Projection<Integer> {}
 

Kotlin:


 @DbTable("basket_summary_view")
 data class BasketSummary(@PK @FK val basket: Basket, val itemCount: Int, val totalPrice: BigDecimal) : Projection<Int>
 

Then, you can use the projection in a query like this:


 var baskets = ...
 List<BasketSummary> summaries = ORM(dataSource).projection(BasketSummary.class)
     .select()
     .where(baskets)  // Type-safe.
     .getResultList();
 

Or use it as a foreign key in an entity.

Java:


 record User(@PK int id, @FK("basket_id") BasketSummary basketSummary) implements Entity<Integer> {}
 

Kotlin:


 data class User(@PK val id: Int, @FK("basket_id") val basketSummary: BasketSummary) : Entity<Int>
 

Then, you can query all users having a basket with at least 1 item:


 List<User> users = ORM(dataSource).projection(User.class)
     .select()
     .where(User_.basketSummary.itemCount, GREATER_THAN, 0)   // Type-safe metamodel.
     .getResultList();