### Install DBOS CLI (Native Executable) Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Installs the DBOS CLI using its native executable. This is the recommended installation method. ```shell $ dbos --version dbos v0.10.0 ``` -------------------------------- ### Install DBOS CLI (JAR) Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Installs the DBOS CLI using its JAR file, which requires the `java -jar` command. This method is an alternative to the native executable. ```shell $ java -jar dbos.jar --version dbos v0.10.0 ``` -------------------------------- ### JDBI @TransactionalStep Example Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Use `@TransactionalStep` with JDBI for transactional operations. Inject `Jdbi` and use `withHandle` for executing SQL. ```java import org.jdbi.v3.core.Jdbi; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.dbos.Transaction.TransactionalStep; @Service public class OrderStepService { @Autowired Jdbi jdbi; @TransactionalStep public Order saveOrder(Order order) { jdbi.withHandle(h -> h.execute("INSERT INTO orders(id, item, qty) VALUES (?, ?, ?)", order.id(), order.item(), order.qty())); return order; } } ``` -------------------------------- ### jOOQ @TransactionalStep Example Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Use `@TransactionalStep` with jOOQ for transactional operations. Inject `DSLContext` and use its `execute` method. ```java import org.jooq.DSLContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.dbos.Transaction.TransactionalStep; @Service public class OrderStepService { @Autowired DSLContext dsl; @TransactionalStep public Order saveOrder(Order order) { dsl.execute("INSERT INTO orders(id, item, qty) VALUES (?, ?, ?)", order.id(), order.item(), order.qty()); return order; } } ``` -------------------------------- ### Build Native Executable Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Builds the native executable for the DBOS CLI using Gradle and GraalVM Native Image. Ensure you have a local C toolchain installed. ```shell ./gradlew :transact-cli:nativeCompile ``` -------------------------------- ### MyBatis @TransactionalStep Example Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Use `@TransactionalStep` with MyBatis mappers for transactional operations. Inject the mapper and call its insert method. ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.dbos.Transaction.TransactionalStep; @Service public class OrderStepService { @Autowired OrderMapper orderMapper; @TransactionalStep public Order saveOrder(Order order) { orderMapper.insert(order.id(), order.item(), order.qty()); return order; } } ``` -------------------------------- ### Start a Workflow Asynchronously in Java Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/README.md Initiate a workflow execution in the background without blocking the current thread. Retrieve the workflow's result later using the returned handle. ```java var handle = DBOS.startWorkflow(()->example.exampleWorkflow("HelloDBOS")); result = handle.getResult(); ``` -------------------------------- ### Spring JDBC @TransactionalStep Example Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Annotate a Spring-managed method with `@TransactionalStep` for transactional execution. Ensure the method is called through a Spring proxy. ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import com.dbos.Transaction.TransactionalStep; @Service public class OrderStepService { @Autowired JdbcTemplate jdbc; @TransactionalStep public Order saveOrder(Order order) { jdbc.update("INSERT INTO orders(id, item, qty) VALUES (?, ?, ?)", order.id(), order.item(), order.qty()); return order; } } @Service public class OrderWorkflowService { @Autowired OrderStepService steps; @Workflow public Order processOrder(Order order) { return steps.saveOrder(order); } } ``` -------------------------------- ### JPA @TransactionalStep Example Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Use `@TransactionalStep` with Spring Data JPA repositories for transactional operations. Inject the repository and use its `save` method. ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.dbos.Transaction.TransactionalStep; @Service public class OrderStepService { @Autowired OrderRepository repo; // Spring Data JPA repository @TransactionalStep public Order saveOrder(Order order) { return repo.save(order); } } ``` -------------------------------- ### Apply Code Formatting Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Use this command to automatically format your code according to DBOS Transact Java SDK standards using Spotless. This is useful if the build fails due to formatting violations. ```shell ./gradlew spotlessApply ``` -------------------------------- ### Show DBOS Version Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Displays the version of the DBOS CLI. ```bash dbos --version ``` -------------------------------- ### Define Billing and Payment Workflows in Java Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/README.md Illustrates how to define a billing workflow that receives payment status and a payment workflow that sends status updates. Use these for orchestrating business logic with durable execution. ```java @Workflow(name = "billing") public void billingWorkflow() { // Calculate the charge, then submit the bill to a payments service String paymentStatus = (String) DBOS.recv(PAYMENT_STATUS, paymentServiceTimeout); if (paymentStatus.equals("paid")) { // handle paid } else { // handle not paid } } @Workflow(name = "payment") public void payment(String targetWorkflowId) { DBOS.send(targetWorkflowId, PAYMENT_STATUS, "paid") ; } ``` -------------------------------- ### Import DBOS Transact into Application Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Add these lines to your `build.gradle.kts` file to include the DBOS Transact library and a logging framework in your application. ```kotlin implementation("dev.dbos:transact") implementation("ch.qos.logback:logback-classic:1.5.6") ``` -------------------------------- ### Build DBOS Transact Java SDK Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Run this command to perform a clean build of the project. It ensures all code is compiled and tests are run. ```shell ./gradlew clean build ``` -------------------------------- ### Configure Database Connection (Command-Line Flags) Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Configures the DBOS system database connection using command-line flags for URL, username, and password. This method has the highest priority. ```bash dbos migrate --db-url jdbc:postgresql://localhost/mydb -U user -P password ``` -------------------------------- ### Configure Database Connection (Environment Variables) Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Configures the DBOS system database connection using environment variables. This method has the lowest priority. ```bash export DBOS_SYSTEM_JDBC_URL=jdbc:postgresql://localhost/mydb export PGUSER=user export PGPASSWORD=password dbos migrate ``` -------------------------------- ### Run Tests for DBOS Transact Java SDK Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Execute this command to clean the project and run all defined tests. It helps verify the correctness of the code. ```shell ./gradlew clean test ``` -------------------------------- ### Run DBOS Migrate Command Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Executes the `dbos migrate` command to create DBOS system tables in the database. Various options can be specified. ```bash dbos migrate ``` ```bash dbos migrate --app-role myapp_role ``` ```bash dbos migrate --no-listen-notify ``` -------------------------------- ### Gradle Dependencies for DBOS Spring Starters Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add these dependencies to your Gradle build file to include the DBOS Spring Boot starter and the txstep starter. ```kotlin implementation("dev.dbos:transact-spring-boot-starter:") implementation("dev.dbos:transact-spring-txstep-starter:") ``` -------------------------------- ### Maven Dependencies for DBOS Spring Starters Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add these dependencies to your Maven pom.xml to include the DBOS Spring Boot starter and the txstep starter. ```xml dev.dbos transact-spring-boot-starter VERSION dev.dbos transact-spring-txstep-starter VERSION ``` -------------------------------- ### Define and Run a Durable Workflow in Java Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/README.md Register ordinary Java functions as workflows and steps to make your program durable. Workflows automatically resume from the last completed step if the program fails and restarts. ```java interface Example { public void workflow(); } class ExampleImpl implements Example { private void stepOne() { System.out.println("Step one completed!"); } private void stepTwo() { System.out.println("Step two completed!"); } @Workflow public void workflow() { DBOS.runStep(() -> stepOne(), "stepOne"); DBOS.runStep(() -> stepTwo(), "stepTwo"); } } ``` -------------------------------- ### MyBatis Integration Dependency Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add the `mybatis-spring-boot-starter` dependency for auto-configuration of `SqlSessionTemplate` with `DataSourceTransactionManager`. ```kotlin implementation("org.mybatis.spring.boot:mybatis-spring-boot-starter:") ``` -------------------------------- ### Create a New Release Branch Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Use this command to create a new release tag and branch from the main branch. Optionally, push the tag and branch to the origin. If no version is specified, it increments the last minor version. ```shell java scripts/createRelease --version 1.2.3 --push ``` -------------------------------- ### Publish to Local Maven Repository Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md This command publishes the DBOS Transact Java SDK artifacts to your local Maven repository. It's useful for testing integration with other local projects. ```shell ./gradlew publishToMavenLocal ``` -------------------------------- ### Run DBOS Reset Command Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Executes the `dbos reset` command to reset the DBOS system database, deleting metadata. Use the `--yes` flag to skip the confirmation prompt. ```bash dbos reset ``` ```bash dbos reset --yes # Skip confirmation ``` -------------------------------- ### jOOQ Integration Dependency Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add the `spring-boot-starter-jooq` dependency for auto-configuration of `DSLContext` with `SpringTransactionProvider`. ```kotlin implementation("org.springframework.boot:spring-boot-starter-jooq") ``` -------------------------------- ### Configure Custom Schema Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-cli/README.md Specifies a custom schema name for all DBOS system tables using the `--schema` option. ```bash dbos migrate --schema myapp_schema ``` -------------------------------- ### JPA Integration Dependency Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add the `spring-boot-starter-data-jpa` dependency for auto-configuration of `JpaTransactionManager`. ```kotlin implementation("org.springframework.boot:spring-boot-starter-data-jpa") ``` -------------------------------- ### JDBI Configuration Bean Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Configure a JDBI `JdbiFactoryBean` bean to integrate with Spring's data source. ```java import org.jdbi.v3.core.Jdbi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; @Configuration public class JdbiConfig { @Bean public Jdbi jdbi(DataSource dataSource) throws Exception { var factory = new JdbiFactoryBean(dataSource); factory.afterPropertiesSet(); return factory.getObject(); } } ``` -------------------------------- ### Check for Dependency Updates Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Run this Gradle command to identify outdated dependencies in your project. It generates a report detailing which dependencies can be updated. ```shell ./gradlew dependencyUpdates ``` -------------------------------- ### Schedule Workflows with Cron Syntax in Java Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/README.md Annotate a workflow method with `@Scheduled` and a cron expression to execute it at specified intervals. Register the workflow implementation with DBOS. ```java public class SchedulerImpl implements Scheduler { @Workflow(name = "every5Second") @Scheduled(cron = "0/5 * * * * ?") public void every5Second(Instant schedule , Instant actual) { log.info("Executed workflow "+ schedule.toString() + " " + actual.toString()) ; } } // In your main DBOS.registerWorkflows(Scheduler.class, new SchedulerImpl()); ``` -------------------------------- ### Patch an Existing Release Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/DEVELOPING.md Execute this command from a release branch to tag the latest commit with a patch version. The version is automatically generated by incrementing the last patch version. The tag can be pushed to origin. ```shell java scripts/createRelease --push ``` -------------------------------- ### JDBI Integration Dependency Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Add the `jdbi3-spring` dependency to enable JDBI's `SpringTransactionHandler` to reuse active Spring transactions. ```kotlin implementation("org.jdbi:jdbi3-spring:") ``` -------------------------------- ### Manage Durable Queues in Java Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/README.md Enqueue tasks from a durable workflow for distributed execution. DBOS manages task completion and results, ensuring reliability even through application interruptions. Queues support flow control, timeouts, rate limiting, deduplication, and prioritization. ```java public void queuedTasks() { for (int i = 0; i < 3; i++) { String workflowId = "child" + i; var options = new StartWorkflowOptions(workflowId).withQueue(q); List> handles = new ArrayList<>(); handles.add(DBOS.startWorkflow(()->simpleService.childWorkflow(workflowId), options)); } for (int i = 0 ; i < 3 ; i++) { String workflowId = "child"+i; var h = DBOS.retrieveWorkflow(workflowId); System.out.println(h.getResult()); } } // In your main var queue = new Queue("exampleQueue"); DBOS.registerQueue(queue); ``` -------------------------------- ### MyBatis Mapper Interface Source: https://github.com/dbos-inc/dbos-transact-java/blob/main/transact-spring-txstep-starter/README.md Define a MyBatis mapper interface with `@Insert` annotation for inserting order data. ```java import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @Mapper public interface OrderMapper { @Insert("INSERT INTO orders(id, item, qty) VALUES(#{id}, #{item}, #{qty})") void insert(@Param("id") String id, @Param("item") String item, @Param("qty") int qty); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.