package cat.calidos.morfeu.utils.injection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import cat.calidos.morfeu.problems.ParsingException;


public class SQLTezt {

protected Connection connection;
protected Statement statement;


@BeforeEach
public void setupDatabase() throws Exception {

	org.h2.Driver.load();
	connection = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa");
	statement = SQLModule.statement(connection);

}


@AfterEach
public void teardown() throws Exception {

	if (statement!=null) {
		statement.execute("SHUTDOWN");
		statement.close();
	}
	if (connection!=null) {
		connection.close();
	}

}


protected void dropPersonsTable() throws ParsingException {
	SQLModule.update(statement, "DROP TABLE IF EXISTS Persons");
}


}


@@ -38,16 +38,37 @@
 ction;%0A%0A
+import java.io.File;%0A
 import j
@@ -146,16 +146,56 @@
 ement;%0A%0A
+import org.apache.commons.io.FileUtils;%0A
 import o
@@ -321,16 +321,54 @@
 eption;%0A
+import cat.calidos.morfeu.utils.Tezt;%0A
 %0A%0Apublic
@@ -382,16 +382,29 @@
 SQLTezt 
+extends Tezt 
 %7B%0A%0Aprote
@@ -462,16 +462,45 @@
 tement;%0A
+private String databasePath;%0A
 %0A%0A@Befor
@@ -558,27 +558,308 @@
 %7B%0A%0A%09
-org.h2.Driver.load(
+File databaseDirectory = setupTempDirectory();%0A%09// we may have concurrency issues with the database, we skip testing then%0A%09org.h2.Driver.load();%0A%09databasePath = databaseDirectory+%22/database%22;%0A%09FileUtils.forceMkdir(new File (databasePath));%0A%09System.err.println(%22Using database temp path %22+databasePath
 );%0A%09
@@ -912,14 +912,28 @@
 :h2:
-~/test
+%22+databasePath+%22/foo
 %22, %22
@@ -1181,16 +1181,110 @@
 ();%0A%09%7D%0A%0A
+//%09if (!databasePath.isEmpty()) %7B%0A//%09%09FileUtils.deleteQuietly(new File (databasePath));%0A//%09%7D%0A%0A
 %7D%0A%0A%0Aprot

fix concurrency database test failure