KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > fetch > FopGetFetchGroup


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.fetch;
13
14 import com.versant.core.metadata.FetchGroup;
15 import com.versant.core.metadata.FetchGroupField;
16 import com.versant.core.jdbc.sql.exp.SqlExp;
17 import com.versant.core.jdbc.sql.exp.SelectExp;
18 import com.versant.core.jdbc.JdbcState;
19 import com.versant.core.jdbc.metadata.*;
20
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.SQLException JavaDoc;
23
24 /**
25  * Fetch fields for a FetchGroup into a State that must already exist.
26  */

27 public class FopGetFetchGroup extends FetchOp {
28
29     private final FetchOpData src;
30     private final FetchGroup fg;
31
32     private int firstColIndex; // the index of our first select list col
33

34     /**
35      * Create new to fetch fg. The src must provide the State and ResultSet.
36      */

37     public FopGetFetchGroup(FetchSpec spec, FetchOpData src, 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             if (!field.doNotFetchObject) {
66                 jdbcField.prepareFetch(spec, spec.getOptions());
67             }
68         }
69         return list;
70     }
71
72     public void fetch(FetchResultImp fetchResult) throws SQLException JavaDoc {
73         JdbcState state = (JdbcState)src.getState(fetchResult);
74         if (state == null) {
75             return; // nothing to fetch
76
}
77         ResultSet JavaDoc rs = src.getResultSet(fetchResult);
78         state.copyPass1Fields(rs, fg, firstColIndex);
79     }
80
81     public String JavaDoc getDescription() {
82         return fg.name + src.getDescription();
83     }
84
85 }
86
87
Popular Tags