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.datasourceaware; 022 023 import java.io.Serializable; 024 import java.util.Comparator; 025 import uk.ac.roslin.ensembl.model.database.Registry; 026 import uk.ac.roslin.ensembl.dao.factory.DAOFactory; 027 import uk.ac.roslin.ensembl.model.IdentifiableObject; 028 029 030 /** 031 * @author paterson 032 */ 033 public abstract class DAObject implements IdentifiableObject { 034 035 036 protected DAOFactory daoFactory = null; 037 protected String schemaVersion = null; 038 protected String dbVersion = null; 039 protected Registry registry = null; 040 protected Integer id = null; 041 042 public DAObject() { 043 044 } 045 046 public DAObject(DAOFactory factory) { 047 this.setDaoFactory(factory); 048 } 049 050 public DAOFactory getDaoFactory() { 051 return daoFactory; 052 } 053 054 public void setDaoFactory(DAOFactory daoFactory) { 055 if (daoFactory != null) { 056 this.daoFactory = daoFactory; 057 this.setSchemaVersion(daoFactory.getEnsemblSchemaVersion()); 058 this.setDBVersion(daoFactory.getDBVersion()); 059 this.setRegistry(daoFactory.getRegistry()); 060 } 061 } 062 063 public String getSchemaVersion() { 064 return schemaVersion; 065 } 066 067 private void setSchemaVersion(String eSchemaVersion) { 068 this.schemaVersion = eSchemaVersion; 069 } 070 071 public String getDBVersion() { 072 return dbVersion; 073 } 074 075 private void setDBVersion(String dbversion) { 076 this.dbVersion = dbversion; 077 } 078 079 public Registry getRegistry() { 080 return registry; 081 } 082 083 public void setRegistry(Registry datasource) { 084 this.registry = datasource; 085 } 086 087 public Integer getId() { 088 return id; 089 } 090 091 public void setId(Integer id) { 092 this.id = id; 093 } 094 095 096 public String getHashID() { 097 return 098 ((this.getDaoFactory()!=null) ? this.getDaoFactory().getDatabaseName() : "NODATABASE") 099 100 +"_" 101 102 +((this.getType()!=null) ? this.getType().toString() : "NOTYPE") 103 104 +"_" 105 106 +((this.getId()!=null) ? this.getId().toString() : "NOID"); 107 } 108 109 110 public static final class DAComparator implements Comparator<DAObject>, Serializable { 111 112 public int compare(DAObject o1, DAObject o2) { 113 114 if (o1 != null && o2 != null) { 115 return ((DAObject)o1 ).getHashID().compareTo(((DAObject)o2).getHashID()); 116 } 117 118 return 0; 119 } 120 121 } 122 123 public static final DAComparator daComparator = new DAComparator(); 124 125 }