01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.db.orm.sqlgen;
04:
05: import java.util.Map;
06:
07: /**
08: * Generates insert query for one entity. Only non-null columns will be inserted (there is no need
09: * to insert <code>null</code> values since they will be automatically null or autogenerated by database).
10: */
11: public class DbSqlInsert implements DbSqlGenerator {
12:
13: protected DbDynamicSqlTemplate template;
14:
15: public DbSqlInsert(Object data) {
16: init(data);
17: }
18:
19: protected void init(Object data) {
20: template = new DbDynamicSqlTemplate(
21: "insert into $T{t -} ($C{t}) values ($V{t})").use("t",
22: data);
23: }
24:
25: // ---------------------------------------------------------------- interface
26:
27: public String generateQuery() {
28: return template.generateQuery();
29: }
30:
31: public Map<String, Object> getQueryParameters() {
32: return template.getQueryParameters();
33: }
34:
35: public Map<String, String[]> getColumnData() {
36: return template.getColumnData();
37: }
38:
39: public Map<String, Object> getQueryReferences() {
40: return template.getQueryReferences();
41: }
42: }
|