001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (c) 2004-2007 Paul Ferraro
004 * 
005 * This library is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Lesser General Public License as published by the 
007 * Free Software Foundation; either version 2.1 of the License, or (at your 
008 * option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this library; if not, write to the Free Software Foundation, 
017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018 * 
019 * Contact: ferraro@users.sourceforge.net
020 */
021package net.sf.hajdbc.cache;
022
023import java.sql.SQLException;
024import java.util.Collection;
025import java.util.Map;
026
027import net.sf.hajdbc.ColumnProperties;
028import net.sf.hajdbc.QualifiedName;
029import net.sf.hajdbc.TableProperties;
030
031/**
032 * @author Paul Ferraro
033 *
034 */
035public abstract class AbstractTableProperties implements TableProperties
036{
037        private final String name;
038        
039        protected AbstractTableProperties(DatabaseMetaDataSupport support, QualifiedName table)
040        {
041                this.name = support.qualifyNameForDML(table);
042        }
043        
044        /**
045         * @see net.sf.hajdbc.TableProperties#getName()
046         */
047        @Override
048        public final String getName()
049        {
050                return this.name;
051        }
052
053        /**
054         * @see net.sf.hajdbc.TableProperties#getColumns()
055         */
056        @Override
057        public final Collection<String> getColumns() throws SQLException
058        {
059                return this.getColumnMap().keySet();
060        }
061
062        /**
063         * @see net.sf.hajdbc.TableProperties#getColumnProperties(java.lang.String)
064         */
065        @Override
066        public final ColumnProperties getColumnProperties(String column) throws SQLException
067        {
068                return this.getColumnMap().get(column);
069        }
070
071        protected abstract Map<String, ColumnProperties> getColumnMap() throws SQLException;
072        
073        /**
074         * @see java.lang.Object#equals(java.lang.Object)
075         */
076        @Override
077        public final boolean equals(Object object)
078        {
079                if ((object == null) || !(object instanceof TableProperties)) return false;
080                        
081                String name = ((TableProperties) object).getName();
082                
083                return (name != null) && name.equals(this.name);
084        }
085
086        /**
087         * @see java.lang.Object#hashCode()
088         */
089        @Override
090        public final int hashCode()
091        {
092                return this.name.hashCode();
093        }
094
095        /**
096         * @see java.lang.Object#toString()
097         */
098        @Override
099        public final String toString()
100        {
101                return this.name;
102        }
103}