/*
 * Copyright (C) 2017 Julien Viet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package io.vertx.ext.asyncsql;

import com.wix.mysql.EmbeddedMysql;
import com.wix.mysql.config.DownloadConfig;
import com.wix.mysql.config.MysqldConfig;
import com.wix.mysql.distribution.Version;

import java.lang.reflect.Field;

import static com.wix.mysql.config.MysqldConfig.aMysqldConfig;
import static com.wix.mysql.distribution.Version.v5_5_40;
import static com.wix.mysql.distribution.Version.v5_6_latest;

/**
 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
 */
public class MySQL {

  public synchronized static MySQL start(int port) throws Exception {
    // Monkey patching to use 5_5_9
    // https://bugs.mysql.com/bug.php?id=60544
    Version version = Version.v5_5_40;
    Field field = version.getDeclaringClass().getDeclaredField("minorVersion");
    field.setAccessible(true);
    field.set(version, 9);
    MysqldConfig cfg = aMysqldConfig(version)
      .withUser("vertx", "password")
      .withPort(port)
      .build();
    EmbeddedMysql.Builder builder = new EmbeddedMysql.Builder(cfg, new DownloadConfig.Builder().build())
      .addSchema("testdb");
    return new MySQL(builder.start());
  }

  private EmbeddedMysql process;

  public MySQL(EmbeddedMysql process) {
    this.process = process;
  }

  public synchronized void stop() throws Exception {
    if (process != null) {
      try {
        process.stop();
      } finally {
        process = null;
      }
    }
  }
}

@@ -749,84 +749,8 @@
 fig;
-%0Aimport com.wix.mysql.distribution.Version;%0A%0Aimport java.lang.reflect.Field;
 %0A%0Aim
@@ -814,66 +814,8 @@
 ig;%0A
-import static com.wix.mysql.distribution.Version.v5_5_40;%0A
 impo
@@ -1043,268 +1043,8 @@
 n %7B%0A
-    // Monkey patching to use 5_5_9%0A    // https://bugs.mysql.com/bug.php?id=60544%0A    Version version = Version.v5_5_40;%0A    Field field = version.getDeclaringClass().getDeclaredField(%22minorVersion%22);%0A    field.setAccessible(true);%0A    field.set(version, 9);%0A
     
@@ -1077,22 +1077,26 @@
 Config(v
-ersion
+5_6_latest
 )%0A      

Revert "Force to use MySQL 5.5.9"