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.ArrayList;
026import java.util.Collection;
027import java.util.HashMap;
028import java.util.List;
029import java.util.Map;
030
031import net.sf.hajdbc.Dialect;
032import net.sf.hajdbc.QualifiedName;
033import net.sf.hajdbc.SequenceProperties;
034import net.sf.hajdbc.TableProperties;
035
036/**
037 * @author Paul Ferraro
038 *
039 */
040public class EagerDatabaseProperties extends AbstractDatabaseProperties
041{
042        private Map<String, TableProperties> tableMap = new HashMap<String, TableProperties>();
043        private Map<String, SequenceProperties> sequenceMap = new HashMap<String, SequenceProperties>();
044        private List<String> defaultSchemaList;
045
046        public EagerDatabaseProperties(DatabaseMetaData metaData, DatabaseMetaDataSupportFactory factory, Dialect dialect) throws SQLException
047        {
048                super(metaData, factory, dialect);
049                
050                Collection<QualifiedName> tables = this.support.getTables(metaData);
051                
052                for (QualifiedName table: tables)
053                {
054                        TableProperties properties = new EagerTableProperties(metaData, this.support, table);
055                        
056                        this.tableMap.put(properties.getName(), properties);
057                }
058                
059                List<String> defaultSchemaList = this.dialect.getDefaultSchemas(metaData);
060                
061                this.defaultSchemaList = new ArrayList<String>(defaultSchemaList);
062                
063                for (SequenceProperties sequence: this.support.getSequences(metaData))
064                {
065                        this.sequenceMap.put(sequence.getName(), sequence);
066                }
067        }
068        
069        @Override
070        protected List<String> getDefaultSchemaList() throws SQLException
071        {
072                return this.defaultSchemaList;
073        }
074
075        @Override
076        protected Map<String, SequenceProperties> getSequenceMap() throws SQLException
077        {
078                return this.sequenceMap;
079        }
080
081        @Override
082        protected Map<String, TableProperties> getTableMap() throws SQLException
083        {
084                return this.tableMap;
085        }
086}