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