From: Jani Laakso Date: Thu, 15 Mar 2007 23:53:51 +0000 (+0000) Subject: Merged Atique's changesets back to Trunk. X-Git-Tag: 6.7.0.beta1~6504 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6cdef7b866a0dbe20d3fd6f269ef61e43d907527;p=vaadin-framework.git Merged Atique's changesets back to Trunk. svn changeset:961/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/data/util/QueryContainer.java b/src/com/itmill/toolkit/data/util/QueryContainer.java index 1a75e8d9c9..33febfe58c 100644 --- a/src/com/itmill/toolkit/data/util/QueryContainer.java +++ b/src/com/itmill/toolkit/data/util/QueryContainer.java @@ -37,21 +37,39 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; - import com.itmill.toolkit.data.Container; import com.itmill.toolkit.data.Item; import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.util.ObjectProperty; /** - * SQL query container. Implementation of container interface for SQL tables - * accessed through JDBC connection. + *

+ * The QueryContainer is the specialized form of + * Container which is Ordered and Indexed. This is used to represent the + * contents of relational database tables accessed through the JDBC Connection + * in the Toolkit Table. This creates Items based on the queryStatement provided + * to the container. + *

+ * + *

+ * The QueryContainer can be visualized as a representation of a + * relational database table.Each Item in the container represents the + * row fetched by the query.All cells in a column have same data type and the + * data type information is retrieved from the metadata of the resultset. + *

+ * + *

+ * Note : If data in the tables gets modified, Container will not get reflected + * with the updates, we have to explicity invoke QueryContainer.refresh method. + * {@link com.itmill.toolkit.data.util.QueryContainer#refresh() refresh()} + *

+ * @see com.itmill.toolkit.data.Container * * @author IT Mill Ltd. * @version - * @VERSION@ * @since 4.0 */ + public class QueryContainer implements Container, Container.Ordered, Container.Indexed { @@ -80,13 +98,17 @@ public class QueryContainer implements Container, Container.Ordered, Statement statement; /** - * Create new QueryContainer with specific ResultSet type and concurrency. + * Constructs a new QueryContainer with the specified + * queryStatement * * @param queryStatement + * Database query * @param connection + * Connection object * @param resultSetType * @param resultSetConcurrency * @throws SQLException + * when database operation fails */ public QueryContainer(String queryStatement, Connection connection, int resultSetType, int resultSetConcurrency) throws SQLException { @@ -98,18 +120,30 @@ public class QueryContainer implements Container, Container.Ordered, } /** - * Create new QueryContainer. + * Constructs a new QueryContainer with the specified + * queryStatement using the default resultset type and default resultset concurrency * * @param queryStatement + * Database query * @param connection + * Connection object + * @see QueryContainer#DEFAULT_RESULTSET_TYPE + * @see QueryContainer#DEFAULT_RESULTSET_CONCURRENCY * @throws SQLException + * when database operation fails */ public QueryContainer(String queryStatement, Connection connection) throws SQLException { this(queryStatement, connection, DEFAULT_RESULTSET_TYPE, DEFAULT_RESULTSET_CONCURRENCY); } - + + /** + *

+ * The init method s invoked by the constructor. This + * method fills the container with the items and properties + *

+ */ private void init() throws SQLException { refresh(); ResultSetMetaData metadata; @@ -127,10 +161,16 @@ public class QueryContainer implements Container, Container.Ordered, } /** - * Refresh QueryContainer items from the database. - * + *

+ * The refresh method refreshes the items in the container. + * This method will update the latest data to the container. + *

+ * Note : This method should be used to update the container with the latest items. * @throws SQLException + * when database operation fails + * */ + public void refresh() throws SQLException { close(); statement = connection.createStatement(resultSetType, @@ -141,10 +181,13 @@ public class QueryContainer implements Container, Container.Ordered, } /** - * Close QueryContainer. Closes SQL statement if open. + * The close method closes the statement and nullify the + * statement. * * @throws SQLException + * when database operation fails */ + public void close() throws SQLException { if (statement != null) statement.close(); @@ -152,19 +195,38 @@ public class QueryContainer implements Container, Container.Ordered, } /** - * Get Item from QueryContainer with given id. + * The getItem method gets the Item with the given Item ID + * from the Container. * - * @param Object - * id + * @param id + * ID of the Item to retrieve + * @return Item Id. */ + public Item getItem(Object id) { return new Row(id); } + /** + *

+ * The getContainerPropertyIds method gets the collection of + * propertyId from the Container. + *

+ * + * @return Collection of Property ID. + */ + public Collection getContainerPropertyIds() { return propertyIds; } + /** + *

+ * The getItemIds method gets the collection of all the item id in the container. + *

+ * + * @return collection of Item IDs + */ public Collection getItemIds() { Collection c = new ArrayList(size); for (int i = 1; i <= size; i++) @@ -172,6 +234,21 @@ public class QueryContainer implements Container, Container.Ordered, return c; } + /** + *

+ * The getContainerProperty method gets the property + * identified by the given itemId and propertyId from the container.If the + * container does not contain the property null is returned. + *

+ * + * @param itemId + * ID of the Item which contains the Property + * @param propertyId + * ID of the Property to retrieve + * + * @return Property with the given ID or null + */ + public synchronized Property getContainerProperty(Object itemId, Object propertyId) { if (!(itemId instanceof Integer && propertyId instanceof String)) @@ -188,14 +265,41 @@ public class QueryContainer implements Container, Container.Ordered, return new ObjectProperty(value != null ? value : new String("")); } + /** + *

+ * The getType gets the data type of all properties + * identified by the given type ID. + *

+ * + * @param id + * ID identifying the Properties + * + * @return data type of the Properties + */ + public Class getType(Object id) { return (Class) propertyTypes.get(id); } + /** + * The size method gets the number of items in the container. + * + * @return the number of items in the container. + */ + public int size() { return size; } + /** + *

+ * The containsId method returns true if given + * id is there in container else false. + *

+ * + * @param id + * ID the of Item to be tested. + */ public boolean containsId(Object id) { if (!(id instanceof Integer)) return false; @@ -207,64 +311,174 @@ public class QueryContainer implements Container, Container.Ordered, return true; } + /** + * The addItem method creates a new Item with the given ID + * into the Container. + * + * @param arg0 + * ID of the Item to be created. + * + * @throws UnsupportedOperationException + * if the addItem method is not supported. + */ public Item addItem(Object arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addItem method creates a new Item into the Container, + * and assign it an ID. + * + * @throws UnsupportedOperationException + * if the addItem method is not supported. + */ public Object addItem() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addItem method removes the Item identified by ItemId + * from the Container. + * + * @throws UnsupportedOperationException + * if the removeItem method is not supported. + */ public boolean removeItem(Object arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addContainerProperty method adds a new Property to all + * Items in the Container. + * + * @param arg0 + * ID of the Property + * @param arg1 + * Data type of the new Property + * @param arg2 + * The value all created Properties are initialized to + * + * @throws UnsupportedOperationException + * if the addContainerProperty method is not supported. + */ public boolean addContainerProperty(Object arg0, Class arg1, Object arg2) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The removeContainerProperty method removes a Property + * specified by the given Property ID from the Container. + * + * @param arg0 + * ID of the Property to remove + * + * @throws UnsupportedOperationException + * if the removeContainerProperty method is not supported. + */ public boolean removeContainerProperty(Object arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The removeAllItems method removes all Items from the + * Container + * + * @throws UnsupportedOperationException + * if the removeAllItems method is not supported. + */ public boolean removeAllItems() throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addItemAfter method add new item after the given item. + * + * @param arg0 + * Id of the previous item in ordered container. + * @param arg1 + * Id of the new item to be added. + * @throws UnsupportedOperationException + * if the addItemAfter method is not supported. + */ public Item addItemAfter(Object arg0, Object arg1) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addItemAfter method add new item after the given item. + * + * @param arg0 + * Id of the previous item in ordered container. + */ public Object addItemAfter(Object arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + *

+ * The firstItemId method returns id of first item in the + * Container. + *

+ */ public Object firstItemId() { if (size < 1) return null; return new Integer(1); } + /** + *

+ * The isFirstId method return true if given + * id is first id at first index. + *

+ * + * @param id + * ID of an Item in the Container. + */ public boolean isFirstId(Object id) { return size > 0 && (id instanceof Integer) && ((Integer) id).intValue() == 1; } + /** + *

+ * The isLastId method return true if given id + * is last id at last index + *

+ * + * @param id + * ID of an Item in the Container + */ public boolean isLastId(Object id) { return size > 0 && (id instanceof Integer) && ((Integer) id).intValue() == size; } + /** + *

+ * The lastItemId method returns id of last item in the + * Container. + *

+ */ public Object lastItemId() { if (size < 1) return null; return new Integer(size); } + /** + *

+ * The nextItemId method return id of next item in container + * at next index. + *

+ * + * @param id + * ID of an Item in the Container. + */ public Object nextItemId(Object id) { if (size < 1 || !(id instanceof Integer)) return null; @@ -274,6 +488,15 @@ public class QueryContainer implements Container, Container.Ordered, return new Integer(i + 1); } + /** + *

+ * The prevItemId method return id of previous item in + * container at previous index. + *

+ * + * @param id + * ID of an Item in the Container. + */ public Object prevItemId(Object id) { if (size < 1 || !(id instanceof Integer)) return null; @@ -283,6 +506,11 @@ public class QueryContainer implements Container, Container.Ordered, return new Integer(i - 1); } + /** + *

+ * The Row class implements methods of Item. + *

+ */ /** Query result row */ class Row implements Item { @@ -292,19 +520,61 @@ public class QueryContainer implements Container, Container.Ordered, id = rowId; } + /** + *

+ * The addItemProperty method adds the item property. + *

+ * + * @param arg0 + * ID of the new Property. + * @param arg1 + * Property to be added and associated with ID. + * @throws UnsupportedOperationException + * if the addItemProperty method is not supported. + */ public boolean addItemProperty(Object arg0, Property arg1) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + *

+ * The getItemProperty gets the property corresponding to + * the given property ID stored in the Item. If the Item does not + * contain the Property, null is returned. + *

+ * + * @param id + * identifier of the Property to get + * @return the Property with the given ID or null + */ public Property getItemProperty(Object propertyId) { return getContainerProperty(id, propertyId); } + /** + *

+ * The getItemPropertyIds method gets the collection of + * property IDs stored in the Item. + *

+ * + * @return unmodifiable collection containing IDs of the Properties + * stored the Item. + */ public Collection getItemPropertyIds() { return propertyIds; } + /** + *

+ * The removeItemProperty method removes given item + * property return true if the item property is removed + * false if not. + *

+ * + * @throws UnsupportedOperationException + * if the removeItemProperty is not supported. + */ public boolean removeItemProperty(Object arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); @@ -312,6 +582,11 @@ public class QueryContainer implements Container, Container.Ordered, } + /** + * The finalize method closes the statement. + * + * @see #close() + */ public void finalize() { try { close(); @@ -320,21 +595,60 @@ public class QueryContainer implements Container, Container.Ordered, } } + /** + * The addItemAt method adds the given item at the position + * of given index. + * + * @param arg0 + * Index to add the new item. + * @param arg1 + * Id of the new item to be added. + * + * @throws UnsupportedOperationException + */ public Item addItemAt(int arg0, Object arg1) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The addItemAt method adds the item at the position of + * provided index in the container. + * + * @param arg0 + * Index to add the new item. + * + * @throws UnsupportedOperationException + * if the addItemAt is not supported. + */ + public Object addItemAt(int arg0) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } + /** + * The getIdByIndex method gets the Index id in the + * container. + * + * @param index + * Index Id. + */ public Object getIdByIndex(int index) { if (size < 1 || index < 0 || index >= size) return null; return new Integer(index + 1); } + /** + * The indexOfId gets the index of the Item corresponding to + * id in the container. + * + * @param id + * ID of an Item in the Container + * @return index of the Item, or -1 if the Container does not include the + * Item + */ + public int indexOfId(Object id) { if (size < 1 || !(id instanceof Integer)) return -1;