/*
 * This file is part of Utils, licensed under the MIT License (MIT).
 *
 * Copyright (c) 2016 - 2016 FlibioStudio
 * Copyright (c) Contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package io.github.flibio.utils.sql;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.plugin.Plugin;

import java.util.Optional;

public class LocalSqlManager extends SqlManager {

    protected LocalSqlManager(Logger logger, String folderName, String file) {
        super(logger, "jdbc:h2:./config/" + folderName + "/" + file + ";AUTO_SERVER=TRUE");
    }

    /**
     * Creates a new LocalSqlManager instance. Uses H2 database.
     * 
     * @param plugin An instance of the main plugin class.
     * @param file The file associated with the data manager
     * @return The new LocalSqlManager instance, if the plugin class is valid.
     */
    public static Optional<LocalSqlManager> createInstance(Object plugin, String file) {
        if (plugin.getClass().isAnnotationPresent(Plugin.class)) {
            Plugin annotation = plugin.getClass().getAnnotation(Plugin.class);
            Logger logger = Sponge.getGame().getPluginManager().getPlugin(annotation.id()).get().getLogger();
            return Optional.of(new LocalSqlManager(logger, annotation.name().toLowerCase().replaceAll(" ", "_"), file));
        } else {
            return Optional.empty();
        }
    }

}

@@ -1557,21 +1557,24 @@
 :h2:
-./config/%22 + 
+%22 + appendSlash(
 fold
@@ -1583,14 +1583,9 @@
 Name
- + %22/%22
+)
  + f
@@ -2310,16 +2310,30 @@
 (logger,
+ %22./config/%22 +
  annotat
@@ -2458,10 +2458,1077 @@
 %0A    %7D%0A%0A
+    /**%0A     * Creates a new LocalSqlManager instance. Uses H2 database.%0A     * %0A     * @param plugin An instance of the main plugin class.%0A     * @param file The file associated with the data manager.%0A     * @param folder The folder to use.%0A     * @return The new LocalSqlManager instance, if the plugin class is valid.%0A     */%0A    public static Optional%3CLocalSqlManager%3E createInstance(Object plugin, String file, String folder) %7B%0A        if (plugin.getClass().isAnnotationPresent(Plugin.class)) %7B%0A            Plugin annotation = plugin.getClass().getAnnotation(Plugin.class);%0A            Logger logger = Sponge.getGame().getPluginManager().getPlugin(annotation.id()).get().getLogger();%0A            return Optional.of(new LocalSqlManager(logger, folder, file));%0A        %7D else %7B%0A            return Optional.empty();%0A        %7D%0A    %7D%0A%0A    private static String appendSlash(String path) %7B%0A        // Append a slash if necessary%0A        if (!path.substring(path.length() - 1).equalsIgnoreCase(%22/%22)) %7B%0A            return path + %22/%22;%0A        %7D%0A        return path;%0A    %7D%0A
 %7D%0A

Allow SQL location to be set