KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > TableExpression


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: TableExpression.java,v 1.4 2003/08/04 16:40:35 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import javax.jdo.JDOFatalInternalException;
14 import javax.jdo.JDOUserException;
15
16
17 /**
18  * Represents a SQL table expression as might be listed in the FROM clause of
19  * a SELECT statement.
20  * A table expression is a fragment of a larger containing QueryStatement.
21  * <p>
22  * A table expression has a base "main" table.
23  * If that table serves as backing for a Java class, and that class has
24  * persistence-capable superclasses, then the table expression may include
25  * joins to superclass tables, or may cause such joins to occur in its
26  * surrounding QueryStatement.
27  *
28  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
29  * @version $Revision: 1.4 $
30  *
31  * @see QueryStatement
32  */

33
34 abstract class TableExpression
35 {
36     protected final QueryStatement qs;
37     protected final Table mainTable;
38     protected final SQLIdentifier mainRangeVar;
39     protected final StoreManager storeMgr;
40     protected String JavaDoc sqlText = null;
41
42     protected TableExpression(QueryStatement qs, Table mainTable, SQLIdentifier mainRangeVar)
43     {
44         this.qs = qs;
45         this.mainTable = mainTable;
46         this.mainRangeVar = mainRangeVar;
47
48         storeMgr = mainTable.getStoreManager();
49     }
50
51     protected void assertNotFrozen()
52     {
53         if (sqlText != null)
54             throw new JDOFatalInternalException("A table expression cannot be modified after being output");
55     }
56
57     public final Table getMainTable()
58     {
59         return mainTable;
60     }
61
62     public final SQLIdentifier getRangeVariable()
63     {
64         return mainRangeVar;
65     }
66
67     public SQLExpression newFieldExpression(String JavaDoc fieldName)
68     {
69         if (!(mainTable instanceof ClassTable))
70             throw new JDOUserException("'" + fieldName + "' can't be referenced in " + mainTable.getName() + ": table does not store a persistence-capable class");
71
72         ClassTable ct = (ClassTable)mainTable;
73         Mapping m;
74
75         if (fieldName.equals("this") && ct instanceof ClassBaseTable)
76             m = ((ClassBaseTable)ct).getIDMapping();
77         else
78             m = ct.getFieldMapping(fieldName);
79
80         return m.newSQLExpression(qs, this, fieldName);
81     }
82
83     public abstract String JavaDoc referenceColumn(Column col);
84
85     public abstract String JavaDoc toString();
86 }
87
Popular Tags