From c74fdd98eb2165729081d286737db8e8929dbcb7 Mon Sep 17 00:00:00 2001 From: wenshao Date: Sat, 14 May 2011 04:06:02 +0000 Subject: [PATCH] git-svn-id: http://code.alibabatech.com/svn/druid/trunk@67 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../com/alibaba/druid/mock/MockResultSet.java | 14 +- .../druid/mock/MockResultSetMetaData.java | 238 ++++++++++++++++-- 2 files changed, 225 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index 4ef5b0aa9b..e6b0c9ae72 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -36,16 +36,19 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Calendar; +import java.util.HashMap; import java.util.List; import java.util.Map; public class MockResultSet implements ResultSet { - private int rowIndex = -1; - private Statement statement; - private List rows = new ArrayList(); + private int rowIndex = -1; + private Statement statement; + private List rows = new ArrayList(); - private boolean wasNull = false; + private boolean wasNull = false; + + private MockResultSetMetaData metaData = new MockResultSetMetaData(); public MockResultSet(Statement statement){ super(); @@ -235,7 +238,6 @@ public class MockResultSet implements ResultSet { @Override public int getInt(String columnLabel) throws SQLException { - return 0; } @@ -324,7 +326,7 @@ public class MockResultSet implements ResultSet { @Override public ResultSetMetaData getMetaData() throws SQLException { - return new MockResultSetMetaData(); + return metaData; } @Override diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSetMetaData.java b/src/main/java/com/alibaba/druid/mock/MockResultSetMetaData.java index 7a4d509112..70b6334096 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSetMetaData.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSetMetaData.java @@ -17,9 +17,21 @@ package com.alibaba.druid.mock; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class MockResultSetMetaData implements ResultSetMetaData { + public MockResultSetMetaData(){ + + } + + private final List columns = new ArrayList(); + + public List getColumns() { + return columns; + } + @Override public T unwrap(Class iface) throws SQLException { return null; @@ -32,107 +44,291 @@ public class MockResultSetMetaData implements ResultSetMetaData { @Override public int getColumnCount() throws SQLException { - return 0; + return columns.size(); } @Override public boolean isAutoIncrement(int column) throws SQLException { - return false; + return columns.get(column - 1).isAutoIncrement(); } @Override public boolean isCaseSensitive(int column) throws SQLException { - return false; + return columns.get(column - 1).isCaseSensitive(); } @Override public boolean isSearchable(int column) throws SQLException { - return false; + return columns.get(column - 1).isSearchable(); } @Override public boolean isCurrency(int column) throws SQLException { - return false; + return columns.get(column - 1).isCurrency(); } @Override public int isNullable(int column) throws SQLException { - return 0; + return columns.get(column - 1).getNullable(); } @Override public boolean isSigned(int column) throws SQLException { - return false; + return columns.get(column - 1).isSigned(); } @Override public int getColumnDisplaySize(int column) throws SQLException { - return 0; + return columns.get(column - 1).getColumnDisplaySize(); } @Override public String getColumnLabel(int column) throws SQLException { - return null; + return columns.get(column - 1).getColumnLabel(); } @Override public String getColumnName(int column) throws SQLException { - return null; + return columns.get(column - 1).getColumnName(); } @Override public String getSchemaName(int column) throws SQLException { - return null; + return columns.get(column - 1).getSchemaName(); } @Override public int getPrecision(int column) throws SQLException { - return 0; + return columns.get(column - 1).getPrecision(); } @Override public int getScale(int column) throws SQLException { - return 0; + return columns.get(column - 1).getScale(); } @Override public String getTableName(int column) throws SQLException { - return null; + return columns.get(column - 1).getTableName(); } @Override public String getCatalogName(int column) throws SQLException { - return null; + return columns.get(column - 1).getCatalogName(); } @Override public int getColumnType(int column) throws SQLException { - return 0; + return columns.get(column - 1).getColumnType(); } @Override public String getColumnTypeName(int column) throws SQLException { - return null; + return columns.get(column - 1).getColumnTypeName(); } @Override public boolean isReadOnly(int column) throws SQLException { - return false; + return columns.get(column - 1).isReadOnly(); } @Override public boolean isWritable(int column) throws SQLException { - return false; + return columns.get(column - 1).isWritable(); } @Override public boolean isDefinitelyWritable(int column) throws SQLException { - return false; + return columns.get(column - 1).isDefinitelyWritable(); } @Override public String getColumnClassName(int column) throws SQLException { - return null; + return columns.get(column - 1).getColumnClassName(); } + public static class ColumnMetaData { + + private boolean autoIncrement = false; + private boolean caseSensitive; + private boolean searchable; + private boolean currency; + private int nullable = 0; + private boolean signed; + private int columnDisplaySize; + private String columnLabel; + private String columnName; + private String schemaName; + private int precision; + private int scale; + private String tableName; + private String catalogName; + private int columnType; + private String columnTypeName; + private boolean readOnly; + private boolean writable; + private boolean definitelyWritable; + private String columnClassName; + + public boolean isAutoIncrement() { + return autoIncrement; + } + + public void setAutoIncrement(boolean autoIncrement) { + this.autoIncrement = autoIncrement; + } + + public boolean isCaseSensitive() { + return caseSensitive; + } + + public void setCaseSensitive(boolean caseSensitive) { + this.caseSensitive = caseSensitive; + } + + public boolean isSearchable() { + return searchable; + } + + public void setSearchable(boolean searchable) { + this.searchable = searchable; + } + + public boolean isCurrency() { + return currency; + } + + public void setCurrency(boolean currency) { + this.currency = currency; + } + + public int getNullable() { + return nullable; + } + + public void setNullable(int nullable) { + this.nullable = nullable; + } + + public boolean isSigned() { + return signed; + } + + public void setSigned(boolean signed) { + this.signed = signed; + } + + public int getColumnDisplaySize() { + return columnDisplaySize; + } + + public void setColumnDisplaySize(int columnDisplaySize) { + this.columnDisplaySize = columnDisplaySize; + } + + public String getColumnLabel() { + return columnLabel; + } + + public void setColumnLabel(String columnLabel) { + this.columnLabel = columnLabel; + } + + public String getColumnName() { + return columnName; + } + + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + public String getSchemaName() { + return schemaName; + } + + public void setSchemaName(String schemaName) { + this.schemaName = schemaName; + } + + public int getPrecision() { + return precision; + } + + public void setPrecision(int precision) { + this.precision = precision; + } + + public int getScale() { + return scale; + } + + public void setScale(int scale) { + this.scale = scale; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getCatalogName() { + return catalogName; + } + + public void setCatalogName(String catalogName) { + this.catalogName = catalogName; + } + + public int getColumnType() { + return columnType; + } + + public void setColumnType(int columnType) { + this.columnType = columnType; + } + + public String getColumnTypeName() { + return columnTypeName; + } + + public void setColumnTypeName(String columnTypeName) { + this.columnTypeName = columnTypeName; + } + + public boolean isReadOnly() { + return readOnly; + } + + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + + public boolean isWritable() { + return writable; + } + + public void setWritable(boolean writable) { + this.writable = writable; + } + + public boolean isDefinitelyWritable() { + return definitelyWritable; + } + + public void setDefinitelyWritable(boolean definitelyWritable) { + this.definitelyWritable = definitelyWritable; + } + + public String getColumnClassName() { + return columnClassName; + } + + public void setColumnClassName(String columnClassName) { + this.columnClassName = columnClassName; + } + + } }