KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > sql > generator > CorrelatedExistSelectPlan


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.jdo.spi.persistence.support.sqlstore.sql.generator;
25
26 import com.sun.jdo.spi.persistence.support.sqlstore.ActionDesc;
27 import com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc;
28 import com.sun.jdo.spi.persistence.support.sqlstore.SQLStoreManager;
29 import com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc;
30 import com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc;
31 import com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.ConstraintFieldDesc;
32
33 import java.util.ArrayList JavaDoc;
34
35 /**
36  * Implements the select plan for Exist-Subqueries.
37  *
38  * @author Mitesh Meswani
39  * @author Markus Fuchs
40  */

41 public class CorrelatedExistSelectPlan extends CorrelatedSelectPlan {
42
43     public CorrelatedExistSelectPlan(RetrieveDesc desc,
44                                      SQLStoreManager store,
45                                      ForeignFieldDesc parentField,
46                                      SelectQueryPlan parentPlan) {
47
48         super(desc, store, parentField, parentPlan);
49     }
50
51     /**
52      * There are no real fields to be selected for an (NOT)EXIST query.
53      * This method just adds the table for the nested select.
54      * The statement for nested select is created as a side effect.
55      */

56     protected void processFields() {
57         for (int i = 0; i < parentField.foreignFields.size(); i++) {
58             LocalFieldDesc field = (LocalFieldDesc) parentField.foreignFields.get(i);
59             addTable(field);
60         }
61     }
62
63     /**
64      * The correlated constraint joining this subquery with the parent field.
65      * The joined table is added as a side-effect.
66      */

67     protected void doCorrelatedJoin() {
68         ArrayList JavaDoc foreignFields = null;
69
70         if (parentField.useJoinTable()) {
71             foreignFields = parentField.assocLocalFields;
72             // The join table is included in #processJoinTable
73
} else {
74             foreignFields = parentField.foreignFields;
75         }
76
77         ArrayList JavaDoc localFields = parentField.localFields;
78         // Add the constraint linking the parent query with the subquery.
79
for (int i = 0; i < localFields.size(); i++) {
80             LocalFieldDesc la = (LocalFieldDesc) localFields.get(i);
81             LocalFieldDesc fa = (LocalFieldDesc) foreignFields.get(i);
82
83             ConstraintFieldDesc lcfd = new ConstraintFieldDesc(la, parentPlan);
84             ConstraintFieldDesc fcfd = new ConstraintFieldDesc(fa, this);
85
86             constraint.addField(lcfd);
87             constraint.addField(fcfd);
88             // Subqueries always join via equijoin.
89
constraint.addOperation(ActionDesc.OP_EQ);
90         }
91     }
92
93     protected Statement newStatement() {
94         return new SelectOneStatement(store.getVendorType(), this);
95     }
96
97 }
98
Popular Tags