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.DatabaseMetaData;
024import java.sql.SQLException;
025import java.util.Collection;
026import java.util.Map;
027
028import net.sf.hajdbc.ColumnProperties;
029import net.sf.hajdbc.ForeignKeyConstraint;
030import net.sf.hajdbc.QualifiedName;
031import net.sf.hajdbc.UniqueConstraint;
032
033/**
034 * @author Paul Ferraro
035 *
036 */
037public class EagerTableProperties extends AbstractTableProperties
038{
039        private Map<String, ColumnProperties> columnMap;
040        private UniqueConstraint primaryKey;
041        private Collection<UniqueConstraint> uniqueConstraints;
042        private Collection<ForeignKeyConstraint> foreignKeyConstraints;
043        private Collection<String> identityColumns;
044        
045        public EagerTableProperties(DatabaseMetaData metaData, DatabaseMetaDataSupport support, QualifiedName table) throws SQLException
046        {
047                super(support, table);
048                
049                this.columnMap = support.getColumns(metaData, table);
050                this.primaryKey = support.getPrimaryKey(metaData, table);
051                this.uniqueConstraints = support.getUniqueConstraints(metaData, table, this.primaryKey);
052                this.foreignKeyConstraints = support.getForeignKeyConstraints(metaData, table);
053                this.identityColumns = support.getIdentityColumns(this.columnMap.values());
054        }
055
056        @Override
057        protected Map<String, ColumnProperties> getColumnMap()
058        {
059                return this.columnMap;
060        }
061
062        /**
063         * @see net.sf.hajdbc.TableProperties#getPrimaryKey()
064         */
065        @Override
066        public UniqueConstraint getPrimaryKey()
067        {
068                return this.primaryKey;
069        }
070
071        /**
072         * @see net.sf.hajdbc.TableProperties#getForeignKeyConstraints()
073         */
074        @Override
075        public Collection<ForeignKeyConstraint> getForeignKeyConstraints()
076        {
077                return this.foreignKeyConstraints;
078        }
079
080        /**
081         * @see net.sf.hajdbc.TableProperties#getUniqueConstraints()
082         */
083        @Override
084        public Collection<UniqueConstraint> getUniqueConstraints()
085        {
086                return this.uniqueConstraints;
087        }
088
089        /**
090         * @see net.sf.hajdbc.TableProperties#getIdentityColumns()
091         */
092        @Override
093        public Collection<String> getIdentityColumns() throws SQLException
094        {
095                return this.identityColumns;
096        }
097}