org.etlunit.feature.mysql_database.MySQLDatabaseImplementation Maven / Gradle / Ivy
package org.etlunit.feature.mysql_database;
import com.mysql.jdbc.Driver;
import org.etlunit.feature.database.BaseDatabaseImplemenation;
import org.etlunit.feature.database.DatabaseConnection;
import org.etlunit.parser.ETLTestValueObject;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class MySQLDatabaseImplementation extends BaseDatabaseImplemenation
{
public data_format getDataFormatForExtract(ETLTestValueObject operands)
{
return null;
}
public database_state getDatabaseState(DatabaseConnection databaseConnection, String s)
{
return database_state.fail;
}
public String getImplementationId()
{
return "mysql";
}
public Object processOperation(operation op, OperationRequest request) throws UnsupportedOperationException
{
switch (op)
{
case executeSql:
break;
case createDatabase:
break;
case completeDatabaseInitialization:
break;
case prepareDatabase:
PrepareRequest prepReq = request.getPrepareRequest();
try
{
Connection conn = getConnection(prepReq.getConnection(), prepReq.getMode());
// get a list of all tables to clear
Statement st = conn.createStatement();
Statement trunc_st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA != 'SYSTEM_LOBS'");
while (rs.next())
{
// batch a truncate
trunc_st.addBatch("TRUNCATE TABLE " + rs.getString(1) + "." + rs.getString(2));
}
trunc_st.executeBatch();
}
catch (Exception e)
{
throw new RuntimeException("Error preparing database", e);
}
break;
}
return null;
}
@Override
protected String getJdbcUrl(DatabaseConnection dc, String mode, int id)
{
return "jdbc:mysql:/" + dc.getServerName() + "/" + dc.getDatabaseName(mode);
}
@Override
protected Class getJdbcDriverClass()
{
return Driver.class;
}
public String getDefaultSchema(DatabaseConnection databaseConnection, String mode)
{
return databaseConnection.getDatabaseName(mode);
}
}