Author: maksimkaszynski
Date: 2007-07-23 15:05:25 -0400 (Mon, 23 Jul 2007)
New Revision: 1811
Added:
trunk/sandbox/api/src/main/java/org/richfaces/model/SortField.java
Removed:
trunk/sandbox/api/src/main/java/org/richfaces/model/DataModelCache.java
Modified:
trunk/sandbox/api/src/main/java/org/richfaces/model/SortOrder.java
Log:
introduced framework/impl-parent and sandbox/impl modules
Deleted: trunk/sandbox/api/src/main/java/org/richfaces/model/DataModelCache.java
===================================================================
--- trunk/sandbox/api/src/main/java/org/richfaces/model/DataModelCache.java 2007-07-23
19:04:43 UTC (rev 1810)
+++ trunk/sandbox/api/src/main/java/org/richfaces/model/DataModelCache.java 2007-07-23
19:05:25 UTC (rev 1811)
@@ -1,186 +0,0 @@
-/**
- *
- */
-package org.richfaces.model;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-import javax.faces.model.DataModelListener;
-
-import org.ajax4jsf.model.DataVisitor;
-import org.ajax4jsf.model.Range;
-import org.ajax4jsf.model.SerializableDataModel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Implementation stores last loaded data, so no additional requests to db will be
performed
- * Acts as a proxy between the component and original data model
- * @author Maksim Kaszynski
- *
- */
-public class DataModelCache extends GridDataModel {
-
- private static Log log = LogFactory.getLog(DataModelCache.class);
-
- private static class DataRange {
- private int startRow;
- private int endRow;
- private SortOrder sortOrder;
- private List loadedData;
-
- public DataRange(int startRow, int endRow, SortOrder sortOrder,
- List loadedData) {
- super();
- this.startRow = startRow;
- this.endRow = endRow;
- this.sortOrder = sortOrder;
- this.loadedData = loadedData;
- }
-
- public boolean match(int s, int e, SortOrder sortOrder) {
- return s == startRow
- && e == endRow
- && sortOrdersMatch(sortOrder, this.sortOrder);
- }
-
- private boolean sortOrdersMatch(SortOrder sortOrder1, SortOrder sortOrder2) {
- boolean result = sortOrder1 == sortOrder2;
-
- if (sortOrder1 != null && sortOrder2 != null) {
- result = sortOrder1.equals(sortOrder2);
- }
-
- return result;
- }
-
- }
-
- private Map secondaryMapping = new HashMap();
-
- private DataRange dataRange;
-
- private GridDataModel gridDataModel;
-
- private int rowCount = Integer.MIN_VALUE;
-
- public DataModelCache(GridDataModel gridDataModel) {
- super();
- this.gridDataModel = gridDataModel;
-
- if (log.isTraceEnabled()) {
- log.trace("initializing with " + gridDataModel);
- }
- }
-
- public void addDataModelListener(DataModelListener listener) {
- gridDataModel.addDataModelListener(listener);
- }
-
- public DataModelListener[] getDataModelListeners() {
- return gridDataModel.getDataModelListeners();
- }
-
- public Object getObjectById(Object id) {
-
- if (log.isDebugEnabled()) {
- log.debug("Trying to get object by id" + id);
- }
- //First try to find data in inner cache
- //If not found - get it from original model
- Object cached = secondaryMapping.get(id);
-
- if (cached == null) {
-
- if (log.isDebugEnabled()) {
- log.debug("Cache miss " + id + " falling back to original
model");
- }
-
- cached = gridDataModel.getObjectById(id);
- secondaryMapping.put(id, cached);
-
- }
-
- if (log.isDebugEnabled()) {
- log.debug("At last found element " + cached);
- }
-
- return cached;
- }
-
- public int getRowCount() {
- if (rowCount == Integer.MIN_VALUE) {
- rowCount = gridDataModel.getRowCount();
- }
- return rowCount;
- }
-
- public Object getRowData() {
- Object secondaryMapped = secondaryMapping.get(getRowKey());
-
- if (secondaryMapped == null) {
- secondaryMapped = super.getRowData();
- }
- return secondaryMapped;
- }
-
- public int getRowIndex() {
- return gridDataModel.getRowIndex();
- }
-
- public Object getRowKey() {
- return gridDataModel.getRowKey();
- }
-
- public SerializableDataModel getSerializableModel(Range range) {
- return gridDataModel.getSerializableModel(range);
- }
-
- public Object getWrappedData() {
- return gridDataModel.getWrappedData();
- }
-
- public boolean isRowAvailable() {
- return secondaryMapping.containsKey(getRowKey()) || super.isRowAvailable();
- }
-
- public List loadData(int startRow, int endRow, SortOrder sortOrder) {
- if (dataRange == null || !dataRange.match(startRow, endRow, sortOrder)) {
- List data = gridDataModel.loadData(startRow, endRow, sortOrder);
- dataRange = new DataRange(startRow, endRow, sortOrder, data);
- }
- return dataRange.loadedData;
- }
-
- public void removeDataModelListener(DataModelListener listener) {
- gridDataModel.removeDataModelListener(listener);
- }
-
- public void setRowIndex(int arg0) {
- gridDataModel.setRowIndex(arg0);
- }
-
- public void setRowKey(Object key) {
- gridDataModel.setRowKey(key);
- super.setRowKey(key);
- }
-
- public void setWrappedData(Object arg0) {
- gridDataModel.setWrappedData(arg0);
- }
-
- public Object getId(Object o) {
- return gridDataModel.getId(o);
- }
-
- public void walk(FacesContext context, DataVisitor visitor, Range range,
- Object argument) throws IOException {
- // TODO Auto-generated method stub
- super.walk(context, visitor, range, argument);
- }
-
-}
Added: trunk/sandbox/api/src/main/java/org/richfaces/model/SortField.java
===================================================================
--- trunk/sandbox/api/src/main/java/org/richfaces/model/SortField.java
(rev 0)
+++ trunk/sandbox/api/src/main/java/org/richfaces/model/SortField.java 2007-07-23 19:05:25
UTC (rev 1811)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SortField implements Serializable{
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private String name = null;
+ private int index = -1;
+ private Boolean ascending = null;
+
+
+
+ public SortField(String name, int index, Boolean ascending) {
+ super();
+ this.name = name;
+ this.index = index;
+ this.ascending = ascending;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public Boolean getAscending() {
+ return ascending;
+ }
+
+ public void setAscending(Boolean ascending) {
+ this.ascending = ascending;
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((ascending == null) ? 0 : ascending.hashCode());
+ result = prime * result + index;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SortField other = (SortField) obj;
+ if (ascending == null) {
+ if (other.ascending != null)
+ return false;
+ } else if (!ascending.equals(other.ascending))
+ return false;
+ if (index != other.index)
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+
+
+}
Modified: trunk/sandbox/api/src/main/java/org/richfaces/model/SortOrder.java
===================================================================
--- trunk/sandbox/api/src/main/java/org/richfaces/model/SortOrder.java 2007-07-23 19:04:43
UTC (rev 1810)
+++ trunk/sandbox/api/src/main/java/org/richfaces/model/SortOrder.java 2007-07-23 19:05:25
UTC (rev 1811)
@@ -1,6 +1,7 @@
package org.richfaces.model;
import java.io.Serializable;
+import java.util.Arrays;
/**
*
* @author Maksim Kaszynski
@@ -9,66 +10,61 @@
*/
public class SortOrder implements Serializable {
+ private static int hashCode(Object[] array) {
+ final int prime = 31;
+ if (array == null)
+ return 0;
+ int result = 1;
+ for (int index = 0; index < array.length; index++) {
+ result = prime * result
+ + (array[index] == null ? 0 : array[index].hashCode());
+ }
+ return result;
+ }
+
private static final long serialVersionUID = 2423450561570551363L;
- private boolean ascending;
-
- private int sortColumn = -1;
+ private SortField [] fields;
+ public SortOrder() {
+
+ }
- public SortOrder( int sortColumn, boolean ascending) {
+ public SortOrder(SortField[] fields) {
super();
- this.sortColumn = sortColumn;
- this.ascending = ascending;
+ this.fields = fields;
}
- public SortOrder() {
- super();
- }
- public boolean isAscending() {
- return ascending;
- }
- public void setAscending(boolean ascending) {
- this.ascending = ascending;
+ public SortField[] getFields() {
+ return fields;
}
- public int getSortColumn() {
- return sortColumn;
+ public void setFields(SortField[] fields) {
+ this.fields = fields;
}
- public void setSortColumn(int sortColumn) {
- this.sortColumn = sortColumn;
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + SortOrder.hashCode(fields);
+ return result;
}
- /**
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return "SortOrder: {field:" + sortColumn + ", ascending: " +
ascending
- + "}";
- }
-
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
public boolean equals(Object obj) {
-
- if (obj instanceof SortOrder) {
- SortOrder sortOrder = (SortOrder) obj;
- return sortColumn == sortOrder.sortColumn
- && ascending == sortOrder.ascending;
-
- }
- return super.equals(obj);
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SortOrder other = (SortOrder) obj;
+ if (!Arrays.equals(fields, other.fields))
+ return false;
+ return true;
}
- public int hashCode() {
- int c = (new Integer(sortColumn)).hashCode();
- if (ascending) {
- c = -c;
- }
- return c;
- }
+
+
}
\ No newline at end of file
Show replies by date