API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.persistance.builders. JOTInsertQuery 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

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

package net.jot.persistance.builders;

import net.jot.persistance.JOTSQLCondition;
import net.jot.persistance.JOTTransaction;
import net.jot.persistance.query.JOTQueryManager;

/**
 * Query builder for insert type queries
 * Use through JOQueryBuilder
 * @author tcolar
 */
public class JOTInsertQuery extends JOTQueryBase
{
	private final JOTTransaction transaction;
    protected JOTInsertQuery(JOTTransaction transaction){this.transaction=transaction;}
    
    /**
     * Runs the insert
     * @param transaction
     * @param fields
     * @param values
     * @throws java.lang.Exception
     */
    public void insert(String[] fields, String[] values) throws Exception
    {
        appendToSQL("(");
        for (int i = 0; i != fields.length; i++)
        {
            if (i > 0)
            {
                appendToSQL(",");
            }
            appendToSQL(fields[i]);
        }
        appendToSQL(") VALUES (");
        for (int i = 0; i != fields.length; i++)
        {
            if (i > 0)
            {
                appendToSQL(",");
            }
            appendToSQL("?");
            params.add(fields[i]);
        }
        appendToSQL(")");
        JOTQueryManager.updateSQL(transaction, modelClass, sql.toString(), values, flags);
    }

    public JOTInsertQuery orWhere(JOTSQLCondition cond)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.orWhere(this,cond);
    }

    public JOTInsertQuery where(JOTSQLCondition cond)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.where(this,cond);
    }

    /**
     * It's much safer to use where(JOTSQLCondition cond)
     * @param where
     * @return
     */
    public JOTInsertQuery where(String where)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.where(this,where);
    }

   /**
     * Pass the (prepared statement )parameters (ie: values)
     * @param pms
     * @return
     */
     public JOTInsertQuery withParams(String[] pms)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.withParams(this,pms);
    }

    public JOTInsertQuery orWhere(String where)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.orWhere(this,where);
    }
    /**
     * append generic SQL to the query, use with precautions !
     * @param append
     * @return
     */
    public JOTInsertQuery appendToSQL(String append)
    {
        return (JOTInsertQuery)JOTQueryBuilderHelper.appendToSQL(this, append);
    }
}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar