Skip to content

H2 Repository Provider

LeeGod edited this page Jul 4, 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 org.fairy.example.MyPlugin;
import org.fairy.bean.Autowired;
import org.fairy.bean.Component;
import org.fairy.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