1 23 package org.dbforms.event.datalist.dao; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.dbforms.config.DbEventInterceptorData; 28 import org.dbforms.config.FieldValue; 29 import org.dbforms.config.FieldValues; 30 import org.dbforms.config.ResultSetVector; 31 import org.dbforms.config.Table; 32 33 import org.dbforms.util.ReflectionUtil; 34 import org.dbforms.util.Util; 35 36 import java.sql.Connection ; 37 import java.sql.SQLException ; 38 39 40 41 47 public class DataSourceFactory { 48 private static Log logCat = LogFactory.getLog(DataSourceFactory.class 50 .getName()); 51 private DataSource dataHandler; 52 53 64 public DataSourceFactory(String dbConnectionName, Connection connection, 65 Table table) throws SQLException { 66 String dataAccessClass = table.getDataAccessClass(); 67 68 if (Util.isNull(dataAccessClass)) { 69 dataAccessClass = "org.dbforms.event.datalist.dao.DataSourceJDBC"; 70 } 71 72 try { 73 dataHandler = (DataSource) ReflectionUtil.newInstance(dataAccessClass); 74 dataHandler.setTable(table); 75 dataHandler.setConnection(connection, dbConnectionName); 76 } catch (Exception e) { 77 logCat.error(e); 78 } 79 } 80 81 93 public ResultSetVector getCurrent(DbEventInterceptorData interceptorData, 94 String position, int count) throws SQLException { 95 return dataHandler.getCurrent(interceptorData, position, count); 96 } 97 98 99 104 public DataSource getDataHandler() { 105 return dataHandler; 106 } 107 108 109 120 public ResultSetVector getFirst(DbEventInterceptorData interceptorData, 121 int count) throws SQLException { 122 return dataHandler.getFirst(interceptorData, count); 123 } 124 125 126 135 public ResultSetVector getLast(DbEventInterceptorData interceptorData, 136 int count) throws SQLException { 137 return dataHandler.getLast(interceptorData, count); 138 } 139 140 141 153 public ResultSetVector getNext(DbEventInterceptorData interceptorData, 154 String position, int count) throws SQLException { 155 return dataHandler.getNext(interceptorData, position, count); 156 } 157 158 159 171 public ResultSetVector getPrev(DbEventInterceptorData interceptorData, 172 String position, int count) throws SQLException { 173 return dataHandler.getPrev(interceptorData, position, count); 174 } 175 176 177 187 public void setSelect(FieldValue[] filterConstraint, 188 FieldValue[] orderConstraint, String sqlFilter, 189 FieldValue[] sqlFilterParams) { 190 dataHandler.setSelect(filterConstraint, orderConstraint, sqlFilter, 191 sqlFilterParams); 192 } 193 194 195 204 public void setSelect(String tableList, String whereClause) 205 throws SQLException { 206 dataHandler.setSelect(tableList, whereClause); 207 } 208 209 210 213 public void close() { 214 dataHandler.close(); 215 } 216 217 218 226 public void doDelete(DbEventInterceptorData interceptorData, 227 String keyValuesStr) throws SQLException { 228 dataHandler.doDelete(interceptorData, keyValuesStr); 229 } 230 231 232 240 public void doInsert(DbEventInterceptorData interceptorData, 241 FieldValues fieldValues) throws SQLException { 242 dataHandler.doInsert(interceptorData, fieldValues); 243 } 244 245 246 255 public void doUpdate(DbEventInterceptorData interceptorData, 256 FieldValues fieldValues, String keyValuesStr) throws SQLException { 257 dataHandler.doUpdate(interceptorData, fieldValues, keyValuesStr); 258 } 259 } 260 | Popular Tags |