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;
023
024
025import uk.ac.roslin.ensembl.model.database.CollectionDatabase;
026import uk.ac.roslin.ensembl.exception.ConfigurationException;
027import uk.ac.roslin.ensembl.model.core.CollectionOfSpecies;
028import uk.ac.roslin.ensembl.config.EnsemblDBType;
029import uk.ac.roslin.ensembl.model.database.Registry;
030
031/**
032 *
033 * @author paterson
034 */
035// will make this abstract once we fill in all the subtypes
036public class DBCollectionDatabase extends DBDatabase implements CollectionDatabase {
037    protected String collectionName = null;
038    protected DBCollection collection = null;
039    
040    public DBCollectionDatabase(String db_name, EnsemblDBType type, Registry registry) throws ConfigurationException {
041        super(db_name, type, registry);
042        init();
043    }
044
045    private void init() throws ConfigurationException {
046
047        this.collectionName = dBName.substring(0, dBName.indexOf("_" + this.type.toString()));
048
049        this.dBClassifier = collectionName;
050
051        String sub = dBName.replace(collectionName + "_" + type.toString() + "_", "");
052        if (sub.contains("_")) {
053            this.dbVersion = sub.substring(0, sub.indexOf("_"));
054            intDBVersion = Integer.parseInt(dbVersion);
055            sub = sub.replaceFirst(dbVersion + "_", "");
056            if (sub.contains("_")) {
057                this.schemaVersion = sub.substring(0, sub.indexOf("_"));
058                intSchemaVersion = Integer.parseInt(schemaVersion);
059                build = sub.replace(schemaVersion + "_", "");
060            } else {
061                this.schemaVersion = sub;
062                intSchemaVersion = Integer.parseInt(schemaVersion);
063            }
064
065
066        } else {
067            // i don;t think this should ever arise....
068            this.dbVersion = sub;
069            intDBVersion = Integer.parseInt(dbVersion);
070            schemaVersion = dbVersion;
071            intSchemaVersion = intDBVersion;
072        }
073
074    }
075
076    @Override
077    public String getCollectionName() {
078        return collectionName;
079    }
080
081    @Override
082    public void setCollectionName(String collectionName) {
083        this.collectionName = collectionName;
084    }
085
086    @Override
087    public void setCollection(CollectionOfSpecies r) {
088        this.collection = (DBCollection) r;
089    }
090
091    @Override
092    public DBCollection getCollection() {
093        return this.collection;
094    }
095
096}