// Path: erp-library/src/main/java/com.jukusoft/erp/lib/utils/FileUtils.java
// public class FileUtils {
// 
//     /**
//      * read content from file
//      *
//      * @param path
//      *            path to file
//      * @param encoding
//      *            file encoding
//      *
//      * @throws IOException
//      *
//      * @return content of file as string
//      */
//     public static String readFile(String path, Charset encoding) throws IOException {
//         if (!new File(path).exists()) {
//             throw new IOException("File doesnt exists: " + path);
//         }
// 
//         if (!new File(path).canRead()) {
//             throw new IOException("File isnt readable, please correct permissions: " + path);
//         }
// 
//         // read bytes from file
//         byte[] encoded = Files.readAllBytes(Paths.get(path));
// 
//         // convert bytes to string with specific encoding and return string
//         return new String(encoded, encoding);
//     }
// 
//     /**
//      * read lines from file
//      *
//      * @param path
//      *            path to file
//      * @param charset
//      *            encoding of file
//      *
//      * @throws IOException
//      *
//      * @return list of lines from file
//      */
//     public static List<String> readLines(String path, Charset charset) throws IOException {
//         if (!(new File(path)).exists()) {
//             throw new FileNotFoundException("Couldnt find file: " + path);
//         }
// 
//         return Files.readAllLines(Paths.get(path), charset);
//     }
// 
//     /**
//      * write text to file
//      *
//      * @param path
//      *            path to file
//      * @param content
//      *            content of file
//      * @param encoding
//      *            file encoding
//      *
//      * @throws IOException
//      */
//     public static void writeFile(String path, String content, Charset encoding) throws IOException {
//         Files.write(Paths.get(path), content.getBytes(encoding), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
//     }
// 
//     /**
//     * get path to user.home directory
//      *
//      * @return path to user.home directory
//     */
//     public static String getUserHomeDir () {
//         return System.getProperty("user.home");
//     }
// 
//     public static String getAppHomeDir (String appName) {
//         return getUserHomeDir() + "/." + appName + "/";
//     }
// 
// }


import com.jukusoft.erp.lib.utils.FileUtils;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.jdbc.JDBCClient;
import io.vertx.ext.sql.ResultSet;
import io.vertx.ext.sql.SQLClient;
import io.vertx.ext.sql.SQLConnection;
import io.vertx.ext.sql.UpdateResult;
import org.json.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static io.vertx.ext.sync.Sync.awaitResult;
package com.jukusoft.erp.lib.database;




public class MySQLDatabase implements Database {

    //instance of vertx
    protected Vertx vertx = null;

    //sql client
    protected SQLClient client = null;

    //sql connection
    protected SQLConnection connection = null;

    //table prefix
    protected String prefix = "";

    public MySQLDatabase (Vertx vertx) {
        this.vertx = vertx;
    }

    @Override
    public void connect (String configFile, Handler<Future<Void>> handler) throws IOException {
        //check, if config file exists
        if (!new File(configFile).exists()) {
            throw new FileNotFoundException("Couldnt found database config file '" + configFile + "'.");
        }

        //read file content
// Path: erp-library/src/main/java/com.jukusoft/erp/lib/utils/FileUtils.java
// public class FileUtils {
// 
//     /**
//      * read content from file
//      *
//      * @param path
//      *            path to file
//      * @param encoding
//      *            file encoding
//      *
//      * @throws IOException
//      *
//      * @return content of file as string
//      */
//     public static String readFile(String path, Charset encoding) throws IOException {
//         if (!new File(path).exists()) {
//             throw new IOException("File doesnt exists: " + path);
//         }
// 
//         if (!new File(path).canRead()) {
//             throw new IOException("File isnt readable, please correct permissions: " + path);
//         }
// 
//         // read bytes from file
//         byte[] encoded = Files.readAllBytes(Paths.get(path));
// 
//         // convert bytes to string with specific encoding and return string
//         return new String(encoded, encoding);
//     }
// 
//     /**
//      * read lines from file
//      *
//      * @param path
//      *            path to file
//      * @param charset
//      *            encoding of file
//      *
//      * @throws IOException
//      *
//      * @return list of lines from file
//      */
//     public static List<String> readLines(String path, Charset charset) throws IOException {
//         if (!(new File(path)).exists()) {
//             throw new FileNotFoundException("Couldnt find file: " + path);
//         }
// 
//         return Files.readAllLines(Paths.get(path), charset);
//     }
// 
//     /**
//      * write text to file
//      *
//      * @param path
//      *            path to file
//      * @param content
//      *            content of file
//      * @param encoding
//      *            file encoding
//      *
//      * @throws IOException
//      */
//     public static void writeFile(String path, String content, Charset encoding) throws IOException {
//         Files.write(Paths.get(path), content.getBytes(encoding), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
//     }
// 
//     /**
//     * get path to user.home directory
//      *
//      * @return path to user.home directory
//     */
//     public static String getUserHomeDir () {
//         return System.getProperty("user.home");
//     }
// 
//     public static String getAppHomeDir (String appName) {
//         return getUserHomeDir() + "/." + appName + "/";
//     }
// 
// }


// Path: erp-library/src/main/java/com.jukusoft/erp/lib/database/MySQLDatabase.java
import com.jukusoft.erp.lib.utils.FileUtils;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.jdbc.JDBCClient;
import io.vertx.ext.sql.ResultSet;
import io.vertx.ext.sql.SQLClient;
import io.vertx.ext.sql.SQLConnection;
import io.vertx.ext.sql.UpdateResult;
import org.json.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static io.vertx.ext.sync.Sync.awaitResult;

package com.jukusoft.erp.lib.database;




public class MySQLDatabase implements Database {

    //instance of vertx
    protected Vertx vertx = null;

    //sql client
    protected SQLClient client = null;

    //sql connection
    protected SQLConnection connection = null;

    //table prefix
    protected String prefix = "";

    public MySQLDatabase (Vertx vertx) {
        this.vertx = vertx;
    }

    @Override
    public void connect (String configFile, Handler<Future<Void>> handler) throws IOException {
        //check, if config file exists
        if (!new File(configFile).exists()) {
            throw new FileNotFoundException("Couldnt found database config file '" + configFile + "'.");
        }

        //read file content
        String content = FileUtils.readFile(configFile, StandardCharsets.UTF_8);