API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.persistance.builders. JOTQueryBuilderHelper View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.jot.persistance.builders;

import net.jot.persistance.JOTSQLCondition;

/**
 * Common static methods shared by all query builders
 * @author tcolar
 */
public final class JOTQueryBuilderHelper {
    private JOTQueryBuilderHelper(){}
    
            /**
     * Note: It is much safer to use where(JOTSQLCondition) ..,
     * If several where, we will be using AND
     * @param where
     */
    public static JOTQueryBase where(JOTQueryBase builder,String where)
    {
        appendToSQL(builder,(builder.nbWhere == 0 ? "WHERE " : "AND ") + where);
        builder.nbWhere++;
        return builder;
    }

    /**
     * Note: It is much safer to use orWere(JOTSQLCondition) ..,
     * If you want to do a OR where instead of and.
     * @param where
     */
    public static JOTQueryBase orWhere(JOTQueryBase builder, String where)
    {
        appendToSQL(builder,(builder.nbWhere == 0 ? "WHERE " : "OR ") + where);
        builder.nbWhere++;
        return builder;
    }
    /**
     * Provide PreparedStement params (optional)
     * @param params
     */
    public static JOTQueryBase withParams(JOTQueryBase builder, String[] pms)
    {
        for (int i = 0; i != pms.length; i++)
        {
            builder.params.add(pms[i]);
        }
        return builder;
    }
    
    
    /**
     * If several where, we will be using AND
     * @param where
     */
    public static JOTQueryBase where(JOTQueryBase builder, JOTSQLCondition cond)
    {
        builder.params.add(cond.getValue());
        return where(builder,cond.getSqlString());
    }

    /**
     * If you want to do a OR where instead of and.
     * @param where
     */
    public static JOTQueryBase orWhere(JOTQueryBase builder, JOTSQLCondition cond)
    {
        builder.params.add(cond.getValue());
        return orWhere(builder,cond.getSqlString());
    }
    
    /**
     * Ascending orderBy
     * should only be called once
     * @param orderBy EX: "date"    "date,price" etc...
     */
    public static JOTQueryBase orderBy(JOTQueryBase builder, String orderBy)
    {
        builder=orderBy(builder, orderBy, true);
        return builder;
    }

    /**
     * Add a orderBy to the query
     * should only be called once
     * @param orderBy EX: "date"    "date,price" etc...
     * @param ascending
     */
    public static JOTQueryBase orderBy(JOTQueryBase builder, String orderBy, boolean ascending)
    {
        appendToSQL(builder,"ORDER BY " + orderBy + (ascending ? "" : " DESC"));
        return builder;
    }

        /**
     * Manually append whatever you like to the query.
     * @param where
     * @return
     */
    public static JOTQueryBase appendToSQL(JOTQueryBase builder,String append)
    {
        builder.sql.append(append).append(" ");
        return builder;
    }


}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar