00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.common.sql.schema;
00026
00027 import java.io.Serializable;
00028 import java.sql.SQLException;
00029 import java.util.ArrayList;
00030
00031 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00032
00033
00034
00035
00036
00037
00038 public class DatabaseProcedure implements Serializable
00039 {
00040
00041 public static final int ProcedureResultUnknown = 0;
00042
00043 public static final int ProcedureNoResult = 1;
00044
00045 public static final int ProcedureReturnsResult = 2;
00046
00047 ArrayList parameters;
00048 private String name;
00049 private String remarks;
00050 private int procedureType;
00051
00052
00053
00054
00055
00056
00057
00058
00059 public static int getTypeFromString(String type)
00060 {
00061 if (type.equals(DatabasesXmlTags.VAL_noResult))
00062 return ProcedureNoResult;
00063 if (type.equals(DatabasesXmlTags.VAL_returnsResult))
00064 return ProcedureReturnsResult;
00065 else
00066 return ProcedureResultUnknown;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 public static String getTypeFromInt(int type)
00076 {
00077 switch (type)
00078 {
00079 case ProcedureNoResult :
00080 return DatabasesXmlTags.VAL_noResult;
00081 case ProcedureReturnsResult :
00082 return DatabasesXmlTags.VAL_returnsResult;
00083 default :
00084 return DatabasesXmlTags.VAL_resultUnknown;
00085 }
00086 }
00087
00088
00089
00090
00091
00092
00093 public DatabaseProcedure(String name, String remarks, int procedureType)
00094 {
00095 this.name = name;
00096 this.remarks = remarks;
00097 this.procedureType = procedureType;
00098 this.parameters = new ArrayList();
00099 }
00100
00101
00102
00103
00104
00105
00106 public void addParameter(DatabaseProcedureParameter param)
00107 {
00108 parameters.add(param);
00109 }
00110
00111
00112
00113
00114 public String getName()
00115 {
00116 return name;
00117 }
00118
00119
00120
00121
00122 public void setName(String name)
00123 {
00124 this.name = name;
00125 }
00126
00127
00128
00129
00130 public ArrayList getParameters()
00131 {
00132 return parameters;
00133 }
00134
00135
00136
00137
00138 public void setParameters(ArrayList parameters)
00139 {
00140 this.parameters = parameters;
00141 }
00142
00143
00144
00145
00146 public int getProcedureType()
00147 {
00148 return procedureType;
00149 }
00150
00151
00152
00153
00154 public void setProcedureType(int procedureType)
00155 {
00156 this.procedureType = procedureType;
00157 }
00158
00159
00160
00161
00162 public String getRemarks()
00163 {
00164 return remarks;
00165 }
00166
00167
00168
00169
00170 public void setRemarks(String remarks)
00171 {
00172 this.remarks = remarks;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 public void mergeParameters(DatabaseProcedure procedure) throws SQLException
00184 {
00185 if (procedure == null)
00186 return;
00187
00188 ArrayList otherParameters = procedure.getParameters();
00189 if (otherParameters == null && parameters == null)
00190 return;
00191
00192 if (this.equals(procedure))
00193 {
00194
00195 return;
00196 }
00197 else
00198 {
00199 throw new SQLException("Unable to merge procedure " + getName()
00200 + ": parameters are differents ");
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211 public boolean equals(Object other)
00212 {
00213 if ((other == null) || !(other instanceof DatabaseProcedure))
00214 return false;
00215
00216 DatabaseProcedure p = (DatabaseProcedure) other;
00217 return (p.getName().equals(name)) && (p.getParameters().equals(parameters));
00218 }
00219
00220
00221
00222
00223
00224
00225 public String getXml()
00226 {
00227 StringBuffer info = new StringBuffer();
00228 info.append("<" + DatabasesXmlTags.ELT_DatabaseProcedure + " "
00229 + DatabasesXmlTags.ATT_name + "=\"" + name + "\" "
00230 + DatabasesXmlTags.ATT_returnType + "=\""
00231 + getTypeFromInt(procedureType) + "\">");
00232 for (int i = 0; i < parameters.size(); i++)
00233 info.append(((DatabaseProcedureParameter) parameters.get(i)).getXml());
00234 info.append("</" + DatabasesXmlTags.ELT_DatabaseProcedure + ">");
00235 return info.toString();
00236 }
00237
00238 }