View Javadoc

1   /*
2    * Copyright 2006 Outsource Cafe, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the 'License')
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an 'AS IS' BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.javagen.agile.db.model;
17  
18  import javax.xml.bind.annotation.XmlAttribute;
19  import javax.xml.bind.annotation.XmlIDREF;
20  import javax.xml.bind.annotation.XmlRootElement;
21  
22  import org.javagen.agile.core.model.AbstractModel;
23  import org.javagen.agile.core.model.Model;
24  
25  
26  @XmlRootElement(name="columnReference")
27  public class ColumnReference extends AbstractModel {
28  
29  //	<foreign-key foreignTable="VEHICLE_STATUSES" onUpdate="none" onDelete="none">
30  //		<reference foreign="SYSTEM_ID" local="SYSTEM_ID"/>
31  //		<reference foreign="VEHICLE_STATUS_ID" local="VEHICLE_STATUS_ID"/>
32  //	</foreign-key>
33  
34      public static final String DEFAULT_MODEL_TYPE = "COLUMNREFERENCE";
35  
36      protected Column foreignColumn;
37  	protected Column localColumn;
38  	protected Short sequenceNumber;
39  
40  	public ColumnReference() {
41          super();
42          this.setModelType(DEFAULT_MODEL_TYPE);
43  	}
44  	
45  	public ColumnReference(FkConstraint parentFkColumn) {
46          this();
47  		this.setParentModel(parentFkColumn);
48  	}
49  	
50      ///////////////////////////////////////////////////////////////////////////
51      // getters and setters:
52      ///////////////////////////////////////////////////////////////////////////
53  
54      public String getName() {
55          if (name==null && foreignColumn!=null && localColumn!=null) {
56              name = localColumn.getName()+"_TO_"+foreignColumn.getName();
57          }
58          return name;
59      }
60      
61      @XmlIDREF
62  	public Column getForeignColumn() {
63  		return foreignColumn;
64  	}
65  	
66  	public void setForeignColumn(Column foreign) {
67  		this.foreignColumn = foreign;
68  	}
69  
70      @XmlIDREF
71      public Column getLocalColumn() {
72  		return localColumn;
73  	}
74  	public void setLocalColumn(Column local) {
75  		this.localColumn = local;
76  	}
77  
78      @XmlAttribute
79  	public Short getSequenceNumber() {
80  		return sequenceNumber;
81  	}
82  	public void setSequenceNumber(Short sequenceNumber) {
83  		this.sequenceNumber = sequenceNumber;
84  	}
85  	
86      ///////////////////////////////////////////////////////////////////////////
87      // misc methods:
88      ///////////////////////////////////////////////////////////////////////////
89  
90      /*** Recursive relationship within single table */
91      public boolean isSelfReferential() {
92          return getLocalColumn().getParentTable() == this.getForeignColumn().getParentTable();
93      }
94  
95      @Override
96      public void copyTo(Model targetModel) {
97          ColumnReference target = (ColumnReference)targetModel;
98  		super.copyTo(target);
99  		if (this.getSequenceNumber()!=null)
100 			target.setSequenceNumber(this.getSequenceNumber());
101 	}
102 
103 }