| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| InsertProcedureDescriptor |
|
| 2.2;2.2 |
| 1 | package org.apache.ojb.broker.metadata; | |
| 2 | ||
| 3 | /* Copyright 2003-2005 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | ||
| 18 | import org.apache.commons.lang.builder.ToStringBuilder; | |
| 19 | import org.apache.commons.lang.builder.ToStringStyle; | |
| 20 | import java.io.Serializable; | |
| 21 | import java.util.Iterator; | |
| 22 | ||
| 23 | /** | |
| 24 | * An InsertProcedureDescriptor contains information that is related to the | |
| 25 | * procedure/function that is used to handle the insertion of new records. | |
| 26 | * <br> | |
| 27 | * Note: Be careful when use InsertProcedureDescriptor variables or caching | |
| 28 | * InsertProcedureDescriptor instances, because instances could become invalid | |
| 29 | * during runtime (see {@link MetadataManager}). | |
| 30 | * | |
| 31 | * @author <a href="mailto:rongallagher@bellsouth.net">Ron Gallagher<a> | |
| 32 | * @version $Id: InsertProcedureDescriptor.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $ | |
| 33 | */ | |
| 34 | public class InsertProcedureDescriptor | |
| 35 | extends ProcedureDescriptor | |
| 36 | implements Serializable, XmlCapable | |
| 37 | { | |
| 38 | private static final long serialVersionUID = -3808311052971075269L; | |
| 39 | //--------------------------------------------------------------- | |
| 40 | /** | |
| 41 | * The value that indicates if the argument list for this procedure | |
| 42 | * includes all field-descriptors from the related class-descriptor. | |
| 43 | */ | |
| 44 | private boolean includeAllFields; | |
| 45 | ||
| 46 | //--------------------------------------------------------------- | |
| 47 | /** | |
| 48 | * Constructor declaration | |
| 49 | */ | |
| 50 | public InsertProcedureDescriptor( | |
| 51 | ClassDescriptor classDescriptor, | |
| 52 | String name, | |
| 53 | boolean includeAllFields) | |
| 54 | { | |
| 55 | super(classDescriptor, name); | |
| 56 | if (includeAllFields) | |
| 57 | { | |
| 58 | this.addArguments(this.getClassDescriptor().getFieldDescriptions()); | |
| 59 | } | |
| 60 | this.includeAllFields = includeAllFields; | |
| 61 | } | |
| 62 | ||
| 63 | //--------------------------------------------------------------- | |
| 64 | /** | |
| 65 | * Retrieve the value that indicates if the argument list for this | |
| 66 | * procedure includes all field-descriptors from the related | |
| 67 | * class-descriptor. | |
| 68 | * | |
| 69 | * @return The current value | |
| 70 | */ | |
| 71 | public boolean getIncludeAllFields() | |
| 72 | { | |
| 73 | return this.includeAllFields; | |
| 74 | } | |
| 75 | ||
| 76 | //--------------------------------------------------------------- | |
| 77 | /** | |
| 78 | * Add an argument | |
| 79 | * <p> | |
| 80 | * The argument will be added only if this procedure is not configured | |
| 81 | * to {@link #getIncludeAllFields() include all arguments}. | |
| 82 | */ | |
| 83 | public final void addArgument(ArgumentDescriptor argument) | |
| 84 | { | |
| 85 | if (!this.getIncludeAllFields()) | |
| 86 | { | |
| 87 | super.addArgument(argument); | |
| 88 | } | |
| 89 | } | |
| 90 | ||
| 91 | /* | |
| 92 | * @see XmlCapable#toXML() | |
| 93 | */ | |
| 94 | public String toXML() | |
| 95 | { | |
| 96 | RepositoryTags tags = RepositoryTags.getInstance(); | |
| 97 | String eol = System.getProperty( "line.separator" ); | |
| 98 | ||
| 99 | // The result | |
| 100 | StringBuffer result = new StringBuffer( 1024 ); | |
| 101 | result.append( eol ); | |
| 102 | result.append( " " ); | |
| 103 | ||
| 104 | // Opening tag and attributes | |
| 105 | result.append( " " ); | |
| 106 | result.append( tags.getOpeningTagNonClosingById( INSERT_PROCEDURE ) ); | |
| 107 | result.append( " " ); | |
| 108 | result.append( tags.getAttribute( NAME, this.getName() ) ); | |
| 109 | if( this.hasReturnValue() ) | |
| 110 | { | |
| 111 | result.append( " " ); | |
| 112 | result.append( tags.getAttribute( RETURN_FIELD_REF, this.getReturnValueFieldRefName() ) ); | |
| 113 | } | |
| 114 | result.append( " " ); | |
| 115 | result.append( tags.getAttribute( INCLUDE_ALL_FIELDS, String.valueOf( this.getIncludeAllFields() ) ) ); | |
| 116 | result.append( ">" ); | |
| 117 | result.append( eol ); | |
| 118 | ||
| 119 | // Write all arguments only if we're not including all fields. | |
| 120 | if( !this.getIncludeAllFields() ) | |
| 121 | { | |
| 122 | Iterator args = this.getArguments().iterator(); | |
| 123 | while( args.hasNext() ) | |
| 124 | { | |
| 125 | result.append( ( ( ArgumentDescriptor ) args.next() ).toXML() ); | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | // Closing tag | |
| 130 | result.append( " " ); | |
| 131 | result.append( tags.getClosingTagById( INSERT_PROCEDURE ) ); | |
| 132 | result.append( eol ); | |
| 133 | return result.toString(); | |
| 134 | } | |
| 135 | ||
| 136 | //--------------------------------------------------------------- | |
| 137 | /** | |
| 138 | * Provide a string representation of this object | |
| 139 | * | |
| 140 | * @return a string representation of this object | |
| 141 | */ | |
| 142 | public String toString() | |
| 143 | { | |
| 144 | ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); | |
| 145 | buf.append("name", this.getName()); | |
| 146 | buf.append("includeAllFields", this.getIncludeAllFields()); | |
| 147 | if (this.hasReturnValue()) | |
| 148 | { | |
| 149 | buf.append("returnFieldRefName", this.getReturnValueFieldRefName()); | |
| 150 | } | |
| 151 | return buf.toString(); | |
| 152 | } | |
| 153 | } |