Runtime

Prerequisites:

  • Java 17
  • Maven 3.x
  • Higson Studio

JavaDoc

We will show how to configure Higson Engine using Spring Boot configuration

Maven Configuration#

Apart from standard spring boot dependencies, you need to include higson-runtime dependency, available in Maven Central.

1
2
3
4
5
  <dependency>
    <groupId>io.higson</groupId>
    <artifactId>higson-runtime</artifactId>
    <version>${higson-runtime.version}</version>
  </dependency>

Another needed dependency is the JDBC driver to the database of choice, e.g., H2, Oracle, Postgres, MsSQL or MySQL and database connection pool managing library:

1
2
3
4
5
  <dependency>
     <groupId>com.h2database</groupId>
     <artifactId>h2</artifactId>
     <version>${h2-database.version}</version>
  </dependency>

Properties#

Add Higson Runtime data source properties to application.properties file.

1
2
3
higson.database.url=<jdbc_url>
higson.database.username=<username>
higson.database.password=<password>

Properties are available here

Spring Configuration#

Add required beans to your java class annotated with @Configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  @Autowired
  private Environment env;
  
  private static final Logger log = LoggerFactory.getLogger(TestConfiguration.class);
  
  @Bean
  public DialectRegistry getDialectRegistry() {
      DialectRegistry registry = new DialectRegistry();
      registry.setDialect(env.getProperty("higson.database.dialect"));
      return registry;
  }

  @Bean
  public DialectTemplate getDialectTemplate(DialectRegistry dialectRegistry) {
      return dialectRegistry.create();
  }
  
  @Bean(destroyMethod = "close")
  public DataSource getDataSource(DialectTemplate dialectTemplate) {
      BasicDataSource dataSource = new BasicDataSource();
      dataSource.setUsername(env.getProperty("higson.database.username"));
      dataSource.setPassword(env.getProperty("higson.database.password"));
      dataSource.setUrl(env.getProperty("higson.database.url"));
      dataSource.setInitialSize(4);
      dataSource.setDriverClassName(dialectTemplate.getJdbcDriverClassName());
      return dataSource;
  }
  
  @Bean(destroyMethod = "destroy")
  public HigsonEngineFactory getHigsonEngineFactory(DataSource dataSource) {
      log.info("Engine factory begin creation...");
      HigsonEngineFactory higsonEngineFactory = new HigsonEngineFactory();
      higsonEngineFactory.setDataSource(dataSource);
      return higsonEngineFactory;
  }
  
  @Bean
  public HigsonEngine getHigsonEngine(HigsonEngineFactory higsonEngineFactory) {
      log.info("Engine begin creation...");
      return higsonEngineFactory.create();
  }

The application is ready to start. After successfully starting the application, you can see similar log output:

Run Higson Runtime REST in Test Mode Using Snapshot-Based Configuration#

It is possible to run the Higson Runtime in test mode using a configuration loaded directly from a snapshot. In this mode:

  • The runtime does not require a database connection, as the entire configuration is sourced locally from the snapshot.
  • The environment operates in read-only mode.
  • Watchers are disabled, as no changes to the configuration are expected.
  • Test mode is mutually exclusive with development mode and cannot be used simultaneously.
  • This setup does not support tables from external data sources.

To use runtime in test mode, you need the following configuration:


private String pathToSnapshot = "C:\Users\UserName\Downloads\snapshot.zip"

@Bean(destroyMethod = "destroy")
public HigsonEngineFactory getHigsonEngineFactory() {
    log.info("Engine factory begin creation...");
    HigsonEngineFactory higsonEngineFactory = new HigsonEngineFactory();
    higsonEngineFactory.setDataSource(new HigsonSnapshotDataSource(new File(pathToSnapshot)));
    return higsonEngineFactory;
}

@Bean
public HigsonEngine getHigsonEngine(HigsonEngineFactory higsonEngineFactory) {
    log.info("Engine begin creation...");
    return higsonEngineFactory.create();
}