Class Litebridge

All Implemented Interfaces:
SelectApi

public class Litebridge extends LitebridgeCore
Default primary entry point for Litebridge.

Litebridge is responsible for managing database interactions, including mapping Data Transfer Objects (DTOs) to tables, registering tables, change tracking, and executing query operations.

It provides a mechanism to translate between DTOs and database tables, facilitating CRUD operations while maintaining consistency and integrity.

Litebridge ensures thread safety by using immutable internal structures and leveraging the DatabaseProvider and PersistenceFacade for database interactions, ensuring that operations are performed safely and efficiently.

This extends LitebridgeCore and provides additional methods for performing MERGE INTO operations if the database provider supports merge operations.

See Also:
  • Constructor Details

    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, DataSource dataSource)
      Constructs a Litebridge instance with the specified database provider and data source.
      Parameters:
      databaseProvider - the database provider
      dataSource - the data source
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig)
      Constructs a Litebridge instance with the specified database provider, data source, and configuration.
      Parameters:
      databaseProvider - the database provider
      dataSource - the data source
      litebridgeConfig - the configuration, or null
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, DataSource dataSource, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup)
      Constructs a Litebridge instance with the specified database provider, data source, configuration, and lookup.
      Parameters:
      databaseProvider - the database provider
      dataSource - the data source
      litebridgeConfig - the configuration, or null
      lookup - the method handles lookup
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager)
      Constructs a Litebridge instance with the specified database provider and transaction manager.
      Parameters:
      databaseProvider - the database provider
      transactionManager - the transaction manager
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, LitebridgeConfig litebridgeConfig)
      Constructs a Litebridge instance with the specified database provider, transaction manager, and configuration.
      Parameters:
      databaseProvider - the database provider
      transactionManager - the transaction manager
      litebridgeConfig - the configuration
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, MethodHandles.Lookup lookup)
      Constructs a Litebridge instance with the specified database provider, transaction manager, and lookup.
      Parameters:
      databaseProvider - the database provider
      transactionManager - the transaction manager
      lookup - the method handles lookup
    • Litebridge

      public Litebridge(DatabaseProvider databaseProvider, TransactionManager transactionManager, @Nullable LitebridgeConfig litebridgeConfig, MethodHandles.Lookup lookup)
      Constructs a Litebridge instance with the specified database provider, transaction manager, configuration, and lookup.
      Parameters:
      databaseProvider - the database provider
      transactionManager - the transaction manager
      litebridgeConfig - the configuration, or null
      lookup - the method handles lookup
    • Litebridge

      protected Litebridge(LitebridgeCore other)
      Copy constructor.
      Parameters:
      other - Instance to copy.
  • Method Details

    • merge

      public void merge(Object dto)
      Merges/upserts the specified entity/mapped DTO into the database.

      This method constructs an SQL `MERGE INTO` statement based on the provided DTO and executes it.

      Parameters:
      dto - the entity/mapped DTO to be merged into the database. It must correspond to a registered ORM table.
    • mergeInto

      public UpdateResult mergeInto(String tableName, Function<SqlMergeUsingStep,MergeTerminal> merge)
      Performs a MERGE INTO operation targeting the specified database table.
      Parameters:
      tableName - the name of the table into which to merge data
      merge - a function that takes an instance of SqlMergeUsingStep and returns a MergeTerminal, specifying the conditions and actions for merging records
      Returns:
      the result of the merge operation
    • mergeInto

      public <DTO> UpdateResult mergeInto(Class<DTO> dtoClass, Function<DtoMergeUsingStep<DTO>,MergeTerminal> merge)
      Performs a MERGE INTO operation targeting the specified mapped DTO type.
      Type Parameters:
      DTO - the type of the DTO
      Parameters:
      dtoClass - the target class of the DTO/entity to merge
      merge - a function that takes an instance of DtoMergeUsingStep and returns a MergeTerminal, specifying the conditions and actions for merging records
      Returns:
      the result of the merge operation
    • mergeInto

      public <DTO> UpdateResult mergeInto(Class<DTO> dtoClass, Class<?> contextDtoClass, Function<DtoMergeUsingStep<DTO>,MergeTerminal> merge)
      Performs a MERGE INTO operation targeting the specified mapped DTO type.
      Type Parameters:
      DTO - the type of the DTO
      Parameters:
      dtoClass - the target class of the DTO/entity to merge
      contextDtoClass - The context DTO class for determining the table mapping.
      merge - a function that takes an instance of DtoMergeUsingStep and returns a MergeTerminal, specifying the conditions and actions for merging records
      Returns:
      the result of the merge operation