JPA 2 CriteriaQuery, using a limit

Define limit and offset on the Query: return em.createQuery(query) .setFirstResult(offset) // offset .setMaxResults(limit) // limit .getResultList(); From the documentation: TypedQuery setFirstResult(int startPosition) Set the position of the first result to retrieve. Parameters: startPosition – position of the first result, numbered from 0 TypedQuery setMaxResults(int maxResult) Set the maximum number of results to retrieve.

Equivalent of LIMIT for DB2

Using FETCH FIRST [n] ROWS ONLY: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.perf/db2z_fetchfirstnrows.htm SELECT LASTNAME, FIRSTNAME, EMPNO, SALARY FROM EMP ORDER BY SALARY DESC FETCH FIRST 20 ROWS ONLY; To get ranges, you’d have to use ROW_NUMBER() (since v5r4) and use that within the WHERE clause: (stolen from here: http://www.justskins.com/forums/db2-select-how-to-123209.html) SELECT code, name, address FROM ( SELECT row_number() OVER ( ORDER … Read more

Limiting Python input strings to certain characters and lengths

Question 1: Restrict to certain characters You are right, this is easy to solve with regular expressions: import re input_str = raw_input(“Please provide some info: “) if not re.match(“^[a-z]*$”, input_str): print “Error! Only letters a-z allowed!” sys.exit() Question 2: Restrict to certain length As Tim mentioned correctly, you can do this by adapting the regular … Read more

HTML5 localStorage size limit for subdomains

From http://dev.w3.org/html5/webstorage/#disk-space A mostly arbitrary limit of five megabytes per origin is recommended. Implementation feedback is welcome and will be used to update this suggestion in the future. It also mentions that : User agents should guard against sites storing data under the origins other affiliated sites, e.g. storing up to the limit in a1.example.com, … Read more