1 /** 2 This file is part of GoldenGate Project (named also GoldenGate or GG). 3 4 Copyright 2009, Frederic Bregier, and individual contributors by the @author 5 tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 individual contributors. 7 8 All GoldenGate Project is free software: you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as published 10 by the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 GoldenGate is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package goldengate.common.database.model; 22 23 import java.sql.Connection; 24 import java.sql.SQLException; 25 26 import goldengate.common.database.DbSession; 27 import goldengate.common.database.exception.GoldenGateDatabaseNoConnectionException; 28 import goldengate.common.database.exception.GoldenGateDatabaseNoDataException; 29 import goldengate.common.database.exception.GoldenGateDatabaseSqlException; 30 31 /** 32 * Interface for Database Model 33 * 34 * This class is an interface for special functions that needs special implementations according to 35 * the database model used. 36 * 37 * @author Frederic Bregier 38 * 39 */ 40 public interface DbModel { 41 /** 42 * 43 * @param server 44 * @param user 45 * @param passwd 46 * @return a connection according to the underlying Database Model 47 * @throws SQLException 48 */ 49 public Connection getDbConnection(String server, String user, String passwd) throws SQLException; 50 51 /** 52 * Release any internal resources if needed 53 */ 54 public void releaseResources(); 55 56 /** 57 * 58 * @return the number of Pooled Connections if any 59 */ 60 public int currentNumberOfPooledConnections(); 61 /** 62 * 63 * @return the current DbType used 64 */ 65 public DbType getDbType(); 66 /** 67 * Create all necessary tables into the database 68 * @param session SQL session 69 * @throws GoldenGateDatabaseNoConnectionException 70 */ 71 public void createTables(DbSession session) throws GoldenGateDatabaseNoConnectionException; 72 73 /** 74 * Reset the sequence (example) 75 * @param session SQL session 76 * @throws GoldenGateDatabaseNoConnectionException 77 */ 78 public void resetSequence(DbSession session, long newvalue) throws GoldenGateDatabaseNoConnectionException; 79 80 /** 81 * @param dbSession 82 * @return The next unique specialId 83 */ 84 public long nextSequence(DbSession dbSession) 85 throws GoldenGateDatabaseNoConnectionException, GoldenGateDatabaseSqlException, 86 GoldenGateDatabaseNoDataException; 87 88 /** 89 * Validate connection 90 * @param dbSession 91 * @throws GoldenGateDatabaseNoConnectionException 92 */ 93 public void validConnection(DbSession dbSession) throws GoldenGateDatabaseNoConnectionException; 94 95 /** 96 * Add a limit on the request to get the "limit" first rows. Note that 97 * it must be compatible to add the "limit" condition.<br> 98 * <b>DO NOT CHANGE (add) ANYTHING to the request</b><br> 99 * 100 * On Oracle: select allfield from (request) where rownnum <= limit<br> 101 * On others: request LIMIT limit<br> 102 * 103 * @param allfields string representing the equivalent to "*" in "select *" but more precisely 104 * as "field1, field2" in "select field1, field2" 105 * @param request 106 * @param limit 107 * @return the new request String which will limit the result to the specified number of rows 108 */ 109 public String limitRequest(String allfields, String request, int limit); 110 }