1 19 20 package org.netbeans.lib.ddl.impl; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import org.openide.util.NbBundle; 25 26 import org.netbeans.lib.ddl.Argument; 27 import org.netbeans.lib.ddl.DatabaseSpecification; 28 import org.netbeans.lib.ddl.DDLException; 29 import org.netbeans.lib.ddl.util.CommandFormatter; 30 31 34 public class ProcedureArgument implements Argument { 35 36 private String name; 37 38 39 private int type; 40 41 42 private int dtype; 43 44 45 private String format; 46 47 48 private Map addprops; 49 50 public static String getArgumentTypeName(int type) 51 { 52 String typename = null; 53 switch (type) { 54 case java.sql.DatabaseMetaData.procedureColumnIn: typename = "IN"; break; case java.sql.DatabaseMetaData.procedureColumnOut: typename = "OUT"; break; case java.sql.DatabaseMetaData.procedureColumnInOut: typename = "INOUT"; break; } 58 59 return typename; 60 } 61 62 63 public String getName() 64 { 65 return name; 66 } 67 68 69 public void setName(String aname) 70 { 71 name = aname; 72 } 73 74 75 public String getFormat() 76 { 77 return format; 78 } 79 80 81 public void setFormat(String fmt) 82 { 83 format = fmt; 84 } 85 86 87 public Object getProperty(String pname) 88 { 89 return addprops.get(pname); 90 } 91 92 93 public void setProperty(String pname, Object pval) 94 { 95 if (addprops == null) addprops = new HashMap (); 96 addprops.put(pname, pval); 97 } 98 99 102 public int getType() 103 { 104 return type; 105 } 106 107 109 public String getTypeName() 110 { 111 return getArgumentTypeName(type); 112 } 113 114 115 public void setType(int atype) 116 { 117 type = atype; 118 } 119 120 121 public int getDataType() 122 { 123 return dtype; 124 } 125 126 127 public void setDataType(int atype) 128 { 129 dtype = atype; 130 } 131 132 139 public Map getColumnProperties(AbstractCommand cmd) throws DDLException { 140 HashMap args = new HashMap (); 141 DatabaseSpecification spec = cmd.getSpecification(); 142 Map typemap = (Map )spec.getProperties().get("ProcedureArgumentMap"); String typename = (String )typemap.get(getArgumentTypeName(type)); 144 args.put("argument.name", cmd.quote(name)); args.put("argument.type", typename); args.put("argument.datatype", spec.getType(dtype)); return args; 148 } 149 150 153 public String getCommand(CreateProcedure cmd) 154 throws DDLException 155 { 156 Map cprops; 157 if (format == null) throw new DDLException(NbBundle.getBundle("org.netbeans.lib.ddl.resources.Bundle").getString("EXC_NoFormatSpec")); try { 159 cprops = getColumnProperties(cmd); 160 return CommandFormatter.format(format, cprops); 161 } catch (Exception e) { 162 throw new DDLException(e.getMessage()); 163 } 164 } 165 } 166 | Popular Tags |