1 56 package org.objectstyle.cayenne.map; 57 58 import org.objectstyle.cayenne.dba.TypesMapping; 59 import org.objectstyle.cayenne.util.Util; 60 import org.objectstyle.cayenne.util.XMLEncoder; 61 import org.objectstyle.cayenne.util.XMLSerializable; 62 63 68 public class ProcedureParameter extends MapObject implements XMLSerializable { 69 public static final int IN_OUT_PARAMETER = 3; 70 public static final int IN_PARAMETER = 1; 71 public static final int OUT_PARAMETER = 2; 72 73 protected int direction = -1; 74 75 protected int maxLength = -1; 77 78 protected int precision = -1; 80 protected int type = TypesMapping.NOT_DEFINED; 81 82 85 public ProcedureParameter() { 86 super(); 87 } 88 89 public ProcedureParameter(String name) { 90 super(name); 91 } 92 93 public ProcedureParameter(String name, int type, int direction) { 94 super(name); 95 setType(type); 96 setDirection(direction); 97 } 98 99 104 public void encodeAsXML(XMLEncoder encoder) { 105 encoder.print("<procedure-parameter name=\"" + Util.encodeXmlAttribute(getName()) + '\"'); 106 107 String type = TypesMapping.getSqlNameByType(getType()); 108 if (type != null) { 109 encoder.print(" type=\"" + type + '\"'); 110 } 111 112 if (getMaxLength() > 0) { 113 encoder.print(" length=\""); 114 encoder.print(getMaxLength()); 115 encoder.print('\"'); 116 } 117 118 if (getPrecision() > 0) { 119 encoder.print(" precision=\""); 120 encoder.print(getPrecision()); 121 encoder.print('\"'); 122 } 123 124 int direction = getDirection(); 125 if (direction == ProcedureParameter.IN_PARAMETER) { 126 encoder.print(" direction=\"in\""); 127 } 128 else if (direction == ProcedureParameter.IN_OUT_PARAMETER) { 129 encoder.print(" direction=\"in_out\""); 130 } 131 else if (direction == ProcedureParameter.OUT_PARAMETER) { 132 encoder.print(" direction=\"out\""); 133 } 134 135 encoder.println("/>"); 136 } 137 138 142 public int getDirection() { 143 return direction; 144 } 145 146 147 public Procedure getEntity() { 148 return (Procedure) getParent(); 149 } 150 151 public int getMaxLength() { 152 return maxLength; 153 } 154 155 public int getPrecision() { 156 return precision; 157 } 158 159 public int getType() { 160 return type; 161 } 162 163 166 public boolean isInParameter() { 167 return direction == IN_PARAMETER || direction == IN_OUT_PARAMETER; 168 } 169 170 173 public boolean isOutParam() { 174 return direction == OUT_PARAMETER || direction == IN_OUT_PARAMETER; 175 } 176 177 183 public void setDirection(int direction) { 184 if (direction != IN_PARAMETER 185 && direction != OUT_PARAMETER 186 && direction != IN_OUT_PARAMETER) { 187 throw new IllegalArgumentException ("Unknown parameter type: " + direction); 188 } 189 190 this.direction = direction; 191 } 192 193 public void setMaxLength(int i) { 194 maxLength = i; 195 } 196 197 public void setPrecision(int i) { 198 precision = i; 199 } 200 201 public void setType(int i) { 202 type = i; 203 } 204 205 206 public Procedure getProcedure() { 207 return (Procedure) getParent(); 208 } 209 210 211 public void setProcedure(Procedure procedure) { 212 setParent(procedure); 213 } 214 } 215 | Popular Tags |