001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.cache.simple; 019 020import java.sql.Connection; 021import java.sql.DatabaseMetaData; 022import java.sql.SQLException; 023 024import net.sf.hajdbc.Database; 025import net.sf.hajdbc.DatabaseCluster; 026import net.sf.hajdbc.DatabaseProperties; 027import net.sf.hajdbc.cache.DatabaseMetaDataCache; 028import net.sf.hajdbc.cache.lazy.LazyDatabaseProperties; 029import net.sf.hajdbc.dialect.Dialect; 030 031/** 032 * DatabaseMetaDataCache implementation that does not cache data. 033 * To be used when memory usage is more of a concern than performance. 034 * 035 * @author Paul Ferraro 036 * @since 2.0 037 */ 038public class SimpleDatabaseMetaDataCache<Z, D extends Database<Z>> implements DatabaseMetaDataCache<Z, D> 039{ 040 private final DatabaseCluster<Z, D> cluster; 041 042 public SimpleDatabaseMetaDataCache(DatabaseCluster<Z, D> cluster) 043 { 044 this.cluster = cluster; 045 } 046 047 /** 048 * @see net.sf.hajdbc.cache.DatabaseMetaDataCache#flush() 049 */ 050 @Override 051 public void flush() 052 { 053 // Nothing to flush 054 } 055 056 /** 057 * {@inheritDoc} 058 * @see net.sf.hajdbc.cache.DatabaseMetaDataCache#getDatabaseProperties(net.sf.hajdbc.Database, java.sql.Connection) 059 */ 060 @Override 061 public DatabaseProperties getDatabaseProperties(D database, Connection connection) throws SQLException 062 { 063 DatabaseMetaData metaData = connection.getMetaData(); 064 Dialect dialect = this.cluster.getDialect(); 065 return new LazyDatabaseProperties(new SimpleDatabaseMetaDataProvider(metaData), dialect); 066 } 067}