KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > Join


1 //$Id: Join.java,v 1.11 2005/02/12 07:19:26 steveebersole Exp $
2
package org.hibernate.mapping;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Iterator JavaDoc;
7
8 import org.hibernate.sql.Alias;
9
10 /**
11  * @author Gavin King
12  */

13 public class Join implements Serializable JavaDoc {
14
15     private static final Alias PK_ALIAS = new Alias(15, "PK");
16
17     private ArrayList JavaDoc properties = new ArrayList JavaDoc();
18     private Table table;
19     private KeyValue key;
20     private PersistentClass persistentClass;
21     private boolean sequentialSelect;
22     private boolean inverse;
23     private boolean optional;
24
25     // Custom SQL
26
private String JavaDoc customSQLInsert;
27     private String JavaDoc customSQLUpdate;
28     private String JavaDoc customSQLDelete;
29     private boolean customInsertCallable;
30     private boolean customUpdateCallable;
31     private boolean customDeleteCallable;
32
33     public void addProperty(Property prop) {
34         properties.add(prop);
35         prop.setPersistentClass( getPersistentClass() );
36     }
37     public boolean containsProperty(Property prop) {
38         return properties.contains(prop);
39     }
40     public Iterator JavaDoc getPropertyIterator() {
41         return properties.iterator();
42     }
43
44     public Table getTable() {
45         return table;
46     }
47     public void setTable(Table table) {
48         this.table = table;
49     }
50
51     public KeyValue getKey() {
52         return key;
53     }
54     public void setKey(KeyValue key) {
55         this.key = key;
56     }
57
58     public PersistentClass getPersistentClass() {
59         return persistentClass;
60     }
61
62     public void setPersistentClass(PersistentClass persistentClass) {
63         this.persistentClass = persistentClass;
64     }
65
66     public void createForeignKey() {
67         getKey().createForeignKeyOfEntity( persistentClass.getEntityName() );
68     }
69
70     public void createPrimaryKey() {
71         //Primary key constraint
72
PrimaryKey pk = new PrimaryKey();
73         pk.setTable(table);
74         pk.setName( PK_ALIAS.toAliasString( table.getName() ) );
75         table.setPrimaryKey(pk);
76
77         pk.addColumns( getKey().getColumnIterator() );
78     }
79
80     public int getPropertySpan() {
81         return properties.size();
82     }
83
84     public String JavaDoc getCustomSQLDelete() {
85         return customSQLDelete;
86     }
87
88     public void setCustomSQLDelete(String JavaDoc customSQLDelete, boolean callable) {
89         this.customSQLDelete = customSQLDelete;
90         this.customDeleteCallable = callable;
91     }
92
93     public String JavaDoc getCustomSQLInsert() {
94         return customSQLInsert;
95     }
96
97     public void setCustomSQLInsert(String JavaDoc customSQLInsert, boolean callable) {
98         this.customSQLInsert = customSQLInsert;
99         this.customInsertCallable = callable;
100     }
101
102     public String JavaDoc getCustomSQLUpdate() {
103         return customSQLUpdate;
104     }
105
106     public void setCustomSQLUpdate(String JavaDoc customSQLUpdate, boolean callable) {
107         this.customSQLUpdate = customSQLUpdate;
108         this.customUpdateCallable = callable;
109     }
110
111     public boolean isCustomDeleteCallable() {
112         return customDeleteCallable;
113     }
114
115     public boolean isCustomInsertCallable() {
116         return customInsertCallable;
117     }
118
119     public boolean isCustomUpdateCallable() {
120         return customUpdateCallable;
121     }
122     public boolean isSequentialSelect() {
123         return sequentialSelect;
124     }
125     public void setSequentialSelect(boolean deferred) {
126         this.sequentialSelect = deferred;
127     }
128
129     public boolean isInverse() {
130         return inverse;
131     }
132     
133     public void setInverse(boolean leftJoin) {
134         this.inverse = leftJoin;
135     }
136
137     public String JavaDoc toString() {
138         return getClass().getName() + '(' + table.toString() + ')';
139     }
140     
141     public boolean isLazy() {
142         Iterator JavaDoc iter = getPropertyIterator();
143         while ( iter.hasNext() ) {
144             Property prop = (Property) iter.next();
145             if ( !prop.isLazy() ) return false;
146         }
147         return true;
148     }
149     
150     public boolean isOptional() {
151         return optional;
152     }
153     public void setOptional(boolean nullable) {
154         this.optional = nullable;
155     }
156 }
157
Popular Tags