001: //$Id: Join.java 10040 2006-06-22 19:51:43Z steve.ebersole@jboss.com $
002: package org.hibernate.mapping;
003:
004: import java.io.Serializable;
005: import java.util.ArrayList;
006: import java.util.Iterator;
007:
008: import org.hibernate.sql.Alias;
009: import org.hibernate.engine.ExecuteUpdateResultCheckStyle;
010:
011: /**
012: * @author Gavin King
013: */
014: public class Join implements Serializable {
015:
016: private static final Alias PK_ALIAS = new Alias(15, "PK");
017:
018: private ArrayList properties = new ArrayList();
019: private Table table;
020: private KeyValue key;
021: private PersistentClass persistentClass;
022: private boolean sequentialSelect;
023: private boolean inverse;
024: private boolean optional;
025:
026: // Custom SQL
027: private String customSQLInsert;
028: private boolean customInsertCallable;
029: private ExecuteUpdateResultCheckStyle insertCheckStyle;
030: private String customSQLUpdate;
031: private boolean customUpdateCallable;
032: private ExecuteUpdateResultCheckStyle updateCheckStyle;
033: private String customSQLDelete;
034: private boolean customDeleteCallable;
035: private ExecuteUpdateResultCheckStyle deleteCheckStyle;
036:
037: public void addProperty(Property prop) {
038: properties.add(prop);
039: prop.setPersistentClass(getPersistentClass());
040: }
041:
042: public boolean containsProperty(Property prop) {
043: return properties.contains(prop);
044: }
045:
046: public Iterator getPropertyIterator() {
047: return properties.iterator();
048: }
049:
050: public Table getTable() {
051: return table;
052: }
053:
054: public void setTable(Table table) {
055: this .table = table;
056: }
057:
058: public KeyValue getKey() {
059: return key;
060: }
061:
062: public void setKey(KeyValue key) {
063: this .key = key;
064: }
065:
066: public PersistentClass getPersistentClass() {
067: return persistentClass;
068: }
069:
070: public void setPersistentClass(PersistentClass persistentClass) {
071: this .persistentClass = persistentClass;
072: }
073:
074: public void createForeignKey() {
075: getKey().createForeignKeyOfEntity(
076: persistentClass.getEntityName());
077: }
078:
079: public void createPrimaryKey() {
080: //Primary key constraint
081: PrimaryKey pk = new PrimaryKey();
082: pk.setTable(table);
083: pk.setName(PK_ALIAS.toAliasString(table.getName()));
084: table.setPrimaryKey(pk);
085:
086: pk.addColumns(getKey().getColumnIterator());
087: }
088:
089: public int getPropertySpan() {
090: return properties.size();
091: }
092:
093: public void setCustomSQLInsert(String customSQLInsert,
094: boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
095: this .customSQLInsert = customSQLInsert;
096: this .customInsertCallable = callable;
097: this .insertCheckStyle = checkStyle;
098: }
099:
100: public String getCustomSQLInsert() {
101: return customSQLInsert;
102: }
103:
104: public boolean isCustomInsertCallable() {
105: return customInsertCallable;
106: }
107:
108: public ExecuteUpdateResultCheckStyle getCustomSQLInsertCheckStyle() {
109: return insertCheckStyle;
110: }
111:
112: public void setCustomSQLUpdate(String customSQLUpdate,
113: boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
114: this .customSQLUpdate = customSQLUpdate;
115: this .customUpdateCallable = callable;
116: this .updateCheckStyle = checkStyle;
117: }
118:
119: public String getCustomSQLUpdate() {
120: return customSQLUpdate;
121: }
122:
123: public boolean isCustomUpdateCallable() {
124: return customUpdateCallable;
125: }
126:
127: public ExecuteUpdateResultCheckStyle getCustomSQLUpdateCheckStyle() {
128: return updateCheckStyle;
129: }
130:
131: public void setCustomSQLDelete(String customSQLDelete,
132: boolean callable, ExecuteUpdateResultCheckStyle checkStyle) {
133: this .customSQLDelete = customSQLDelete;
134: this .customDeleteCallable = callable;
135: this .deleteCheckStyle = checkStyle;
136: }
137:
138: public String getCustomSQLDelete() {
139: return customSQLDelete;
140: }
141:
142: public boolean isCustomDeleteCallable() {
143: return customDeleteCallable;
144: }
145:
146: public ExecuteUpdateResultCheckStyle getCustomSQLDeleteCheckStyle() {
147: return deleteCheckStyle;
148: }
149:
150: public boolean isSequentialSelect() {
151: return sequentialSelect;
152: }
153:
154: public void setSequentialSelect(boolean deferred) {
155: this .sequentialSelect = deferred;
156: }
157:
158: public boolean isInverse() {
159: return inverse;
160: }
161:
162: public void setInverse(boolean leftJoin) {
163: this .inverse = leftJoin;
164: }
165:
166: public String toString() {
167: return getClass().getName() + '(' + table.toString() + ')';
168: }
169:
170: public boolean isLazy() {
171: Iterator iter = getPropertyIterator();
172: while (iter.hasNext()) {
173: Property prop = (Property) iter.next();
174: if (!prop.isLazy())
175: return false;
176: }
177: return true;
178: }
179:
180: public boolean isOptional() {
181: return optional;
182: }
183:
184: public void setOptional(boolean nullable) {
185: this.optional = nullable;
186: }
187: }
|