DAO Medge Code Examples
Back to the Main Page

Database Execute

package au.id.medge.daotester.testsuite;

import au.id.medge.dao.utilities.DAOException;
import java.sql.SQLException;

public class ExecuteTest extends AbstractTestSuite {

    public ExecuteTest() {
        super("Execute Test");
    }

    private void testExecute1() {
        try {
            String tableName = (String) getDAO().executeStatement("show create table home.person");
            if (tableName.equalsIgnoreCase("person")) {
                reportSuccess(tableName);
            } else {
                reportFailure(tableName);
            }
        } catch (DAOException | SQLException ex) {
            reportFailure("Execution failed", ex);
        }
    }

    private void testExecute2() {
        try {
            String createTable = (String) getDAO().executeStatement("show create table home.person", 2);
            if (createTable.toLowerCase().contains("create table")) {
                reportSuccess(createTable);
            } else {
                reportFailure(createTable);
            }
        } catch (DAOException | SQLException ex) {
            reportFailure("Execution failed", ex);
        }
    }

    private void testExecuteAll() {
        try {
            Object[] objs = getDAO().executeStatement("show create table home.person", new int[]{1, 2});
            String tableName = (String)objs[0];
            if (tableName.equalsIgnoreCase("person")) {
                reportSuccess(tableName);
            } else {
                reportFailure(tableName);
            }
            
            String createTable = (String)objs[1];
            if (createTable.toLowerCase().contains("create table")) {
                reportSuccess(createTable);
            } else {
                reportFailure(createTable);
            }
        } catch (DAOException | SQLException ex) {
            reportFailure("Execution failed", ex);
        }
    }

    @Override
    public void runTestSuite() {
        testExecute1();
        testExecute2();
        testExecuteAll();
    }

}
Back to the Main Page