View Javadoc

1   // $Id: Procedure.java,v 1.3 2007/08/08 11:41:11 kameleono Exp $
2   package net.sourceforge.sql2java;
3   
4   import java.util.ArrayList;
5   import java.util.HashMap;
6   import java.util.List;
7   
8   public class Procedure {
9   	private static final String IN_COLUMN = "IN";
10  	private static final String IN_OUT_COLUMN = "INOUT";
11  	private static final String OUT_COLUMN = "OUT";
12  
13      private String name;
14      private String sqlName;
15      private String remarks;
16      private String returnType;
17      /* List<Column> */
18      private List columns, inColumns, outColumns;
19      private HashMap colsHash;
20      private int position;
21      
22      public Procedure() {
23          columns = new ArrayList();
24          inColumns = new ArrayList();
25          outColumns = new ArrayList();
26          colsHash = new HashMap();
27          position = 1;
28      }
29      
30      private int nextPosition() {
31      	return position++;
32      }
33  
34      private boolean addColumn(Column column) {
35      	if (null == colsHash.get(column.getName())) {
36          	column.setOrdinalPosition(nextPosition());
37              columns.add(column);
38      		colsHash.put(column.getName(), column);
39      		return true;
40      	}
41      	return false;
42      }
43      
44      public void addInColumn(Column column) {
45      	column.setDefaultValue(IN_COLUMN);
46      	if (addColumn(column)) {
47      		inColumns.add(column);
48      	}
49      }
50      
51      public void addInOutColumn(Column column) {
52      	column.setDefaultValue(IN_OUT_COLUMN);
53      	if (addColumn(column)) {
54  	        inColumns.add(column);
55  	        outColumns.add(column);
56      	}
57      }
58  
59      public void addOutColumn(Column column) {
60      	column.setDefaultValue(OUT_COLUMN);
61      	if (addColumn(column)) {
62      		outColumns.add(column);
63      	}
64      }
65      
66      public int getColumnsCount() {
67      	return columns.size();
68      }
69      
70      public int getOutColumnsCount() {
71      	return outColumns.size();
72      }
73      
74      public Column[] getColumns() {
75          return (Column[]) columns.toArray(new Column[columns.size()]);
76      }
77      
78      public Column[] getInColumns() {
79          return (Column[]) inColumns.toArray(new Column[inColumns.size()]);
80      }
81      
82      public Column[] getOutColumns() {
83          return (Column[]) outColumns.toArray(new Column[outColumns.size()]);
84      }
85  
86      public String getName() {
87          return name;
88      }
89  
90      public void setName(String name) {
91      	this.sqlName = name;
92          this.name = StringUtilities.convertName(name, true);
93      }
94      
95      public String getSqlName() {
96      	return sqlName;
97      }
98  
99      public String getRemarks() {
100         return remarks;
101     }
102 
103     public void setRemarks(String remarks) {
104         this.remarks = remarks;
105     }
106 
107     public String getReturnType() {
108         return returnType;
109     }
110 
111     public void setReturnType(String returnType) {
112         this.returnType = returnType;
113     }
114 }