01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: * Free Software Foundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Rodrigo Westrupp
27: */
28:
29: package com.caucho.amber.expr;
30:
31: import com.caucho.amber.entity.Embeddable;
32: import com.caucho.amber.field.AmberField;
33: import com.caucho.amber.manager.AmberConnection;
34: import com.caucho.amber.query.FromItem;
35: import com.caucho.amber.query.QueryParser;
36: import com.caucho.amber.table.LinkColumns;
37: import com.caucho.amber.table.Table;
38: import com.caucho.amber.type.EmbeddableType;
39: import com.caucho.amber.type.Type;
40: import com.caucho.util.CharBuffer;
41:
42: import java.lang.reflect.Method;
43: import java.sql.ResultSet;
44: import java.sql.SQLException;
45: import java.util.ArrayList;
46: import java.util.HashSet;
47: import java.util.Iterator;
48: import java.util.Map;
49:
50: /**
51: * An embedded expression which should be loaded.
52: */
53: public class LoadEmbeddedExpr extends LoadExpr {
54: LoadEmbeddedExpr(PathExpr expr) {
55: super (expr);
56: }
57:
58: /**
59: * Returns the embeddable type.
60: */
61: public EmbeddableType getEmbeddableType() {
62: return (EmbeddableType) getType();
63: }
64:
65: /**
66: * Binds the expression as a select item.
67: */
68: public AmberExpr bindSelect(QueryParser parser) {
69: _fromItem = _expr.bindSubPath(parser);
70:
71: if (_fromItem == null)
72: throw new NullPointerException(_expr.getClass().getName()
73: + " " + _expr);
74:
75: return this ;
76: }
77:
78: /**
79: * Returns the object for the expr.
80: */
81: public Object getObject(AmberConnection aConn, ResultSet rs,
82: int index) throws SQLException {
83: Embeddable embeddable = getEmbeddableType().createObject();
84:
85: embeddable.__caucho_load(aConn, rs, index);
86:
87: return embeddable;
88: }
89:
90: /**
91: * Returns the object for the expr.
92: */
93: public Object getCacheObject(AmberConnection aConn, ResultSet rs,
94: int index) throws SQLException {
95: // XXX: needs to handle embeddable type caching.
96:
97: return getObject(aConn, rs, index);
98: }
99: }
|