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 finding queries from provided data entity object.
09: * By default, column aliases are generated if {@link DbSqlTemplate} generates them.
10: * Generated select query contains list of all entity columns.
11: */
12: public class DbSqlFind implements DbSqlGenerator {
13:
14: protected DbDynamicSqlTemplate template;
15:
16: public DbSqlFind(Object finder) {
17: init(null, finder, null);
18: }
19:
20: public DbSqlFind(String prefix, Object finder) {
21: init(prefix, finder, null);
22: }
23:
24: public DbSqlFind(Object finder, boolean columnAlias) {
25: init(null, finder, Boolean.valueOf(columnAlias));
26: }
27:
28: public DbSqlFind(String prefix, Object finder, boolean columnAlias) {
29: init(prefix, finder, Boolean.valueOf(columnAlias));
30: }
31:
32: protected void init(String prefix, Object finder,
33: Boolean columnAlias) {
34: if (prefix == null) {
35: prefix = "select $C{+t.*}";
36: }
37: template = new DbDynamicSqlTemplate(prefix
38: + " from $T{t} $W{where !t}").use("t", finder);
39: if (columnAlias != null) {
40: template.columnAliases(columnAlias.booleanValue());
41: }
42: }
43:
44: // ---------------------------------------------------------------- delegate
45:
46: /**
47: * @see jodd.db.orm.sqlgen.DbSqlTemplate#columnAliases(boolean)
48: */
49: public DbSqlFind columnAliases(boolean aliases) {
50: template.columnAliases(aliases);
51: return this ;
52: }
53:
54: public DbSqlFind setColumnAliasesType(
55: DbSqlTemplate.ColumnAliasType aliasesType) {
56: template.setColumnAliasesType(aliasesType);
57: return this ;
58: }
59:
60: // ---------------------------------------------------------------- interface
61:
62: public String generateQuery() {
63: return template.generateQuery();
64: }
65:
66: public Map<String, Object> getQueryParameters() {
67: return template.getQueryParameters();
68: }
69:
70: public Map<String, String[]> getColumnData() {
71: return template.getColumnData();
72: }
73:
74: public Map<String, Object> getQueryReferences() {
75: return template.getQueryReferences();
76: }
77: }
|