Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 24 25 package org.objectweb.cjdbc.common.sql.schema; 26 27 import java.sql.SQLException ; 28 import java.util.ArrayList ; 29 30 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 31 32 37 public class DatabaseProcedure 38 { 39 40 public static final int ProcedureResultUnknown = 0; 41 42 public static final int ProcedureNoResult = 1; 43 44 public static final int ProcedureReturnsResult = 2; 45 46 ArrayList parameters; 47 private String name; 48 private String remarks; 49 private int procedureType; 50 51 58 public static int getTypeFromString(String type) 59 { 60 if (type.equals(DatabasesXmlTags.VAL_noResult)) 61 return ProcedureNoResult; 62 if (type.equals(DatabasesXmlTags.VAL_returnsResult)) 63 return ProcedureReturnsResult; 64 else 65 return ProcedureResultUnknown; 66 } 67 68 74 public static String getTypeFromInt(int type) 75 { 76 switch (type) 77 { 78 case ProcedureNoResult : 79 return DatabasesXmlTags.VAL_noResult; 80 case ProcedureReturnsResult : 81 return DatabasesXmlTags.VAL_returnsResult; 82 default : 83 return DatabasesXmlTags.VAL_resultUnknown; 84 } 85 } 86 87 92 public DatabaseProcedure(String name, String remarks, int procedureType) 93 { 94 this.name = name; 95 this.remarks = remarks; 96 this.procedureType = procedureType; 97 this.parameters = new ArrayList (); 98 } 99 100 105 public void addParameter(DatabaseProcedureParameter param) 106 { 107 parameters.add(param); 108 } 109 110 113 public String getName() 114 { 115 return name; 116 } 117 118 121 public void setName(String name) 122 { 123 this.name = name; 124 } 125 126 129 public ArrayList getParameters() 130 { 131 return parameters; 132 } 133 134 137 public void setParameters(ArrayList parameters) 138 { 139 this.parameters = parameters; 140 } 141 142 145 public int getProcedureType() 146 { 147 return procedureType; 148 } 149 150 153 public void setProcedureType(int procedureType) 154 { 155 this.procedureType = procedureType; 156 } 157 158 161 public String getRemarks() 162 { 163 return remarks; 164 } 165 166 169 public void setRemarks(String remarks) 170 { 171 this.remarks = remarks; 172 } 173 174 182 public void mergeParameters(DatabaseProcedure procedure) throws SQLException  183 { 184 if (procedure == null) 185 return; 186 187 ArrayList otherParameters = procedure.getParameters(); 188 if (otherParameters == null && parameters == null) 189 return; 190 191 if (this.equals(procedure)) 192 { 193 return; 195 } 196 else 197 { 198 throw new SQLException ("Unable to merge procedure " + getName() 199 + ": parameters are differents "); 200 } 201 } 202 203 210 public boolean equals(Object other) 211 { 212 if ((other == null) || !(other instanceof DatabaseProcedure)) 213 return false; 214 215 DatabaseProcedure p = (DatabaseProcedure) other; 216 return (p.getName().equals(name)) && (p.getParameters().equals(parameters)); 217 } 218 219 224 public String getXml() 225 { 226 StringBuffer info = new StringBuffer (); 227 info.append("<" + DatabasesXmlTags.ELT_DatabaseProcedure + " " 228 + DatabasesXmlTags.ATT_name + "=\"" + name + "\" " 229 + DatabasesXmlTags.ATT_returnType + "=\"" 230 + getTypeFromInt(procedureType) + "\">"); 231 for (int i = 0; i < parameters.size(); i++) 232 info.append(((DatabaseProcedureParameter) parameters.get(i)).getXml()); 233 info.append("</" + DatabasesXmlTags.ELT_DatabaseProcedure + ">"); 234 return info.toString(); 235 } 236 237 } 238
| Popular Tags
|