1 20 package net.mlw.vlh.adapter.jdbc.objectWrapper; 21 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import net.mlw.vlh.ValueListInfo; 28 import net.mlw.vlh.adapter.jdbc.AbstractJdbcAdapter; 29 import net.mlw.vlh.adapter.util.ObjectWrapper; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 34 49 public class DefaultWrapperAdapter extends AbstractJdbcAdapter 50 { 51 54 private static final Log LOGGER = LogFactory.getLog(DefaultWrapperAdapter.class); 55 56 private String _columnName = null; 57 58 private int _columnNumber = 1; 59 60 private ObjectWrapper _wrapper; 61 62 private boolean wrapResultSet = false; 63 64 69 private Object getOrignalRecord(ResultSet result) throws SQLException 70 { 71 if (wrapResultSet) 72 { 73 return result; 74 } 75 else 76 { 77 if (_columnName != null && _columnName.length() > 0) 78 { 79 return result.getObject(_columnName); 80 } 81 else 82 { 83 return result.getObject(_columnNumber); 84 } 85 } 86 } 87 88 public List processResultSet(String name, ResultSet result, int numberPerPage, ValueListInfo info) throws SQLException 89 { 90 if (LOGGER.isDebugEnabled()) 91 { 92 LOGGER.debug("Start wrapping using column '" 93 + (_columnName != null && _columnName.length() > 0 ? _columnName : (_columnNumber + "")) + "'."); 94 } 95 96 List list = new ArrayList (); 97 if (_wrapper == null) 98 { 99 LOGGER.error("Required _wrapper is null!"); 100 } 101 else 102 { 103 _wrapper.setValueListInfo(info); 104 for (int i = 0; result.next() && i < numberPerPage; i++) 105 { 106 list.add(_wrapper.getWrappedRecord(getOrignalRecord(result))); 107 } 108 } 109 110 LOGGER.debug("End wrapping."); 111 return list; 112 } 113 114 117 public String getColumnName() 118 { 119 return _columnName; 120 } 121 122 132 public void setColumnName(String columnName) 133 { 134 _columnName = columnName; 135 } 136 137 140 public int getColumnNumber() 141 { 142 return _columnNumber; 143 } 144 145 154 public void setColumnNumber(int columnNumber) 155 { 156 _columnNumber = columnNumber; 157 } 158 159 162 public ObjectWrapper getWrapper() 163 { 164 return _wrapper; 165 } 166 167 173 public void setWrapper(ObjectWrapper objectWrapper) 174 { 175 this._wrapper = objectWrapper; 176 } 177 178 181 public boolean isWrapResultSet() 182 { 183 return wrapResultSet; 184 } 185 186 196 public void setWrapResultSet(boolean wrapResultSet) 197 { 198 this.wrapResultSet = wrapResultSet; 199 } 200 } | Popular Tags |