// Path: src/fi/mamk/osa/database/sql/DataModel.java
// public abstract class DataModel {
//     
//     public abstract HashMap<String,String> getResourceColumns();
//     public abstract HashMap<String,String> getSimpleTables();
//     public abstract HashMap<String,HashMap<String,String>> getComplexTables();
// 
// }
// 
// Path: src/fi/mamk/osa/database/sql/SQLManager.java
// public abstract class SQLManager extends DatabaseManager {
//     
//     private static final Logger logger = Logger.getLogger(SQLManager.class);
//     
//     public static DataSource dataSource = null;
//     public static MiniConnectionPoolManager poolManager = null;
//   
//     /**
//      * Get db connection
//      * @return
//      * @throws SQLException
//      */
//     public static Connection getConnection() throws SQLException {
//         if (dataSource != null) {
//             return dataSource.getConnection();
//         }
//         if (poolManager != null) {
//             return poolManager.getConnection();
//         }
//         return null;
//     }
//     
//     /** 
//      * Checks the database status.
//      * 
//      * @return true if database is working properly. 
//      *         false if any of needed databases is offline
//      */
//     public abstract boolean testDatabase();    
// }


import java.sql.Connection;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Vector;
import org.apache.log4j.Logger;
import fi.mamk.osa.database.sql.DataModel;
import fi.mamk.osa.database.sql.SQLManager;
package fi.mamk.osa.database.sql.mysql;



//import fi.mamk.osa.bean.OsaResourceBean;

/**
 * A Class that binds xml Schema to a database 
 * @author Jussi Juvén
 */
public class MySQLDataModel extends DataModel {
    
    private static final Logger logger = Logger.getLogger(MySQLDataModel.class); 
        
    public HashMap<String,String> resourceColumns = new HashMap<String, String>();
    public HashMap<String,String> simpleTables = new HashMap<String, String>();
    public HashMap<String,HashMap<String,String>> complexTables = new HashMap<String,HashMap<String,String>>();       
    
    /**
     * Default Constructor for a Datamodel
     * 
     * @param xmlFile xml Schema file to parse
     * @throws java.lang.Exception
     */
    public MySQLDataModel() throws Exception {
//        if(!this.loadSchemaFromBean((null))) {
//            throw new Exception("Unable to load Schema from bean");
//        }
        logger.debug("Checking database...");
        if(!this.checkDatabase()) {
            throw new Exception("database error");
        }
        
        logger.debug("Database checked. - OK");
        
    }

    
    /**
     * Checks database against loaded Schema.
     * 
     * @return success
     * @throws java.lang.Exception
     */
    private boolean checkDatabase() {
        
        boolean retval = true;
        Connection con = null;
        try {       
            
// Path: src/fi/mamk/osa/database/sql/DataModel.java
// public abstract class DataModel {
//     
//     public abstract HashMap<String,String> getResourceColumns();
//     public abstract HashMap<String,String> getSimpleTables();
//     public abstract HashMap<String,HashMap<String,String>> getComplexTables();
// 
// }
// 
// Path: src/fi/mamk/osa/database/sql/SQLManager.java
// public abstract class SQLManager extends DatabaseManager {
//     
//     private static final Logger logger = Logger.getLogger(SQLManager.class);
//     
//     public static DataSource dataSource = null;
//     public static MiniConnectionPoolManager poolManager = null;
//   
//     /**
//      * Get db connection
//      * @return
//      * @throws SQLException
//      */
//     public static Connection getConnection() throws SQLException {
//         if (dataSource != null) {
//             return dataSource.getConnection();
//         }
//         if (poolManager != null) {
//             return poolManager.getConnection();
//         }
//         return null;
//     }
//     
//     /** 
//      * Checks the database status.
//      * 
//      * @return true if database is working properly. 
//      *         false if any of needed databases is offline
//      */
//     public abstract boolean testDatabase();    
// }


// Path: src/fi/mamk/osa/database/sql/mysql/MySQLDataModel.java
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Vector;
import org.apache.log4j.Logger;
import fi.mamk.osa.database.sql.DataModel;
import fi.mamk.osa.database.sql.SQLManager;

package fi.mamk.osa.database.sql.mysql;



//import fi.mamk.osa.bean.OsaResourceBean;

/**
 * A Class that binds xml Schema to a database 
 * @author Jussi Juvén
 */
public class MySQLDataModel extends DataModel {
    
    private static final Logger logger = Logger.getLogger(MySQLDataModel.class); 
        
    public HashMap<String,String> resourceColumns = new HashMap<String, String>();
    public HashMap<String,String> simpleTables = new HashMap<String, String>();
    public HashMap<String,HashMap<String,String>> complexTables = new HashMap<String,HashMap<String,String>>();       
    
    /**
     * Default Constructor for a Datamodel
     * 
     * @param xmlFile xml Schema file to parse
     * @throws java.lang.Exception
     */
    public MySQLDataModel() throws Exception {
//        if(!this.loadSchemaFromBean((null))) {
//            throw new Exception("Unable to load Schema from bean");
//        }
        logger.debug("Checking database...");
        if(!this.checkDatabase()) {
            throw new Exception("database error");
        }
        
        logger.debug("Database checked. - OK");
        
    }

    
    /**
     * Checks database against loaded Schema.
     * 
     * @return success
     * @throws java.lang.Exception
     */
    private boolean checkDatabase() {
        
        boolean retval = true;
        Connection con = null;
        try {       
            
            con = SQLManager.dataSource.getConnection();