// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package dbcache;

import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Utility {
    protected static List<String> labels = new ArrayList<String>();
    protected static List<String> counters = new ArrayList<String>();
    protected static List<DAL> dals = new ArrayList<DAL>();
    private static void add(String label, String counter, DAL dal) {
        labels.add(label);
        counters.add(counter);
        dals.add(dal);
    }
    protected static void addAll() throws ClassNotFoundException, SQLException, URISyntaxException {
        add("Plain JDBC - no app cache", "c1", new DAL_JDBC("jdbc:mysql://localhost/test", "root", ""));
        add("Plain JDBC - local app cache", "c2", new DAL_LocalCache(new DAL_JDBC("jdbc:mysql://localhost/test", "root", "")));
        add("Plain JDBC - remote app cache", "c3", new DAL_RemoteCache(new DAL_JDBC("jdbc:mysql://localhost/test", "root", "")));
        add("JPA - no app cache, no Hibernate level2 cache", "c4", new DAL_JPA("hibernate_mysql_nocache"));
        add("JPA - local app cache, no Hibernate level2 cache", "c5", new DAL_LocalCache(new DAL_JPA("hibernate_mysql_nocache")));
        add("JPA - remote app cache, no Hibernate level2 cache", "c6", new DAL_RemoteCache(new DAL_JPA("hibernate_mysql_nocache")));
        add("JPA - no app cache, local Hibernate level2 cache", "c7", new DAL_JPA("hibernate_mysql_localcache"));
        add("JPA - no app cache, remote Hibernate level2 cache", "c8", new DAL_JPA("hibernate_mysql_remotecache"));
    }
    protected static void closeAll() {
        for(DAL dal : dals) {
            dal.close();
        }
    }
}
