001 /** 002 * Copyright (C) 2010 The Roslin Institute <contact andy.law@roslin.ed.ac.uk> 003 * 004 * This file is part of the Ensembl Java API demonstration project developed by the 005 * Bioinformatics Group at The Roslin Institute, The Royal (Dick) School of 006 * Veterinary Studies, University of Edinburgh. 007 * 008 * This is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (version 3) as published by 010 * the Free Software Foundation. 011 * 012 * This software is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * in this software distribution. If not, see <http://www.gnu.org/licenses/gpl-3.0.html/>. 019 */ 020 021 package uk.ac.roslin.ensembl.dao.database.factory; 022 023 import java.util.HashMap; 024 import uk.ac.roslin.ensembl.config.EnsemblComparaDivision; 025 import uk.ac.roslin.ensembl.dao.coreaccess.AssemblyDAO; 026 import uk.ac.roslin.ensembl.dao.coreaccess.ProteinFeatureDAO; 027 import uk.ac.roslin.ensembl.dao.coreaccess.DNASequenceDAO; 028 import uk.ac.roslin.ensembl.dao.coreaccess.TranslationDAO; 029 import uk.ac.roslin.ensembl.dao.database.DBCollectionCoreDatabase; 030 031 032 033 //not sure i want this separate hierarchy of DAOs to handle the Species requiremnet 034 import uk.ac.roslin.ensembl.dao.database.DBComparisonDatabase; 035 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBAssemblyDAO; 036 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBChromosomeDAO; 037 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBCoordinateSystemDAO; 038 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBGeneDAO; 039 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBDNASequenceDAO; 040 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBExonDAO; 041 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBProteinFeatureDAO; 042 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBTranscriptDAO; 043 import uk.ac.roslin.ensembl.dao.database.coreaccess.DBTranslationDAO; 044 import uk.ac.roslin.ensembl.dao.factory.DAOCollectionCoreFactory; 045 import uk.ac.roslin.ensembl.dao.factory.DAOCoreFactory; 046 import uk.ac.roslin.ensembl.exception.DAOException; 047 import uk.ac.roslin.ensembl.model.core.CollectionSpecies; 048 import uk.ac.roslin.ensembl.model.database.CollectionCoreDatabase; 049 import uk.ac.roslin.ensembl.model.database.CollectionDatabase; 050 051 052 public class DBDAOCollectionCoreFactory extends DBDAOCollectionFactory implements DAOCollectionCoreFactory { 053 054 private HashMap<String, DBDAOComparaFactory> comparaFactories = 055 new HashMap<String, DBDAOComparaFactory>(); 056 057 public DBDAOCollectionCoreFactory() { 058 super(); 059 } 060 061 062 public DBDAOCollectionCoreFactory(CollectionDatabase database, CollectionSpecies species) throws DAOException { 063 super(database,species); 064 } 065 066 @Override 067 public CollectionCoreDatabase getDatabase() { 068 return (CollectionCoreDatabase) this.database; 069 } 070 071 072 @Override 073 public DBCoordinateSystemDAO getCoordinateSystemDAO() throws DAOException { 074 return new DBCoordinateSystemDAO(this); 075 } 076 077 078 @Override 079 public DBChromosomeDAO getChromosomeDAO() throws DAOException{ 080 return new DBChromosomeDAO(this); 081 } 082 083 @Override 084 public DBGeneDAO getGeneDAO() throws DAOException{ 085 try { 086 return new DBGeneDAO(this); 087 } catch (Exception ex) { 088 return null; 089 } 090 } 091 092 @Override 093 public DBProteinFeatureDAO getProteinFeatureDAO() throws DAOException{ 094 return new DBProteinFeatureDAO(this); 095 } 096 097 098 @Override 099 public DBAssemblyDAO getAssemblyDAO() throws DAOException{ 100 return new DBAssemblyDAO(this); 101 } 102 103 @Override 104 public DBDNASequenceDAO getSequenceDAO() throws DAOException{ 105 return new DBDNASequenceDAO(this); 106 } 107 108 @Override 109 public DBTranslationDAO getTranslationDAO() throws DAOException{ 110 return new DBTranslationDAO(this); 111 } 112 113 @Override 114 public DBTranscriptDAO getTranscriptDAO() throws DAOException{ 115 return new DBTranscriptDAO(this); 116 } 117 118 @Override 119 public DBExonDAO getExonDAO() throws DAOException{ 120 return new DBExonDAO(this); 121 } 122 123 @Override 124 public DBDAOComparaFactory getComparaFactory(EnsemblComparaDivision comparaDivision) { 125 // throw new UnsupportedOperationException("Not supported yet."); 126 127 if (comparaDivision == null) { 128 comparaDivision = EnsemblComparaDivision.MULTI; 129 } 130 131 DBDAOComparaFactory out = null; 132 133 if (this.comparaFactories.containsKey(comparaDivision.toString())) { 134 return this.comparaFactories.get(comparaDivision.toString()); 135 } 136 137 //so far we only have collections for bacteria 138 //so default to the bacterial compara here 139 140 DBComparisonDatabase db = null; 141 142 if (this.getRegistry()!=null) { 143 db= (DBComparisonDatabase) this.getRegistry().getComparaDatabase(comparaDivision != null ? comparaDivision : EnsemblComparaDivision.BACTERIA , 144 dbVersion != null ? dbVersion : String.valueOf(this.getRegistry().getHighestDBVersion())); 145 } 146 147 if (db != null) { 148 out = db.getComparaFactory(); 149 } 150 151 this.comparaFactories.put(comparaDivision.toString(), out); 152 153 return out; 154 155 156 } 157 158 }