001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (c) 2004-2008 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.List; 027import java.util.Map; 028 029import net.sf.hajdbc.DatabaseProperties; 030import net.sf.hajdbc.Dialect; 031import net.sf.hajdbc.SequenceProperties; 032import net.sf.hajdbc.TableProperties; 033 034/** 035 * @author Paul Ferraro 036 * 037 */ 038public abstract class AbstractDatabaseProperties implements DatabaseProperties 039{ 040 protected final Dialect dialect; 041 protected final DatabaseMetaDataSupport support; 042 043 private final boolean supportsSelectForUpdate; 044 045 protected AbstractDatabaseProperties(DatabaseMetaData metaData, DatabaseMetaDataSupportFactory factory, Dialect dialect) throws SQLException 046 { 047 this.dialect = dialect; 048 this.support = factory.createSupport(metaData, dialect); 049 this.supportsSelectForUpdate = metaData.supportsSelectForUpdate(); 050 } 051 052 /** 053 * @see net.sf.hajdbc.DatabaseProperties#supportsSelectForUpdate() 054 */ 055 @Override 056 public final boolean supportsSelectForUpdate() throws SQLException 057 { 058 return this.supportsSelectForUpdate; 059 } 060 061 /** 062 * @see net.sf.hajdbc.DatabaseProperties#getTables() 063 */ 064 @Override 065 public final Collection<TableProperties> getTables() throws SQLException 066 { 067 return this.getTableMap().values(); 068 } 069 070 /** 071 * @see net.sf.hajdbc.DatabaseProperties#getSequences() 072 */ 073 @Override 074 public final Collection<SequenceProperties> getSequences() throws SQLException 075 { 076 return this.getSequenceMap().values(); 077 } 078 079 /** 080 * @see net.sf.hajdbc.DatabaseProperties#findTable(java.lang.String) 081 */ 082 @Override 083 public final TableProperties findTable(String table) throws SQLException 084 { 085 return this.support.find(this.getTableMap(), table, this.getDefaultSchemaList()); 086 } 087 088 /** 089 * @see net.sf.hajdbc.DatabaseProperties#findSequence(java.lang.String) 090 */ 091 @Override 092 public final SequenceProperties findSequence(String sequence) throws SQLException 093 { 094 return this.support.find(this.getSequenceMap(), sequence, this.getDefaultSchemaList()); 095 } 096 097 protected abstract Map<String, TableProperties> getTableMap() throws SQLException; 098 099 protected abstract Map<String, SequenceProperties> getSequenceMap() throws SQLException; 100 101 protected abstract List<String> getDefaultSchemaList() throws SQLException; 102}