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