Java Code Examples for com.j256.ormlite.stmt.Where#queryForFirst()

The following examples show how to use com.j256.ormlite.stmt.Where#queryForFirst() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mOrgAnd   File: OrgNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return line number of next node on same or higher level than current node.
 */
public int getSiblingLineNumber() {
    try {
        Where<OrgNode, Integer> where = OrgNodeRepository.queryBuilder().orderBy(LINENUMBER_FIELD_NAME, true).where();
        where.eq(FILE_FIELD_NAME, file).and().gt(LINENUMBER_FIELD_NAME, lineNumber).and().le(LEVEL_FIELD_NAME, level);
        OrgNode node = where.queryForFirst();
        if (node != null) {
            if (node.type != Type.File)
                return node.lineNumber;
        }
        else
            return Integer.MAX_VALUE; // Current node seems to be last in file
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return -1;
}
 
Example 2
Source Project: mOrgAnd   File: OrgNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
public int getNextNodeLineNumber() {
    try {
        Where<OrgNode, Integer> where = OrgNodeRepository.queryBuilder().orderBy(LINENUMBER_FIELD_NAME, true).where();
        where.eq(FILE_FIELD_NAME, file).and().gt(LINENUMBER_FIELD_NAME, lineNumber);
        OrgNode node = where.queryForFirst();
        if (node != null)
            return node.lineNumber;
        else
            return Integer.MAX_VALUE; // Current node seems to be last in file
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return -1;
}