01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.fetch;
12:
13: import com.versant.core.metadata.FetchGroup;
14: import com.versant.core.metadata.FetchGroupField;
15: import com.versant.core.jdbc.sql.exp.SqlExp;
16: import com.versant.core.jdbc.sql.exp.SelectExp;
17: import com.versant.core.jdbc.JdbcState;
18: import com.versant.core.jdbc.metadata.*;
19:
20: import java.sql.ResultSet;
21: import java.sql.SQLException;
22:
23: /**
24: * Fetch fields for a FetchGroup into a State that must already exist.
25: */
26: public class FopGetFetchGroup extends FetchOp {
27:
28: private final FetchOpData src;
29: private final FetchGroup fg;
30:
31: private int firstColIndex; // the index of our first select list col
32:
33: /**
34: * Create new to fetch fg. The src must provide the State and ResultSet.
35: */
36: public FopGetFetchGroup(FetchSpec spec, FetchOpData src,
37: FetchGroup fg) {
38: super (spec);
39: this .src = src;
40: this .fg = fg;
41: }
42:
43: public FetchOpData getOutputData() {
44: return src;
45: }
46:
47: public SqlExp init(SelectExp root, int firstColIndex) {
48: this .firstColIndex = firstColIndex;
49: //boolean joinok = !root.outer;
50: SqlExp list = null, pos = null;
51: FetchGroupField[] fields = fg.fields;
52: int n = fields.length;
53: for (int i = 0; i < n; i++) {
54: FetchGroupField field = fields[i];
55: JdbcField jdbcField = (JdbcField) field.fmd.storeField;
56: SqlExp ce = jdbcField.createOwningTableColumnExpList(root);
57: if (ce != null) {
58: if (list == null) {
59: pos = list = ce;
60: } else {
61: pos.next = ce;
62: for (; pos.next != null; pos = pos.next)
63: ;
64: }
65: }
66: if (!field.doNotFetchObject) {
67: jdbcField.prepareFetch(spec, spec.getOptions());
68: }
69: }
70: return list;
71: }
72:
73: public void fetch(FetchResultImp fetchResult) throws SQLException {
74: JdbcState state = (JdbcState) src.getState(fetchResult);
75: if (state == null) {
76: return; // nothing to fetch
77: }
78: ResultSet rs = src.getResultSet(fetchResult);
79: state.copyPass1Fields(rs, fg, firstColIndex);
80: }
81:
82: public String getDescription() {
83: return fg.name + src.getDescription();
84: }
85:
86: }
|