2
* HA-JDBC: High-Availability JDBC
3
* Copyright (c) 2004-2007 Paul Ferraro
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License as published by the
7
* Free Software Foundation; either version 2.1 of the License, or (at your
8
* option) any later version.
10
* This library is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library; if not, write to the Free Software Foundation,
17
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Contact: ferraro@users.sourceforge.net
21
package net.sf.hajdbc.cache;
23
import java.sql.Connection;
24
import java.sql.SQLException;
26
import net.sf.hajdbc.Balancer;
27
import net.sf.hajdbc.Database;
28
import net.sf.hajdbc.DatabaseProperties;
29
import net.sf.hajdbc.Dialect;
32
* DatabaseMetaDataCache implementation that eagerly caches data when first flushed.
33
* To be used when performance more of a concern than memory usage.
35
* @author Paul Ferraro
38
public class EagerDatabaseMetaDataCache<D> extends AbstractDatabaseMetaDataCache
40
private volatile DatabaseProperties properties;
41
private final Balancer<D> balancer;
43
public EagerDatabaseMetaDataCache(Dialect dialect, Balancer<D> balancer)
47
this.balancer = balancer;
51
* @see net.sf.hajdbc.DatabaseMetaDataCache#flush()
54
public void flush() throws SQLException
56
Database<D> database = this.balancer.next();
58
this.setDatabaseProperties(database.connect(database.createConnectionFactory()));
62
* @see net.sf.hajdbc.DatabaseMetaDataCache#getDatabaseProperties(java.sql.Connection)
65
public synchronized DatabaseProperties getDatabaseProperties(Connection connection) throws SQLException
67
if (this.properties == null)
69
this.setDatabaseProperties(connection);
72
return this.properties;
75
private synchronized void setDatabaseProperties(Connection connection) throws SQLException
77
this.properties = new EagerDatabaseProperties(connection.getMetaData(), this.factory, this.dialect);
b'\\ No newline at end of file'