Skip to content

Add a ValueProvider

Prerequisites

Implementing Liquibase extensions requires an understanding of Java. You will be creating classes, overriding methods, and working with inheritance hierarchies.

Project Setup

If you have not already created a repository to hold your code, see Your First Extension in the Getting Started guide.

Overview

When adding support for a new precondition, the interface you are going to implement is liquibase.configuration.ConfigurationValueProvider.

ConfigurationValueProvider should be thread-safe.

Tip

There is a liquibase.configuration.AbstractMapConfigurationValueProvider base class you can use which limits the number of methods you must implement.

If your data source cannot be loaded into a java.util.Map as AbstractMapConfigurationValueProvider requires, liquibase.configuration.AbstractConfigurationValueProvider does not require that implementation while still being easier than implementing ConfigurationValueProvider directly. you must implement.

API Documentation

A complete description of the API, including what methods must be implemented and how is available on the liquibase.configuration.ConfigurationValueProvider API page.

Example Code

package com.example.configuration;

import liquibase.configuration.AbstractMapConfigurationValueProvider;

import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;

public class ExampleValueProvider extends AbstractMapConfigurationValueProvider {

    @Override
    public int getPrecedence() {
        return 200;
    }

    @Override
    protected String getSourceDescription() {
        return "Example value";
    }

    @Override
    protected Map<?, ?> getMap() {
        Map<String, Object> values = new HashMap<>();
        values.put("liquibase.url", "jdbc:my://database");
        values.put("other.key.here", "my value");
        values.put("liquibase.random", new SecureRandom().nextInt());

        return values;
    }
}