KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > sql > exp > BinaryExp


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.sql.exp;
13
14 import com.versant.core.jdbc.sql.SqlDriver;
15
16 /**
17  * An expression with two args.
18  */

19 public class BinaryExp extends SqlExp {
20
21     public BinaryExp(SqlExp left, SqlExp right) {
22         super(left);
23         left.next = right;
24         right.next = null;
25     }
26
27     public BinaryExp() {
28     }
29
30     public SqlExp createInstance() {
31         return new BinaryExp();
32     }
33
34     /**
35      * Create an aliases for any subtables we may have.
36      */

37     public int createAlias(int index) {
38         return childList.next.createAlias(childList.createAlias(index));
39     }
40
41     /**
42      * Replace any references to old with nw. This is used when redundant
43      * joins are removed.
44      */

45     public void replaceSelectExpRef(SelectExp old, SelectExp nw) {
46         childList.replaceSelectExpRef(old, nw);
47         childList.next.replaceSelectExpRef(old, nw);
48     }
49
50     /**
51      * Normalize this node i.e. transform it into its simplist possible form.
52      * This will turn sub selects into joins and so on.
53      */

54     public SqlExp normalize(SqlDriver driver, SelectExp sel, boolean convertExists) {
55         SqlExp r = childList.normalize(driver, sel, convertExists);
56         if (r != null) {
57             r.next = childList.next;
58             childList = r;
59         }
60         r = childList.next.normalize(driver, sel, convertExists);
61         if (r != null) {
62             childList.next = r;
63         }
64         return null;
65     }
66
67     /**
68      * If this expression involves a single table only then return the
69      * SelectExp for the table (e.g. a.col1 == 10 returns a, a.col1 = b.col2
70      * returns null). This is used to detect expressions that can be moved
71      * into the ON list for the join to the table involved.
72      * @param exclude
73      */

74     public SelectExp getSingleSelectExp(SelectExp exclude) {
75         SelectExp a = childList.getSingleSelectExp(exclude);
76         SelectExp b = childList.next.getSingleSelectExp(exclude);
77         if (b == null || b == exclude) return a;
78         if (a == null || a == exclude) return b;
79         return a == b ? a : null;
80     }
81
82 }
83
Popular Tags