openamf/src/java/org/openamf/recordset ASRecordSet.java,1.10,1.11

[email protected]
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/recordset
In directory sc8-pr-cvs1:/tmp/cvs-serv16187/src/java/org/openamf/recordset

Modified Files:
	ASRecordSet.java 
Log Message:
1) Initial PageableRecordSet support, still needs testing and cleanup
2) Added HttpServletRequest to ServiceInvoker constructor
3) Added PageableRecordSet config
4) Config is now a singleton and can be accessed from Config.getInstance()


Index: ASRecordSet.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/recordset/ASRecordSet.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ASRecordSet.java	28 May 2003 04:44:44 -0000	1.10
--- ASRecordSet.java	28 May 2003 15:53:29 -0000	1.11
***************
*** 12,15 ****
--- 12,16 ----
  import java.util.Iterator;
  import java.util.List;
+ import java.util.Map;
  
  import org.apache.commons.beanutils.PropertyUtils;
***************
*** 17,20 ****
--- 18,22 ----
  import org.apache.commons.logging.LogFactory;
  import org.openamf.ASObject;
+ import org.openamf.config.Config;
  
  public class ASRecordSet extends ASObject {
***************
*** 28,31 ****
--- 30,34 ----
  	private static final String SI_TOTAL_COUNT = "totalCount";
  	private static final String SI_INITIAL_DATA = "initialData";
+ 	private static final String SI_ROWS = "rows";
  	private static final String SI_CURSOR = "cursor";
  	private static final String SI_SERVICE_NAME = "serviceName";
***************
*** 34,37 ****
--- 37,42 ----
  
  	private HashMap serverInfo;
+ 	private List rows;
+ 	private int initialRowCount;
  
  	public ASRecordSet() {
***************
*** 43,46 ****
--- 48,57 ----
  		setCursor(1);
  		setVersion(1);
+ 		rows = new ArrayList();
+ 		initialRowCount =
+ 			Config
+ 				.getInstance()
+ 				.getPageableRecordsetConfig()
+ 				.getInitialDataRowCount();
  	}
  
***************
*** 71,74 ****
--- 82,97 ----
  	}
  
+ 	public Map getRecords(int from, int count) {
+ 		
+ 		List page = rows.subList(from, from + count);
+ 		
+ 		HashMap records = new HashMap();
+ 		records.put("page", page);
+ 		records.put("cursor", new Integer(from));
+ 		
+ 		return records;
+ 		
+ 	}
+ 
  	public int getCursor() {
  		Object value = serverInfo.get(SI_CURSOR);
***************
*** 117,121 ****
  
  			int rowIndex = 0;
! 			ArrayList rows = new ArrayList();
  			while (rs.next()) {
  				rowIndex++;
--- 140,144 ----
  
  			int rowIndex = 0;
! 			ArrayList initialData = new ArrayList();
  			while (rs.next()) {
  				rowIndex++;
***************
*** 131,137 ****
  				}
  				rows.add(row);
  			}
  			setTotalCount(rowIndex);
! 			setInitialData(rows);
  			setColumnNames(columnNames);
  		} catch (SQLException e) {
--- 154,163 ----
  				}
  				rows.add(row);
+ 				if (rowIndex <= initialRowCount) {
+ 					initialData.add(row);
+ 				}
  			}
  			setTotalCount(rowIndex);
! 			setInitialData(initialData);
  			setColumnNames(columnNames);
  		} catch (SQLException e) {
***************
*** 146,150 ****
  	 */
  	public void populate(String[] columnNames, List rows) {
! 		setInitialData(rows);
  		setTotalCount(rows.size());
  		setColumnNames(columnNames);
--- 172,184 ----
  	 */
  	public void populate(String[] columnNames, List rows) {
! 		this.rows = rows;
! 
! 		List initialData =
! 			rows.subList(
! 				0,
! 				(initialRowCount > rows.size()
! 					? rows.size() - 1
! 					: initialRowCount - 1));
! 		setInitialData(initialData);
  		setTotalCount(rows.size());
  		setColumnNames(columnNames);
***************
*** 162,170 ****
  
  		ArrayList names = new ArrayList();
- 
  		Object firstBean = list.get(0);
  		PropertyDescriptor[] properties =
  			PropertyUtils.getPropertyDescriptors(firstBean);
- 
  		for (int i = 0; i < properties.length; i++) {
  			PropertyDescriptor descriptor = properties[i];
--- 196,202 ----
***************
*** 177,183 ****
  		setColumnNames(columnNames);
  
! 		ArrayList rows = new ArrayList(list.size());
! 		for (Iterator iter = list.iterator(); iter.hasNext();) {
! 			Object bean = (Object) iter.next();
  			ArrayList row = new ArrayList();
  			for (int i = 0; i < properties.length; i++) {
--- 209,218 ----
  		setColumnNames(columnNames);
  
! 		int rowIndex = 0;
! 		ArrayList initialData = new ArrayList();
! 		Iterator iterator = list.iterator();
! 		while (iterator.hasNext()) {
! 			rowIndex++;
! 			Object bean = (Object) iterator.next();
  			ArrayList row = new ArrayList();
  			for (int i = 0; i < properties.length; i++) {
***************
*** 193,200 ****
  			}
  			rows.add(row);
  		}
! 		setInitialData(rows);
  		setTotalCount(rows.size());
- 		
  		log.debug(this);
  	}
--- 228,237 ----
  			}
  			rows.add(row);
+ 			if (rowIndex <= initialRowCount) {
+ 				initialData.add(row);
+ 			}
  		}
! 		setInitialData(initialData);
  		setTotalCount(rows.size());
  		log.debug(this);
  	}
***************
*** 205,209 ****
  
  		boolean ignore = false;
- 
  		if (descriptor.getName().equals("class")) {
  			ignore = true;
--- 242,245 ----
***************
*** 224,228 ****
  
  		StringBuffer info = new StringBuffer();
- 
  		addInfo(info, SI_ID, getId());
  		addInfo(info, SI_TOTAL_COUNT, getTotalCount());
--- 260,263 ----
***************
*** 230,234 ****
  		addInfo(info, SI_SERVICE_NAME, getServiceName());
  		addInfo(info, SI_VERSION, getVersion());
- 
  		StringBuffer names = new StringBuffer();
  		String[] columnNames = getColumnNames();
--- 265,268 ----
***************
*** 243,247 ****
  		addInfo(info, SI_COLUMN_NAMES, names);
  		addInfo(info, SI_INITIAL_DATA, getInitialData().toString());
- 
  		return info.toString();
  	}
--- 277,280 ----




-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.