Skip to content

H2 Repository Provider

LeeGod edited this page Dec 2, 2021 · 2 revisions

H2 is a part of SQL Storage, but it uses file instead of databases Which is a good storage for Flat File

Repository Provider

package org.fairy.example.repo;

import io.fairyproject.example.MyPlugin;
import io.fairyproject.bean.Autowired;
import io.fairyproject.bean.Component;
import io.fairyproject.mysql.config.file.SimpleFileRepositoryProvider;

import java.nio.file.Path;

/**
 * RepositoryProvider accepts Component scanning
 */
@Component
public class ExampleH2RepositoryProvider extends SimpleFileRepositoryProvider {

    // Wiring your Plugin to here, to get Data Folder
    @Autowired
    private MyPlugin plugin;
    
    public ExampleH2RepositoryProvider() {
        // Writing the name of your repository provider
        super("myRepoProvider");
    }

    @Override
    public Path path() {
        // H2 is a Local File Database, so we give it a path to write data
        return this.plugin.getDataFolder().toPath().resolve("example-h2");
    }
}

Register Repository Provider

Storage.registerRepositoryProvider(new ExampleH2RepositoryProvider());
Clone this wiki locally