View Javadoc

1   /*
2    * 
3    * 
4    */
5   package oscon2006.mock;
6   
7   import java.sql.ResultSetMetaData;
8   import java.sql.SQLException;
9   import java.sql.Types;
10  import java.util.*;
11  
12  public class MockResultSetMetaData implements ResultSetMetaData
13  {
14  
15  	public static MockResultSetMetaData getDefaultMetaData()
16  	{
17  		MockResultSetMetaData meta = new MockResultSetMetaData();
18  		
19  		meta.addColumn(new MockColumn(Types.VARCHAR, "VarcharColumn"));
20  		meta.addColumn(new MockColumn(Types.BOOLEAN, "BooleanColumn"));
21  		meta.addColumn(new MockColumn(Types.INTEGER, "IntegerColumn"));
22  		meta.addColumn(new MockColumn(Types.DOUBLE, "DoubleColumn"));
23  		meta.addColumn(new MockColumn(Types.TIME, "TimeColumn"));
24  		meta.addColumn(new MockColumn(Types.DATE, "DateColumn"));
25  		meta.addColumn(new MockColumn(Types.CHAR, "CharColumn"));
26  		meta.addColumn(new MockColumn(Types.JAVA_OBJECT, "JavaObjectColumn"));
27  		meta.addColumn(new MockColumn(Types.TIMESTAMP, "TimeStampColumn"));
28  		meta.addColumn(new MockColumn(Types.NUMERIC, "NumericColumn"));
29  		meta.addColumn(new MockColumn(Types.DECIMAL, "DecimalColumn"));
30  		
31  		return meta;
32  	}
33  	
34  	private ArrayList<MockColumn> columns = new ArrayList<MockColumn>();
35  	
36  	public MockResultSetMetaData()
37  	{
38  		
39  	}
40  
41  	public void clear()
42  	{
43  		columns.clear();
44  	}
45  	
46  	public void addColumn(MockColumn c)
47  	{
48  		columns.add(c);
49  	}
50  	
51  	
52  	public int getColumnCount() throws SQLException
53  	{
54  		return columns.size();
55  	}
56  
57  	public boolean isAutoIncrement(int column) throws SQLException
58  	{
59  		return false;
60  	}
61  
62  	public boolean isCaseSensitive(int column) throws SQLException
63  	{
64  		return false;
65  	}
66  
67  	public boolean isSearchable(int column) throws SQLException
68  	{
69  		return false;
70  	}
71  
72  	public boolean isCurrency(int column) throws SQLException
73  	{
74  		return false;
75  	}
76  
77  	public int isNullable(int column) throws SQLException
78  	{
79  		return ResultSetMetaData.columnNoNulls;
80  	}
81  
82  	public boolean isSigned(int column) throws SQLException
83  	{
84  		return false;
85  	}
86  
87  	public MockColumn getColumn(int column)
88  	{
89  		return columns.get(column - 1);
90  		
91  	}
92  	public int getColumnDisplaySize(int column) throws SQLException
93  	{
94  		return getColumn(column).getDisplaySize();
95  	}
96  
97  	public String getColumnLabel(int column) throws SQLException
98  	{
99  		return this.getColumnName(column);
100 	}
101 
102 	public String getColumnName(int column) throws SQLException
103 	{
104 		return getColumn(column).getName();
105 	}
106 
107 	public String getSchemaName(int column) throws SQLException
108 	{
109 		return "SchemaName";
110 	}
111 
112 	public int getPrecision(int column) throws SQLException
113 	{
114 		return 0;
115 	}
116 
117 	public int getScale(int column) throws SQLException
118 	{
119 		return 0;
120 	}
121 
122 	public String getTableName(int column) throws SQLException
123 	{
124 		return "Table" + column;
125 	}
126 
127 	public String getCatalogName(int column) throws SQLException
128 	{
129 		return "Catalog" + column;
130 	}
131 
132 	public int getColumnType(int column) throws SQLException
133 	{
134 		return getColumn(column).getType();
135 	}
136 
137 	public String getColumnTypeName(int column) throws SQLException
138 	{
139 		return "ColumnTypeName" + column;
140 	}
141 
142 	public boolean isReadOnly(int column) throws SQLException
143 	{
144 		return false;
145 	}
146 
147 	public boolean isWritable(int column) throws SQLException
148 	{
149 		return false;
150 	}
151 
152 	public boolean isDefinitelyWritable(int column) throws SQLException
153 	{
154 		return false;
155 	}
156 
157 	public String getColumnClassName(int column) throws SQLException
158 	{
159 		return "ColumnClassName" + column;
160 	}
161 
162 }