Permalink
Browse files

Update ronin and tosa docs

  • Loading branch information...
akeefer-guidewire committed Feb 10, 2012
1 parent fe32608 commit 4a7ffabfe400f5c932c6cf102d1900846b30e4a1
Showing with 25 additions and 12 deletions.
  1. +6 −6 ronin-docs/docs.html
  2. +7 −2 ronin-docs/tosa.html
  3. +12 −4 ronin-docs/tutorial.html
View
@@ -741,14 +741,14 @@ <h2>Tracing</h2>
[java] INFO Ronin - request for /PostCx/index - 1104.521 ms
[java] INFO Ronin - controller.PostCx.beforeRequest() - 0.214 ms
[java] INFO Ronin - controller.PostCx.index - 555.263 ms
- [java] INFO Ronin - db.roblog.BlogInfo.find() - 1.005 ms
- [java] INFO Ronin - select * from "BlogInfo" where true order by "id" ASC
+ [java] INFO Ronin - db.roblog.BlogInfo.selectAll() - 1.005 ms
+ [java] INFO Ronin - SELECT * FROM BlogInfo ([]) - 0.124 ms
[java] INFO Ronin - view.Layout.render() - 239.046 ms
- [java] INFO Ronin - db.roblog.BlogInfo.find() - 0.519 ms
- [java] INFO Ronin - select * from "BlogInfo" where true order by "id" ASC
+ [java] INFO Ronin - db.roblog.BlogInfo.selectAll() - 0.519 ms
+ [java] INFO Ronin - SELECT * FROM BlogInfo ([]) - 0.124 ms
[java] INFO Ronin - view.All.render() - 135.492 ms
- [java] INFO Ronin - db.roblog.Post.findSortedPaged() - 0.884 ms
- [java] INFO Ronin - select * from "Post" where true order by "Posted" DESC, "id" ASC limit 20 offset 0
+ [java] INFO Ronin - db.roblog.Post.selectAll() - 0.884 ms
+ [java] INFO Ronin - SELECT * FROM Post ORDER BY Posted DESC LIMIT ? OFFSET ? ([20, 0]) - 0.562 ms
[java] INFO Ronin - controller.PostCx.afterRequest() - 0.103 ms
</pre>
View
@@ -363,7 +363,7 @@ <h2>Paging Queries</h2>
}</pre>
<p>Paging a query also allows you to control where within the result set you start reading, by controlling
- either the startPage or startOffset. That can come in handy when you want to preset a list of data to
+ either the startPage or startOffset. That can come in handy when you want to present a list of data to
a user while letting them skip back and forth through the pages of result. For example, if you're
displaying a table 20 rows at a time and allowing a user to skip between pages of results, you could
use the following code to display the results starting at page 5 (note that :startPage is 0-indexed, so
@@ -373,7 +373,12 @@ <h2>Paging Queries</h2>
Person.selectAll().orderBy(Person#Name).page(:startPage = 4, :pageSize = 20)</pre>
<p>The resulting query will, when initially executed, load results 80-99 from the database. Note that the
- query, if you continue to iterate it, will still continue past result 99.</p>
+ query, if you continue to iterate it, will still continue past result 99. If you'd like to explicitly
+ load a single page of results, you can use the loadPage() method to explicitly load just a single page
+ of results in a <code>List</code>:</p>
+
+ <pre class="prettyprint linenums">
+ Person.selectAll().orderBy(Person#Name).page(:pageSize = 20).loadPage(4)</pre>
</section>
View
@@ -804,14 +804,22 @@ <h1>Querying The Database</h1>
<p>Add the following function to <code>PostRx</code>:</p>
<pre class="prettyprint linenums">
function all() {
- var posts = Post.findSorted(null, Post#Posted, false)
+ var posts = Post.selectAll().orderBy(Post#Posted, DESC).toList()
Layout.render(Writer, \ -> AllPosts.render(Writer, posts))
}
</pre>
<p>The first line of the function declares a local variable. As in our for loop, it is not necessary to specify the type of the variable - Gosu will infer the correct type from the value you assign to it. Instead, you use the var keyword to declare the variable.</p>
- <p>The findSorted method is one of several static methods present on all types generated by Tosa. It returns a sorted list of entities from the database. The first parameter allows you to filter the entities returned; here we want all posts, so we pass in null. The second parameter is the property by which we want to sort the entities. We specify the Post#Posted property, so the posts will be sorted chronologically. The third property is false for a descending sort order (true would make it ascending).</p>
+ <p>The selectAll() method is one of several static methods present on all types generated by Tosa.
+ It returns a QueryResult object that will return all Posts in the database (we could have used select(), selectWhere(),
+ or selectLike() if we wanted to add a WHERE clause to the query). We then applying an ordering to the query before
+ it's issued, using the orderBy() method, which takes two parameters: the first is the property we want to sort on,
+ while the second parameter is the sort direction. We specify the Post#Posted property, so the posts will be sorted chronologically,
+ and DESC as the sort direction so that more recent posts will appear first. The second parameter is optional and defaults to ASC. If we needed
+ a more complicated sort, we could have used orderBySql() instead, which takes a direct Sql statement to use as the
+ order by clause. Lastly, we materialize the results as a List to pass off to our template by using toList(). (We could
+ have also simply passed the QueryResult itself off to a template that was expecting to get an Iterable instead of a List.)</p>
<p>We then pass the list of posts to a new template, <code>AllPosts.gst.</code> Create this file and give it the following contents:</p>
@@ -850,8 +858,8 @@ <h1>Next Steps</h1>
<li>Implement a page which displays a snippet of each post, with a link to the full post and some text indicating
how many comments have been left on the post.
</li>
- <li>Using the findSortedPaged() method, display posts 20 at a time on the AllPosts page.</li>
- <li>Using the findWithSql() method, show "previous" and "next" links on the ViewPost page.</li>
+ <li>Using the page() and loadPage() methods on the QueryResult, display posts 20 at a time on the AllPosts page.</li>
+ <li>Using the selectWhere() method, show "previous" and "next" links on the ViewPost page.</li>
<li>Refactor the comments display to a separate controller method and view, and use blocks to include it in the
ViewPost page. Use AJAX to refresh just the comments display when the user leaves a comment.
</li>

0 comments on commit 4a7ffab

Please sign in to comment.