You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QueryDelegate.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.sqlcontainer.query;
  5. import java.io.Serializable;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.List;
  9. import com.vaadin.data.Container.Filter;
  10. import com.vaadin.data.util.sqlcontainer.RowId;
  11. import com.vaadin.data.util.sqlcontainer.RowItem;
  12. public interface QueryDelegate extends Serializable {
  13. /**
  14. * Generates and executes a query to determine the current row count from
  15. * the DB. Row count will be fetched using filters that are currently set to
  16. * the QueryDelegate.
  17. *
  18. * @return row count
  19. * @throws SQLException
  20. */
  21. public int getCount() throws SQLException;
  22. /**
  23. * Executes a paged SQL query and returns the ResultSet. The query is
  24. * defined through implementations of this QueryDelegate interface.
  25. *
  26. * @param offset
  27. * the first item of the page to load
  28. * @param pagelength
  29. * the length of the page to load
  30. * @return a ResultSet containing the rows of the page
  31. * @throws SQLException
  32. * if the database access fails.
  33. */
  34. public ResultSet getResults(int offset, int pagelength) throws SQLException;
  35. /**
  36. * Allows the SQLContainer implementation to check whether the QueryDelegate
  37. * implementation implements paging in the getResults method.
  38. *
  39. * @see QueryDelegate#getResults(int, int)
  40. *
  41. * @return true if the delegate implements paging
  42. */
  43. public boolean implementationRespectsPagingLimits();
  44. /**
  45. * Sets the filters to apply when performing the SQL query. These are
  46. * translated into a WHERE clause. Default filtering mode will be used.
  47. *
  48. * @param filters
  49. * The filters to apply.
  50. * @throws UnsupportedOperationException
  51. * if the implementation doesn't support filtering.
  52. */
  53. public void setFilters(List<Filter> filters)
  54. throws UnsupportedOperationException;
  55. /**
  56. * Sets the order in which to retrieve rows from the database. The result
  57. * can be ordered by zero or more columns and each column can be in
  58. * ascending or descending order. These are translated into an ORDER BY
  59. * clause in the SQL query.
  60. *
  61. * @param orderBys
  62. * A list of the OrderBy conditions.
  63. * @throws UnsupportedOperationException
  64. * if the implementation doesn't support ordering.
  65. */
  66. public void setOrderBy(List<OrderBy> orderBys)
  67. throws UnsupportedOperationException;
  68. /**
  69. * Stores a row in the database. The implementation of this interface
  70. * decides how to identify whether to store a new row or update an existing
  71. * one.
  72. *
  73. * @param columnToValueMap
  74. * A map containing the values for all columns to be stored or
  75. * updated.
  76. * @return the number of affected rows in the database table
  77. * @throws UnsupportedOperationException
  78. * if the implementation is read only.
  79. */
  80. public int storeRow(RowItem row) throws UnsupportedOperationException,
  81. SQLException;
  82. /**
  83. * Removes the given RowItem from the database.
  84. *
  85. * @param row
  86. * RowItem to be removed
  87. * @return true on success
  88. * @throws UnsupportedOperationException
  89. * @throws SQLException
  90. */
  91. public boolean removeRow(RowItem row) throws UnsupportedOperationException,
  92. SQLException;
  93. /**
  94. * Starts a new database transaction. Used when storing multiple changes.
  95. *
  96. * Note that if a transaction is already open, it will be rolled back when a
  97. * new transaction is started.
  98. *
  99. * @throws SQLException
  100. * if the database access fails.
  101. */
  102. public void beginTransaction() throws SQLException;
  103. /**
  104. * Commits a transaction. If a transaction is not open nothing should
  105. * happen.
  106. *
  107. * @throws SQLException
  108. * if the database access fails.
  109. */
  110. public void commit() throws SQLException;
  111. /**
  112. * Rolls a transaction back. If a transaction is not open nothing should
  113. * happen.
  114. *
  115. * @throws SQLException
  116. * if the database access fails.
  117. */
  118. public void rollback() throws SQLException;
  119. /**
  120. * Returns a list of primary key column names. The list is either fetched
  121. * from the database (TableQuery) or given as an argument depending on
  122. * implementation.
  123. *
  124. * @return
  125. */
  126. public List<String> getPrimaryKeyColumns();
  127. /**
  128. * Performs a query to find out whether the SQL table contains a row with
  129. * the given set of primary keys.
  130. *
  131. * @param keys
  132. * the primary keys
  133. * @return true if the SQL table contains a row with the provided keys
  134. * @throws SQLException
  135. */
  136. public boolean containsRowWithKey(Object... keys) throws SQLException;
  137. /************************/
  138. /** ROWID CHANGE EVENT **/
  139. /************************/
  140. /**
  141. * An <code>Event</code> object specifying the old and new RowId of an added
  142. * item after the addition has been successfully committed.
  143. */
  144. public interface RowIdChangeEvent extends Serializable {
  145. /**
  146. * Gets the old (temporary) RowId of the added row that raised this
  147. * event.
  148. *
  149. * @return old RowId
  150. */
  151. public RowId getOldRowId();
  152. /**
  153. * Gets the new, possibly database assigned RowId of the added row that
  154. * raised this event.
  155. *
  156. * @return new RowId
  157. */
  158. public RowId getNewRowId();
  159. }
  160. /** RowId change listener interface. */
  161. public interface RowIdChangeListener extends Serializable {
  162. /**
  163. * Lets the listener know that a RowId has been changed.
  164. *
  165. * @param event
  166. */
  167. public void rowIdChange(QueryDelegate.RowIdChangeEvent event);
  168. }
  169. /**
  170. * The interface for adding and removing <code>RowIdChangeEvent</code>
  171. * listeners. By implementing this interface a class explicitly announces
  172. * that it will generate a <code>RowIdChangeEvent</code> when it performs a
  173. * database commit that may change the RowId.
  174. */
  175. public interface RowIdChangeNotifier extends Serializable {
  176. /**
  177. * Adds a RowIdChangeListener for the object.
  178. *
  179. * @param listener
  180. * listener to be added
  181. */
  182. public void addListener(QueryDelegate.RowIdChangeListener listener);
  183. /**
  184. * Removes the specified RowIdChangeListener from the object.
  185. *
  186. * @param listener
  187. * listener to be removed
  188. */
  189. public void removeListener(QueryDelegate.RowIdChangeListener listener);
  190. }
  191. }