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