001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.amber.field;
030:
031: import com.caucho.amber.table.LinkColumns;
032: import com.caucho.amber.type.RelatedType;
033: import com.caucho.config.ConfigException;
034: import com.caucho.log.Log;
035: import com.caucho.util.L10N;
036:
037: import javax.persistence.CascadeType;
038: import java.util.logging.Logger;
039:
040: /**
041: * Configuration for a bean's field
042: */
043: public class AssociationField extends CollectionField {
044: private static final L10N L = new L10N(AssociationField.class);
045: protected static final Logger log = Log
046: .open(AssociationField.class);
047:
048: private LinkColumns _linkColumns;
049:
050: private boolean _hasJoinColumns;
051:
052: private boolean _hasInverseJoinColumns;
053:
054: public AssociationField(RelatedType relatedType, String name,
055: CascadeType[] cascadeTypes) throws ConfigException {
056: super (relatedType, name, cascadeTypes);
057: }
058:
059: public AssociationField(RelatedType relatedType) {
060: super (relatedType);
061: }
062:
063: /**
064: * Returns true if this field is annotated with
065: * @JoinTable and the attribute joinColumns.
066: */
067: public boolean hasJoinColumns() {
068: return _hasJoinColumns;
069: }
070:
071: /**
072: * Sets true if this field is annotated with
073: * @JoinTable and the attribute joinColumns.
074: */
075: public void setJoinColumns(boolean hasJoinColumns) {
076: _hasJoinColumns = hasJoinColumns;
077: }
078:
079: /**
080: * Returns true if this field is annotated with
081: * @JoinTable and the attribute inverseJoinColumns.
082: */
083: public boolean hasInverseJoinColumns() {
084: return _hasInverseJoinColumns;
085: }
086:
087: /**
088: * Sets true if this field is annotated with
089: * @JoinTable and the attribute inverseJoinColumns.
090: */
091: public void setInverseJoinColumns(boolean hasInverseJoinColumns) {
092: _hasInverseJoinColumns = hasInverseJoinColumns;
093: }
094:
095: /**
096: * Sets the result columns.
097: */
098: public void setLinkColumns(LinkColumns columns) {
099: _linkColumns = columns;
100: }
101:
102: /**
103: * Gets the result.
104: */
105: public LinkColumns getLinkColumns() {
106: return _linkColumns;
107: }
108:
109: /**
110: * Generates the target select.
111: */
112: public String generateTargetSelect(String id) {
113: return getLinkColumns().generateSelectSQL(id);
114: }
115: }
|