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.util.Collection; 024import java.util.List; 025import java.util.Map; 026import java.util.concurrent.ExecutorService; 027 028/** 029 * @author Paul Ferraro 030 * @param <D> either java.sql.Driver or javax.sql.DataSource 031 */ 032public interface DatabaseCluster<D> extends Lifecycle 033{ 034 /** 035 * Returns the identifier of this cluster. 036 * @return an identifier 037 */ 038 public String getId(); 039 040 /** 041 * Activates the specified database 042 * @param database a database descriptor 043 * @param manager a state manager 044 * @return true, if the database was activated, false it was already active 045 */ 046 public boolean activate(Database<D> database, StateManager manager); 047 048 /** 049 * Deactivates the specified database 050 * @param database a database descriptor 051 * @param manager a state manager 052 * @return true, if the database was deactivated, false it was already inactive 053 */ 054 public boolean deactivate(Database<D> database, StateManager manager); 055 056 /** 057 * Returns the database identified by the specified id 058 * @param id a database identifier 059 * @return a database descriptor 060 * @throws IllegalArgumentException if no database exists with the specified identifier 061 */ 062 public Database<D> getDatabase(String id); 063 064 /** 065 * Returns the Balancer implementation used by this database cluster. 066 * @return an implementation of <code>Balancer</code> 067 */ 068 public Balancer<D> getBalancer(); 069 070 /** 071 * Returns an executor service used to execute transactional database writes. 072 * @return an implementation of <code>ExecutorService</code> 073 */ 074 public ExecutorService getTransactionalExecutor(); 075 076 /** 077 * Returns an executor service used to execute non-transactional database writes. 078 * @return an implementation of <code>ExecutorService</code> 079 */ 080 public ExecutorService getNonTransactionalExecutor(); 081 082 /** 083 * Returns a dialect capable of returning database vendor specific values. 084 * @return an implementation of <code>Dialect</code> 085 */ 086 public Dialect getDialect(); 087 088 /** 089 * Returns a LockManager capable of acquiring named read/write locks on the specific objects in this database cluster. 090 * @return a LockManager implementation 091 */ 092 public LockManager getLockManager(); 093 094 /** 095 * Sets the LockManager implementation capable of acquiring named read/write locks on the specific objects in this database cluster. 096 * @param lockManager a lock manager 097 */ 098 public void setLockManager(LockManager lockManager); 099 100 /** 101 * Returns a StateManager for persisting database cluster state. 102 * @return a StateManager implementation 103 */ 104 public StateManager getStateManager(); 105 106 /** 107 * Sets the StateManager implementation for persisting database cluster state. 108 * @param stateManager a state manager 109 */ 110 public void setStateManager(StateManager stateManager); 111 112 /** 113 * Returns a DatabaseMetaData cache. 114 * @return a <code>DatabaseMetaDataCache</code> implementation 115 */ 116 public DatabaseMetaDataCache getDatabaseMetaDataCache(); 117 118 /** 119 * Indicates whether or not sequence detection is enabled for this cluster. 120 * @return true, if sequence detection is enabled, false otherwise. 121 */ 122 public boolean isSequenceDetectionEnabled(); 123 124 /** 125 * Indicates whether or not identity column detection is enabled for this cluster. 126 * @return true, if identity column detection is enabled, false otherwise. 127 */ 128 public boolean isIdentityColumnDetectionEnabled(); 129 130 /** 131 * Indicates whether or not non-deterministic CURRENT_DATE SQL functions will be evaluated to deterministic static values. 132 * @return true, if temporal SQL replacement is enabled, false otherwise. 133 */ 134 public boolean isCurrentDateEvaluationEnabled(); 135 136 /** 137 * Indicates whether or not non-deterministic CURRENT_TIME functions will be evaluated to deterministic static values. 138 * @return true, if temporal SQL replacement is enabled, false otherwise. 139 */ 140 public boolean isCurrentTimeEvaluationEnabled(); 141 142 /** 143 * Indicates whether or not non-deterministic CURRENT_TIMESTAMP functions will be evaluated to deterministic static values. 144 * @return true, if temporal SQL replacement is enabled, false otherwise. 145 */ 146 public boolean isCurrentTimestampEvaluationEnabled(); 147 148 /** 149 * Indicates whether or not non-deterministic RAND() functions will be replaced by evaluated to static values. 150 * @return true, if temporal SQL replacement is enabled, false otherwise. 151 */ 152 public boolean isRandEvaluationEnabled(); 153 154 /** 155 * Determines whether the specified databases are alive. 156 * @param databases a collection of database descriptors 157 * @return a map of alive status to set of database descriptors 158 */ 159 public Map<Boolean, List<Database<D>>> getAliveMap(Collection<Database<D>> databases); 160 161 /** 162 * Indicates whether or not this cluster is active, i.e. started, but not yet stopped. 163 * @return true, if this cluster is active, false otherwise. 164 */ 165 public boolean isActive(); 166}