Author: abelevich
Date: 2007-05-28 14:11:47 -0400 (Mon, 28 May 2007)
New Revision: 901
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/cashe/
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/cashe/DataGridCache.java
Log:
Added:
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/cashe/DataGridCache.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/cashe/DataGridCache.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/main/java/org/richfaces/model/cashe/DataGridCache.java 2007-05-28
18:11:47 UTC (rev 901)
@@ -0,0 +1,158 @@
+/*
+ * Copyright
+ * Copyright (c) Exadel,Inc. 2007
+ * All rights reserved.
+ *
+ * History
+ * $Source:
/cvs-master/intralinks-jsf-comps/components/data-view-grid/src/component/com/exadel/jsf/model/cache/DataGridCache.java,v
$
+ * $Revision: 1.2 $
+ */
+
+package org.richfaces.model.cashe;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModelListener;
+
+import org.ajax4jsf.ajax.repeat.DataVisitor;
+import org.ajax4jsf.ajax.repeat.Range;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.richfaces.model.DataRange;
+import org.richfaces.model.ScrollableGridDataModel2;
+import org.richfaces.model.SortOrder;
+import org.richfaces.model.snapshot.ObjectLocator;
+
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class DataGridCache extends ScrollableGridDataModel2 {
+
+ private final static Log log = LogFactory.getLog(DataGridCache.class);
+
+ private ScrollableGridDataModel2 dataModel;
+ private Map cache = new HashMap();
+
+ public DataGridCache(ScrollableGridDataModel2 model) {
+ dataModel = model;
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) throws IOException {
+ dataModel.walk(context, visitor, range, argument);
+ }
+
+ /**
+ * @see com.exadel.jsf.model.ScrollableGridDataModel2#createDataRange(int, int,
com.exadel.jsf.model.SortOrder)
+ */
+ protected DataRange createDataRange(int startRow, int endRow,
+ SortOrder sortOrder) {
+ return null;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ public int getRowCount() {
+ return dataModel.getRowCount();
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ public int getRowIndex() {
+ return dataModel.getRowIndex();
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#getWrappedData()
+ */
+ public Object getWrappedData() {
+ return dataModel;
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#isRowAvailable()
+ */
+ public boolean isRowAvailable() {
+ return dataModel.isRowAvailable();
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ public void setRowIndex(int rowIndex) {
+ dataModel.setRowIndex(rowIndex);
+ }
+
+ /**
+ * @see javax.faces.model.DataModel#setWrappedData(java.lang.Object)
+ */
+ public void setWrappedData(Object data) {
+ dataModel = (ScrollableGridDataModel2) data;
+ }
+
+ public ObjectLocator getObjectLocator() {
+ return dataModel.getObjectLocator();
+ }
+
+ public Object getRowData() {
+ Object rowKey = getRowKey();
+ Object data = null;
+ if (rowKey != null) {
+ data = cache.get(rowKey);
+ if (data == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("DataGridCache.getRowData() - cache miss: rowKey " + rowKey);
+ }
+ data = dataModel.getRowData();
+ cache.put(rowKey, data);
+ } else {
+ log.debug("DataGridCache.getRowData() - cache hit: rowKey " + rowKey);
+ }
+ } else {
+ log.debug("DataGridCache.getRowData() rowKey is null");
+ }
+ return data;
+ }
+
+ public Object getRowKey() {
+ return dataModel.getRowKey();
+ }
+
+// public Collection getSelectedObjects() {
+// return dataModel.getSelectedObjects();
+// }
+
+// public Selection getSelection() {
+// return dataModel.getSelection();
+// }
+
+ public void removeDataModelListener(DataModelListener listener) {
+ dataModel.removeDataModelListener(listener);
+ }
+
+ public void reset() {
+ dataModel.reset();
+ }
+
+ public void setObjectLocator(ObjectLocator objectLocator) {
+ dataModel.setObjectLocator(objectLocator);
+ }
+
+ public void setRowKey(Object key) {
+ dataModel.setRowKey(key);
+ }
+
+// public void setSelection(Selection selection) {
+// dataModel.setSelection(selection);
+// }
+
+
+}
Show replies by date