001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.metadata;
018:
019: import java.util.List;
020:
021: /**
022: * Defines a join between a main table and an external table.
023: *
024: * @see org.objectweb.speedo.metadata.SpeedoTable
025: * @see org.objectweb.speedo.metadata.SpeedoColumn
026: *
027: * @author S.Chassande-Barrioz
028: */
029: public class SpeedoJoin extends SpeedoElement {
030: /**
031: * main table
032: */
033: public SpeedoTable mainTable;
034:
035: /**
036: * external table
037: */
038: public SpeedoTable extTable;
039:
040: /**
041: * The list of SpeedoJoinColumn composing the join. This columns are in the
042: * external table.
043: */
044: public List columns;
045:
046: private final static byte ALL = (byte) 0xFF;
047: private final static byte INDEXED = 1;
048: private final static byte OUTER_JOIN = 2;
049: private final static byte UNIQUE = 4;
050: private byte conditions = 0;
051:
052: public final static byte ACTION_NONE = 1;
053: public final static byte ACTION_NULL = 2;
054: public final static byte ACTION_CASCADE = 3;
055: public final static byte ACTION_RESTRICT = 4;
056: public final static byte ACTION_DEFAULT = 5;
057:
058: /**
059: * Defines the action to do on the external table when a delete action
060: * occurs in the main table.
061: */
062: public byte deleteAction;
063:
064: public SpeedoJoin() {
065: SpeedoDefaults.setDefaults(this );
066: }
067:
068: public void setOuter(boolean v) {
069: setCondition(v, OUTER_JOIN);
070: }
071:
072: public boolean getOuter() {
073: return getCondition(OUTER_JOIN);
074: }
075:
076: public void setIndexed(boolean v) {
077: setCondition(v, INDEXED);
078: }
079:
080: /**
081: * @return boolean value indicating if the join column are unique.
082: */
083: public boolean getIndexed() {
084: return getCondition(INDEXED);
085: }
086:
087: public void setUnique(boolean v) {
088: setCondition(v, UNIQUE);
089: }
090:
091: public boolean getUnique() {
092: return getCondition(UNIQUE);
093: }
094:
095: private void setCondition(boolean v, byte condition) {
096: if (v) {
097: conditions = (byte) (conditions | condition);
098: } else {
099: conditions = (byte) (conditions & (ALL - condition));
100: }
101: }
102:
103: private boolean getCondition(byte condition) {
104: return (conditions & condition) == 1;
105: }
106:
107: public String toString() {
108: StringBuffer sb = new StringBuffer();
109: sb.append("SpeedoJoin between '");
110: if (mainTable == null) {
111: sb.append("null");
112: } else {
113: sb.append(mainTable.name);
114: }
115: sb.append("' and '");
116: if (extTable == null) {
117: sb.append("null");
118: } else {
119: sb.append(extTable.name);
120: }
121: sb.append(" with this column").append(columns);
122: return sb.toString();
123: }
124: }
|