001: package com.mockrunner.gen;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005:
006: import com.mockrunner.gen.proc.JavaLineProcessor;
007:
008: public class JDKVersionGenerator {
009: public static void main(String[] args) throws Exception {
010: VersionGenerator generator = new VersionGenerator(
011: prepareProcessorMapJDK13(), getGeneratorNameJDK13(),
012: getRootTargetDirJDK13(), getRootSourceDir(),
013: getProcessedPackagesJDK13());
014: generator.doSynchronize();
015: generator = new VersionGenerator(prepareProcessorMapJDK14(),
016: getGeneratorNameJDK14(), getRootTargetDirJDK14(),
017: getRootSourceDir(), getProcessedPackagesJDK14());
018: generator.doSynchronize();
019: }
020:
021: private static String getGeneratorNameJDK13() {
022: return "JDBC JDK1.3";
023: }
024:
025: private static String getGeneratorNameJDK14() {
026: return "JDBC JDK1.4";
027: }
028:
029: private static String getRootTargetDirJDK13() {
030: return "srcjdk1.3";
031: }
032:
033: private static String getRootTargetDirJDK14() {
034: return "srcjdk1.4";
035: }
036:
037: private static String getRootSourceDir() {
038: return "src";
039: }
040:
041: private static String[] getProcessedPackagesJDK13() {
042: return new String[] { "com/mockrunner/jdbc",
043: "com/mockrunner/mock/jdbc" };
044: }
045:
046: private static String[] getProcessedPackagesJDK14() {
047: return new String[] { "com/mockrunner/mock/jdbc" };
048: }
049:
050: private static Map prepareProcessorMapJDK13() {
051: Map jdbcFiles = new HashMap();
052:
053: jdbcFiles.putAll(prepareProcessorMapJDK14());
054:
055: JavaLineProcessor mockConnectionProc = getProcessorForClass(
056: "com.mockrunner.mock.jdbc.MockConnection", jdbcFiles);
057: mockConnectionProc.addLine("import java.sql.Savepoint;");
058: mockConnectionProc.addLine("private int holdability;");
059: mockConnectionProc
060: .addLine("holdability = ResultSet.HOLD_CURSORS_OVER_COMMIT;");
061: mockConnectionProc.addBlock("public int getHoldability()");
062: mockConnectionProc
063: .addBlock("public void setHoldability(int holdability)");
064: mockConnectionProc.addBlock("public Savepoint setSavepoint()");
065: mockConnectionProc
066: .addBlock("public Savepoint setSavepoint(String name)");
067: mockConnectionProc
068: .addBlock("public void releaseSavepoint(Savepoint savepoint)");
069: mockConnectionProc
070: .addBlock("public void rollback(Savepoint savepoint)");
071: mockConnectionProc
072: .addBlock("public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)");
073: mockConnectionProc
074: .addBlock("public PreparedStatement prepareStatement(String sql, int[] columnIndexes)");
075: mockConnectionProc
076: .addBlock("public PreparedStatement prepareStatement(String sql, String[] columnNames)");
077: mockConnectionProc
078: .addBlock("private void verifyAutoGeneratedKeysParameter(int autoGeneratedKeys)");
079:
080: JavaLineProcessor mockResultSetProc = getProcessorForClass(
081: "com.mockrunner.mock.jdbc.MockResultSet", jdbcFiles);
082: mockResultSetProc
083: .addLine("private int resultSetHoldability = ResultSet.HOLD_CURSORS_OVER_COMMIT;");
084: mockResultSetProc
085: .addLine("resultSetHoldability = statement.getResultSetHoldability();");
086: mockResultSetProc
087: .addBlock("public void setResultSetHoldability(int resultSetHoldability)");
088: mockResultSetProc.addBlock("public int getHoldability()");
089:
090: JavaLineProcessor mockDatabaseMetadataProc = getProcessorForClass(
091: "com.mockrunner.mock.jdbc.MockDatabaseMetaData",
092: jdbcFiles);
093: mockDatabaseMetadataProc
094: .addLine("private int sqlStateType = sqlStateSQL99;");
095: mockDatabaseMetadataProc
096: .addBlock("public int getSQLStateType()");
097: mockDatabaseMetadataProc
098: .addBlock("public void setSQLStateType(int sqlStateType)");
099:
100: JavaLineProcessor mockPreparedStatementProc = getProcessorForClass(
101: "com.mockrunner.mock.jdbc.MockPreparedStatement",
102: jdbcFiles);
103: mockPreparedStatementProc
104: .addLine("import java.sql.ParameterMetaData;");
105: mockPreparedStatementProc
106: .addLine("private MockParameterMetaData parameterMetaData;");
107: mockPreparedStatementProc
108: .addLine("prepareParameterMetaData();");
109: mockPreparedStatementProc
110: .addLine("prepareParameterMetaData();");
111: mockPreparedStatementProc
112: .addLine("prepareParameterMetaData();");
113: mockPreparedStatementProc
114: .addBlock("private void prepareParameterMetaData()");
115: mockPreparedStatementProc
116: .addBlock("public ParameterMetaData getParameterMetaData()");
117:
118: JavaLineProcessor mockStatementProc = getProcessorForClass(
119: "com.mockrunner.mock.jdbc.MockStatement", jdbcFiles);
120: mockStatementProc
121: .addLine("private int resultSetHoldability = ResultSet.HOLD_CURSORS_OVER_COMMIT;");
122: mockStatementProc.addBlock("try");
123: mockStatementProc.addBlock("catch(SQLException exc)");
124: mockStatementProc.addBlock("try");
125: mockStatementProc.addBlock("catch(SQLException exc)");
126: mockStatementProc
127: .addLine("this.resultSetHoldability = resultSetHoldability;");
128: mockStatementProc
129: .addBlock("public int getResultSetHoldability()");
130: mockStatementProc
131: .addBlock("public int executeUpdate(String sql, int autoGeneratedKeys)");
132: mockStatementProc
133: .addBlock("public int executeUpdate(String sql, int[] columnIndexes)");
134: mockStatementProc
135: .addBlock("public int executeUpdate(String sql, String[] columnNames)");
136: mockStatementProc
137: .addBlock("public boolean execute(String sql, int autoGeneratedKeys)");
138: mockStatementProc
139: .addBlock("public boolean execute(String sql, int[] columnIndexes)");
140: mockStatementProc
141: .addBlock("public boolean execute(String sql, String[] columnNames)");
142: mockStatementProc
143: .addBlock("private void setGeneratedKeysResultSet(String sql, int autoGeneratedKeys)");
144: mockStatementProc
145: .addBlock("public boolean getMoreResults(int current)");
146:
147: JavaLineProcessor jdbcTestCaseAdapterProc = getProcessorForClass(
148: "com.mockrunner.jdbc.JDBCTestCaseAdapter", jdbcFiles);
149: jdbcTestCaseAdapterProc
150: .addLine("import com.mockrunner.mock.jdbc.MockSavepoint;");
151: jdbcTestCaseAdapterProc
152: .addBlock("protected List getSavepoints()");
153: jdbcTestCaseAdapterProc
154: .addBlock("protected MockSavepoint getSavepoint(int index)");
155: jdbcTestCaseAdapterProc
156: .addBlock("protected MockSavepoint getSavepoint(String name)");
157: jdbcTestCaseAdapterProc
158: .addBlock("protected void verifySavepointPresent(int index)");
159: jdbcTestCaseAdapterProc
160: .addBlock("protected void verifySavepointPresent(String name)");
161: jdbcTestCaseAdapterProc
162: .addBlock("protected void verifySavepointReleased(int index)");
163: jdbcTestCaseAdapterProc
164: .addBlock("protected void verifySavepointReleased(String name)");
165: jdbcTestCaseAdapterProc
166: .addBlock("protected void verifySavepointNotReleased(int index)");
167: jdbcTestCaseAdapterProc
168: .addBlock("protected void verifySavepointNotReleased(String name)");
169: jdbcTestCaseAdapterProc
170: .addBlock("protected void verifySavepointRollbacked(int index)");
171: jdbcTestCaseAdapterProc
172: .addBlock("protected void verifySavepointRollbacked(String name)");
173: jdbcTestCaseAdapterProc
174: .addBlock("protected void verifySavepointNotRollbacked(int index)");
175: jdbcTestCaseAdapterProc
176: .addBlock("protected void verifySavepointNotRollbacked(String name)");
177: jdbcTestCaseAdapterProc
178: .addBlock("protected void verifySavepointRolledBack(int index)");
179: jdbcTestCaseAdapterProc
180: .addBlock("protected void verifySavepointRolledBack(String name)");
181: jdbcTestCaseAdapterProc
182: .addBlock("protected void verifySavepointNotRolledBack(int index)");
183: jdbcTestCaseAdapterProc
184: .addBlock("protected void verifySavepointNotRolledBack(String name)");
185: jdbcFiles.put("com.mockrunner.jdbc.BasicJDBCTestCaseAdapter",
186: jdbcTestCaseAdapterProc);
187:
188: JavaLineProcessor jdbcTestModuleProc = getProcessorForClass(
189: "com.mockrunner.jdbc.JDBCTestModule", jdbcFiles);
190: jdbcTestModuleProc
191: .addLine("import com.mockrunner.mock.jdbc.MockSavepoint;");
192: jdbcTestModuleProc.addBlock("public List getSavepoints()");
193: jdbcTestModuleProc
194: .addBlock("public MockSavepoint getSavepoint(int index)");
195: jdbcTestModuleProc
196: .addBlock("public MockSavepoint getSavepoint(String name)");
197: jdbcTestModuleProc
198: .addBlock("public void verifySavepointPresent(int index)");
199: jdbcTestModuleProc
200: .addBlock("public void verifySavepointPresent(String name)");
201: jdbcTestModuleProc
202: .addBlock("public void verifySavepointReleased(int index)");
203: jdbcTestModuleProc
204: .addBlock("public void verifySavepointReleased(String name)");
205: jdbcTestModuleProc
206: .addBlock("public void verifySavepointNotReleased(int index)");
207: jdbcTestModuleProc
208: .addBlock("public void verifySavepointNotReleased(String name)");
209: jdbcTestModuleProc
210: .addBlock("public void verifySavepointRollbacked(int index)");
211: jdbcTestModuleProc
212: .addBlock("public void verifySavepointRollbacked(String name)");
213: jdbcTestModuleProc
214: .addBlock("public void verifySavepointNotRollbacked(int index)");
215: jdbcTestModuleProc
216: .addBlock("public void verifySavepointNotRollbacked(String name)");
217: jdbcTestModuleProc
218: .addBlock("public void verifySavepointRolledBack(int index)");
219: jdbcTestModuleProc
220: .addBlock("public void verifySavepointRolledBack(String name)");
221: jdbcTestModuleProc
222: .addBlock("public void verifySavepointNotRolledBack(int index)");
223: jdbcTestModuleProc
224: .addBlock("public void verifySavepointNotRolledBack(String name)");
225:
226: JavaLineProcessor polyResultSetProc = getProcessorForClass(
227: "com.mockrunner.mock.jdbc.PolyResultSet", jdbcFiles);
228: polyResultSetProc
229: .addBlock("public URL getURL(int columnIndex)");
230: polyResultSetProc
231: .addBlock("public URL getURL(String columnName)");
232: polyResultSetProc
233: .addBlock("public void updateRef(int columnIndex, Ref value)");
234: polyResultSetProc
235: .addBlock("public void updateRef(String columnName, Ref value)");
236: polyResultSetProc
237: .addBlock("public void updateBlob(int columnIndex, Blob value)");
238: polyResultSetProc
239: .addBlock("public void updateBlob(String columnName, Blob value)");
240: polyResultSetProc
241: .addBlock("public void updateClob(int columnIndex, Clob value)");
242: polyResultSetProc
243: .addBlock("public void updateClob(String columnName, Clob value)");
244: polyResultSetProc
245: .addBlock("public void updateArray(int columnIndex, Array value)");
246: polyResultSetProc
247: .addBlock("public void updateArray(String columnName, Array value)");
248:
249: jdbcFiles.put("com.mockrunner.mock.jdbc.MockSavepoint",
250: Boolean.FALSE);
251: jdbcFiles.put("com.mockrunner.mock.jdbc.MockParameterMetaData",
252: Boolean.FALSE);
253:
254: return jdbcFiles;
255: }
256:
257: private static Map prepareProcessorMapJDK14() {
258: Map jdbcFiles = new HashMap();
259:
260: JavaLineProcessor mockConnectionProc = getProcessorForClass(
261: "com.mockrunner.mock.jdbc.MockConnection", jdbcFiles);
262: mockConnectionProc.addLine("import java.sql.NClob;");
263: mockConnectionProc.addLine("import java.sql.SQLXML;");
264: mockConnectionProc.addBlock("public NClob createNClob()");
265: mockConnectionProc.addBlock("public SQLXML createSQLXML()");
266:
267: JavaLineProcessor mockResultSetProc = getProcessorForClass(
268: "com.mockrunner.mock.jdbc.MockResultSet", jdbcFiles);
269: mockResultSetProc.addLine("import java.sql.NClob;");
270: mockResultSetProc.addLine("import java.sql.RowId;");
271: mockResultSetProc.addLine("import java.sql.SQLXML;");
272: mockResultSetProc
273: .addBlock("public NClob getNClob(int columnIndex)");
274: mockResultSetProc
275: .addBlock("public NClob getNClob(String columnName)");
276: mockResultSetProc
277: .addBlock("private NClob getNClobFromClob(Clob clobValue)");
278: mockResultSetProc
279: .addBlock("public void updateNClob(int columnIndex, NClob nClob)");
280: mockResultSetProc
281: .addBlock("public void updateNClob(String columnName, NClob nClob)");
282: mockResultSetProc
283: .addBlock("public void updateNClob(int columnIndex, Reader reader, long length)");
284: mockResultSetProc
285: .addBlock("public void updateNClob(String columnName, Reader reader, long length)");
286: mockResultSetProc
287: .addBlock("public void updateNClob(int columnIndex, Reader reader)");
288: mockResultSetProc
289: .addBlock("public void updateNClob(String columnName, Reader reader)");
290: mockResultSetProc
291: .addBlock("public RowId getRowId(int columnIndex)");
292: mockResultSetProc
293: .addBlock("public RowId getRowId(String columnName)");
294: mockResultSetProc
295: .addBlock("public void updateRowId(int columnIndex, RowId rowId)");
296: mockResultSetProc
297: .addBlock("public void updateRowId(String columnName, RowId rowId)");
298: mockResultSetProc
299: .addBlock("public SQLXML getSQLXML(int columnIndex)");
300: mockResultSetProc
301: .addBlock("public SQLXML getSQLXML(String columnName)");
302: mockResultSetProc
303: .addBlock("public void updateSQLXML(int columnIndex, SQLXML xmlObject)");
304: mockResultSetProc
305: .addBlock("public void updateSQLXML(String columnName, SQLXML xmlObject)");
306:
307: JavaLineProcessor mockPreparedStatementProc = getProcessorForClass(
308: "com.mockrunner.mock.jdbc.MockPreparedStatement",
309: jdbcFiles);
310: mockPreparedStatementProc.addLine("import java.sql.NClob;");
311: mockPreparedStatementProc.addLine("import java.sql.RowId;");
312: mockPreparedStatementProc.addLine("import java.sql.SQLXML;");
313: mockPreparedStatementProc
314: .addBlock("public void setNClob(int parameterIndex, NClob nClob)");
315: mockPreparedStatementProc
316: .addBlock("public void setNClob(int parameterIndex, Reader reader)");
317: mockPreparedStatementProc
318: .addBlock("public void setNClob(int parameterIndex, Reader reader, long length)");
319: mockPreparedStatementProc
320: .addBlock("public void setRowId(int parameterIndex, RowId rowId)");
321: mockPreparedStatementProc
322: .addBlock("public void setSQLXML(int parameterIndex, SQLXML xmlObject)");
323:
324: JavaLineProcessor mockCallableStatementProc = getProcessorForClass(
325: "com.mockrunner.mock.jdbc.MockCallableStatement",
326: jdbcFiles);
327: mockCallableStatementProc.addLine("import java.sql.NClob;");
328: mockCallableStatementProc.addLine("import java.sql.RowId;");
329: mockCallableStatementProc.addLine("import java.sql.SQLXML;");
330: mockCallableStatementProc
331: .addBlock("public NClob getNClob(int parameterIndex)");
332: mockCallableStatementProc
333: .addBlock("public SQLXML getSQLXML(int parameterIndex)");
334: mockCallableStatementProc
335: .addBlock("public RowId getRowId(int parameterIndex)");
336: mockCallableStatementProc
337: .addBlock("public NClob getNClob(String parameterName)");
338: mockCallableStatementProc
339: .addBlock("public SQLXML getSQLXML(String parameterName)");
340: mockCallableStatementProc
341: .addBlock("public RowId getRowId(String parameterName)");
342: mockCallableStatementProc
343: .addBlock("public void setNClob(String parameterName, NClob nClob)");
344: mockCallableStatementProc
345: .addBlock("public void setNClob(String parameterName, Reader reader)");
346: mockCallableStatementProc
347: .addBlock("public void setNClob(String parameterName, Reader reader, long length)");
348: mockCallableStatementProc
349: .addBlock("public void setSQLXML(String parameterName, SQLXML xmlObject)");
350: mockCallableStatementProc
351: .addBlock("public void setRowId(String parameterName, RowId rowId)");
352: mockCallableStatementProc
353: .addBlock("private NClob getNClobFromClob(Clob clobValue)");
354:
355: JavaLineProcessor mockDatabaseMetadataProc = getProcessorForClass(
356: "com.mockrunner.mock.jdbc.MockDatabaseMetaData",
357: jdbcFiles);
358: mockDatabaseMetadataProc
359: .addLine("import java.sql.RowIdLifetime;");
360: mockDatabaseMetadataProc
361: .addLine("private RowIdLifetime rowIdLifetime = RowIdLifetime.ROWID_VALID_TRANSACTION;");
362: mockDatabaseMetadataProc
363: .addBlock("public RowIdLifetime getRowIdLifetime()");
364: mockDatabaseMetadataProc
365: .addBlock("public void setRowIdLifetime(RowIdLifetime rowIdLifetime)");
366:
367: JavaLineProcessor polyResultSetProc = getProcessorForClass(
368: "com.mockrunner.mock.jdbc.PolyResultSet", jdbcFiles);
369: polyResultSetProc.addLine("import java.sql.NClob;");
370: polyResultSetProc.addLine("import java.sql.RowId;");
371: polyResultSetProc.addLine("import java.sql.SQLXML;");
372: polyResultSetProc
373: .addBlock("public String getNString(int columnIndex)");
374: polyResultSetProc
375: .addBlock("public RowId getRowId(int columnIndex)");
376: polyResultSetProc
377: .addBlock("public NClob getNClob(int columnIndex)");
378: polyResultSetProc
379: .addBlock("public SQLXML getSQLXML(int columnIndex)");
380: polyResultSetProc
381: .addBlock("public RowId getRowId(String columnName)");
382: polyResultSetProc
383: .addBlock("public NClob getNClob(String columnName)");
384: polyResultSetProc
385: .addBlock("public SQLXML getSQLXML(String columnName)");
386: polyResultSetProc.addBlock("public int getHoldability()");
387: polyResultSetProc
388: .addBlock("public void updateRowId(int columnIndex, RowId x)");
389: polyResultSetProc
390: .addBlock("public void updateNClob(int columnIndex, NClob nClob)");
391: polyResultSetProc
392: .addBlock("public void updateSQLXML(int columnIndex, SQLXML xmlObject)");
393: polyResultSetProc
394: .addBlock("public void updateRowId(String columnName, RowId value)");
395: polyResultSetProc
396: .addBlock("public void updateNClob(String columnName, NClob nClob)");
397: polyResultSetProc
398: .addBlock("public void updateSQLXML(String columnName, SQLXML xmlObject)");
399:
400: jdbcFiles.put("com.mockrunner.mock.jdbc.MockSQLXML",
401: Boolean.FALSE);
402: jdbcFiles.put("com.mockrunner.mock.jdbc.MockNClob",
403: Boolean.FALSE);
404: jdbcFiles.put("com.mockrunner.mock.jdbc.MockRowId",
405: Boolean.FALSE);
406:
407: return jdbcFiles;
408: }
409:
410: private static JavaLineProcessor getProcessorForClass(
411: String className, Map jdbcFiles) {
412: JavaLineProcessor processor = (JavaLineProcessor) jdbcFiles
413: .get(className);
414: if (null == processor) {
415: processor = new JavaLineProcessor();
416: jdbcFiles.put(className, processor);
417: }
418: return processor;
419: }
420: }
|