Skip to content

Java API

Gerald Quintana edited this page May 26, 2016 · 2 revisions

Java API

Installation

Maven

Beep beep is published in Maven Central repositories

<dependency>
  <groupId>com.github.gquintana.beepbeep</groupId>
  <artifactId>beepbeep</artifactId>
  <version>0.1.1</version>
</dependency>

Usage

Pipeline

A Pipeline is a chain of event consumers starting by ScriptScanner which produces ScriptStartEvents for each Script. The Pipeline is executed with its run method.

A Pipeline is mostly immutable and is created from a PipelineBuilder

SqlPipelineBuilder pipelineBuilder = new SqlPipelineBuilder()
  .withUrl("jdbc:mysql://localhost:3306/mydb")  
  .withFilesScriptScanner("scripts/*.sql");
try(SqlPipeline pipeline = pipelineBuilder.build()) {
  pipeline.run();
}

The pipeline may end with custom consumer which receives line execution results. It

ScriptScanner

A ScriptScanner aims at finding Scripts on the file system (FileScriptScanner) or the classpath (ResourceScriptScanner).

ScriptScanner can be created from the ScriptScanners or ScriptScannerFactories classes. The later just adds curryfication over the former. There are many implementations:

  • resource, resources find scripts by scanning Jars and folders on class path
  • file, files find scripts by file system (be sure to have the appropriate permissions)
  • composite can mix and match multiple ScriptScanner in a single one
  • scheme uses a prefix scheme (classpath:, 'file:) to determine the appropriate implementation

The file and resources ScriptScanners can use Java predicates to select scripts or name globbing. Name globbing uses the usual Ant syntax:

base/folder/**/script*.ext

** means any number of directories between folder and script-12.ext. It's a recursive search.

ScriptStore

The ScriptStore is basically a DAO/repository to write ran scripts into a database. There multiple implementations for different backends: SqlScriptStore, ElasticsearchScriptStore, MemoryScriptStore (for testing purposes)....

ScriptStores have a prepare method in charge of creating the table/index/..., this method should be idempotent since it's ran each time the pipeline starts.

Clone this wiki locally