001/**
002 * Copyright (C) 2010-2015 The Roslin Institute <contact andy.law@roslin.ed.ac.uk>
003 *
004 * This file is part of JEnsembl: a Java API to Ensembl data sources developed by the
005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of
006 * Veterinary Studies, University of Edinburgh.
007 *
008 * Project hosted at: http://jensembl.sourceforge.net
009 *
010 * This is free software: you can redistribute it and/or modify
011 * it under the terms of the GNU General Public License (version 3) as published by
012 * the Free Software Foundation.
013 *
014 * This software is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * in this software distribution. If not, see: http://opensource.org/licenses/gpl-3.0.html
021 */
022package uk.ac.roslin.ensembl.dao.database.factory;
023
024import java.util.HashMap;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import uk.ac.roslin.ensembl.dao.database.DBAnalysisDAO;
028import uk.ac.roslin.ensembl.dao.factory.DAOFuncgenFactory;
029import uk.ac.roslin.ensembl.datasourceaware.DAAnalysis;
030import uk.ac.roslin.ensembl.exception.DAOException;
031import uk.ac.roslin.ensembl.model.database.SingleSpeciesDatabase;
032
033public class DBDAOSingleSpeciesFuncgenFactory extends DBDAOSingleSpeciesFactory implements DAOFuncgenFactory {
034    
035    private HashMap<Integer, DAAnalysis> analyses;
036    final static Logger LOGGER = LoggerFactory.getLogger(DBDAOSingleSpeciesFuncgenFactory.class);
037    
038    public DBDAOSingleSpeciesFuncgenFactory()   {
039        super ();
040    }
041    public DBDAOSingleSpeciesFuncgenFactory(SingleSpeciesDatabase database)  throws DAOException {
042        super(database);
043    }
044
045
046//    not implemented yet
047//    @Override
048//    public DBSingleSpeciesFuncgenDatabase getDatabase() {
049//        return (DBSingleSpeciesFuncgenDatabase) this.database;
050//    }
051
052    @Override
053    public DBAnalysisDAO getAnalysisDAO()  throws DAOException{
054        return new DBAnalysisDAO(this);
055    }    
056    
057    @Override
058    public DAAnalysis getAnalysis(Integer id) {
059        if (analyses==null) {
060            this.fetchAnalyses();
061        }
062        return analyses.get(id);
063    }
064
065    private void fetchAnalyses() {
066        try {
067            this.analyses = this.getAnalysisDAO().getAnalyses();
068        } catch (DAOException ex) {
069            //at the moment we are just consuming this here
070            LOGGER.info("Factory failed to retrieve Analyses for its Database", ex);
071            analyses = new HashMap<Integer, DAAnalysis>();
072        }   
073    }
074    
075}