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; 022 023import java.sql.Connection; 024import java.sql.SQLException; 025import java.util.Set; 026import java.util.concurrent.ExecutorService; 027 028 029/** 030 * @author Paul Ferraro 031 * @param <D> Driver or DataSource 032 * @since 2.0 033 */ 034public interface SynchronizationContext<D> 035{ 036 /** 037 * Returns a connection to the specified database. 038 * @param database a database to which to connect 039 * @return a database connection 040 * @throws SQLException if connection could not be obtained 041 */ 042 public Connection getConnection(Database<D> database) throws SQLException; 043 044 /** 045 * Returns the database from which to synchronize. 046 * @return a database 047 */ 048 public Database<D> getSourceDatabase(); 049 050 /** 051 * Returns the database to synchronize. 052 * @return a database 053 */ 054 public Database<D> getTargetDatabase(); 055 056 /** 057 * Returns a snapshot of the activate databases in the cluster at the time synchronization started. 058 * @return a collection of databases 059 */ 060 public Set<Database<D>> getActiveDatabaseSet(); 061 062 /** 063 * Returns a cache of database meta data for the source database. 064 * @return a cache of database meta data 065 */ 066 public DatabaseProperties getSourceDatabaseProperties(); 067 068 /** 069 * Returns a cache of database meta data for the target database. 070 * @return a cache of database meta data 071 */ 072 public DatabaseProperties getTargetDatabaseProperties(); 073 074 /** 075 * Returns the dialect of the cluster. 076 * @return a dialect 077 */ 078 public Dialect getDialect(); 079 080 /** 081 * An executor service for executing tasks asynchronously. 082 * @return an executor service 083 */ 084 public ExecutorService getExecutor(); 085 086 /** 087 * Closes any open database connections and shuts down the executor service. 088 */ 089 public void close(); 090}