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 (dBversion 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;
022    
023    import java.util.Collection;
024    import java.util.HashMap;
025    import java.util.TreeSet;
026    import uk.ac.roslin.ensembl.model.database.CollectionDatabase;
027    import uk.ac.roslin.ensembl.model.core.CollectionSpecies;
028    import uk.ac.roslin.ensembl.model.database.DatabaseType;
029    import uk.ac.roslin.ensembl.model.core.CollectionOfSpecies;
030    
031    public class DBCollection implements CollectionOfSpecies  {
032    
033        private String collectionName="";
034        private String dBversion="";
035        private String schemaVersion="";
036        private TreeSet<DBCollectionSpecies> species = new TreeSet<DBCollectionSpecies>();
037        private DBCollectionCoreDatabase coreDatabase;
038        private TreeSet<DBCollectionDatabase> databases = new TreeSet<DBCollectionDatabase>();
039    
040        public DBCollection() {
041        }
042    
043        public DBCollection(DBCollectionCoreDatabase database) {
044            this.setPrimaryCoreDatabase(database);
045        }
046    
047        public void setPrimaryCoreDatabase(DBCollectionCoreDatabase database) {
048            this.coreDatabase = database;
049            if (this.coreDatabase != null) {
050                this.databases.add(database);
051            }
052            collectionName=this.coreDatabase!=null ? coreDatabase.getCollectionName() : null;
053            schemaVersion = this.coreDatabase!=null ? coreDatabase.getSchemaVersion() : null;
054            dBversion = this.coreDatabase != null ? coreDatabase.getDBVersion() : null ;
055        }
056    
057    
058        @Override
059        public void setProperty(String id, HashMap row) {
060        }
061    
062        @Override
063        public String getDBVersion() {
064            return dBversion;
065        }
066    
067        @Override
068        public String getCollectionName() {
069            return collectionName;
070        }
071    
072        @Override
073        public TreeSet<DBCollectionDatabase> getDatabases() {
074            return databases;
075        }
076    
077        @Override
078        public void addDatabases(TreeSet<? extends CollectionDatabase> databases) {
079    
080            for (CollectionDatabase d : databases) {
081                try {
082                    this.databases.add((DBCollectionDatabase) d);
083                } catch (Exception e) {
084                }
085            }
086        }
087    
088        @Override
089        public TreeSet<DBCollectionSpecies> getSpecies() {
090            return this.species;
091        }
092    
093        @Override
094        public void addSpecies(Collection<? extends CollectionSpecies> spp) {
095            for (CollectionSpecies cs : spp) {
096                    this.addSpecies(cs);
097            }
098        }
099    
100        @Override
101        public void addSpecies(CollectionSpecies sp) {
102                try {
103                    this.species.add((DBCollectionSpecies) sp);
104                } catch (Exception e) {
105                }
106        }
107    
108        @Override
109        public DBCollectionCoreDatabase getCoreDatabase() {
110            return coreDatabase;
111        }
112    
113        @Override
114        public String getSchemaVersion() {
115            return schemaVersion;
116        }
117    
118        @Override
119        public TreeSet<DBCollectionDatabase> getDatabasesByType(DatabaseType type) {
120            TreeSet<DBCollectionDatabase> out = new TreeSet<DBCollectionDatabase>();
121            for (DBCollectionDatabase d : databases) {
122                if (d.getType()==type) {
123                    out.add(d);
124                }
125            }
126            return out;
127        }
128    
129        @Override
130        public String toString() {
131            return this.collectionName;
132        }
133    
134    
135    }