001 package org.apache.ojb.broker.metadata;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.commons.lang.builder.ToStringBuilder;
019 import org.apache.commons.lang.builder.ToStringStyle;
020 import java.io.Serializable;
021 import java.util.Iterator;
022
023 /**
024 * An DeleteProcedureDescriptor contains information that is related to the
025 * procedure/function that is used to handle the deleting of existing records.
026 * <br>
027 * Note: Be careful when use DeleteProcedureDescriptor variables or caching
028 * DeleteProcedureDescriptor instances, because instances could become invalid
029 * during runtime (see {@link MetadataManager}).
030 *
031 * @author <a href="mailto:rongallagher@bellsouth.net">Ron Gallagher<a>
032 * @version $Id: DeleteProcedureDescriptor.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
033 */
034 public class DeleteProcedureDescriptor extends ProcedureDescriptor
035 implements Serializable, XmlCapable
036 {
037 private static final long serialVersionUID = -1265854095889157172L;
038 //---------------------------------------------------------------
039 /**
040 * The value that indicates if the argument list for this procedure
041 * includes only the field-descriptors from the related class-descriptor
042 * that are identified as being part of the primary key.
043 */
044 private boolean includePkFieldsOnly;
045
046 //---------------------------------------------------------------
047
048 /**
049 * Constructor declaration
050 */
051 public DeleteProcedureDescriptor(ClassDescriptor classDescriptor,
052 String name, boolean includePkFieldsOnly)
053 {
054 super(classDescriptor, name);
055 if (includePkFieldsOnly)
056 {
057 addArguments(getClassDescriptor().getPkFields());
058 addArguments(getClassDescriptor().getLockingFields());
059 }
060 this.includePkFieldsOnly = includePkFieldsOnly;
061 }
062
063 //---------------------------------------------------------------
064 /**
065 * Retrieve the value that indicates if the argument list for this
066 * procedure includes only the field-descriptors from the related
067 * class-descriptor that are identified as being part of the primary
068 * key.
069 *
070 * @return The current value
071 */
072 public boolean getIncludePkFieldsOnly()
073 {
074 return this.includePkFieldsOnly;
075 }
076
077 //---------------------------------------------------------------
078 /**
079 * Add an argument
080 * <p>
081 * The argument will be added only if this procedure is not configured
082 * to {@link #getIncludePkFieldsOnly() include just the
083 * primary key fields}.
084 */
085 public final void addArgument(ArgumentDescriptor argument)
086 {
087 if (!this.getIncludePkFieldsOnly())
088 {
089 super.addArgument(argument);
090 }
091 }
092
093 /*
094 * @see XmlCapable#toXML()
095 */
096 public String toXML()
097 {
098 RepositoryTags tags = RepositoryTags.getInstance();
099 String eol = System.getProperty( "line.separator" );
100
101 // The result
102 StringBuffer result = new StringBuffer( 1024 );
103 result.append( eol );
104 result.append( " " );
105
106 // Opening tag and attributes
107 result.append( " " );
108 result.append( tags.getOpeningTagNonClosingById( DELETE_PROCEDURE ) );
109 result.append( " " );
110 result.append( tags.getAttribute( NAME, this.getName() ) );
111 if( this.hasReturnValue() )
112 {
113 result.append( " " );
114 result.append( tags.getAttribute( RETURN_FIELD_REF, this.getReturnValueFieldRefName() ) );
115 }
116 result.append( " " );
117 result.append( tags.getAttribute( INCLUDE_PK_FIELDS_ONLY, String.valueOf( this.getIncludePkFieldsOnly() ) ) );
118 result.append( ">" );
119 result.append( eol );
120
121 // Write all arguments only if we're not including all fields.
122 if( !this.getIncludePkFieldsOnly() )
123 {
124 Iterator args = this.getArguments().iterator();
125 while( args.hasNext() )
126 {
127 result.append( ( ( ArgumentDescriptor ) args.next() ).toXML() );
128 }
129 }
130
131 // Closing tag
132 result.append( " " );
133 result.append( tags.getClosingTagById( DELETE_PROCEDURE ) );
134 result.append( eol );
135 return result.toString();
136 }
137
138 //---------------------------------------------------------------
139 /**
140 * Provide a string representation of this object
141 *
142 * @return a string representation of this object
143 */
144 public String toString()
145 {
146 ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
147 buf.append("name", this.getName());
148 buf.append("includePkFieldsOnly", this.getIncludePkFieldsOnly());
149 if (this.hasReturnValue())
150 {
151 buf.append("returnFieldRefName", this.getReturnValueFieldRefName());
152 }
153 return buf.toString();
154 }
155 }