You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/04/24 13:08:54 UTC
svn commit: r531879 - in /harmony/enhanced/classlib/trunk/modules/sql/src:
main/java/javax/sql/rowset/RowSetMetaDataImpl.java
test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
Author: tellison
Date: Tue Apr 24 04:08:53 2007
New Revision: 531879
URL: http://svn.apache.org/viewvc?view=rev&rev=531879
Log:
Apply patch HARMONY-3740 ([classlib][sql] 11 new methods in RowSetMetaDataImpl)
Modified:
harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java?view=diff&rev=531879&r1=531878&r2=531879
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/RowSetMetaDataImpl.java Tue Apr 24 04:08:53 2007
@@ -35,6 +35,8 @@
*/
public class RowSetMetaDataImpl implements RowSetMetaData, Serializable {
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
private static final int DEFAULT_COLUMN_COUNT = 4;
private static final long serialVersionUID = 6893806403181801867L;
@@ -102,23 +104,44 @@
colInfo[arrayIndex].caseSensitive = property;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.sql.RowSetMetaData#setSearchable(int, boolean)
+ */
public void setSearchable(int columnIndex, boolean property)
throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ colInfo[arrayIndex].searchable = property;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.sql.RowSetMetaData#setCurrency(int, boolean)
+ */
public void setCurrency(int columnIndex, boolean property)
throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ colInfo[arrayIndex].currency = property;
}
public void setNullable(int columnIndex, int property) throws SQLException {
throw new NotImplementedException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.sql.RowSetMetaData#setSigned(int, boolean)
+ */
public void setSigned(int columnIndex, boolean property)
throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ colInfo[arrayIndex].signed = property;
}
public void setColumnDisplaySize(int columnIndex, int size)
@@ -126,9 +149,16 @@
throw new NotImplementedException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see javax.sql.RowSetMetaData#setColumnLabel(int, String)
+ */
public void setColumnLabel(int columnIndex, String label)
throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ colInfo[arrayIndex].columnLabel = label == null ? EMPTY_STRING : label;
}
public void setColumnName(int columnIndex, String columnName)
@@ -200,28 +230,56 @@
return colInfo[arrayIndex].caseSensitive;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isSearchable(int)
+ */
public boolean isSearchable(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].searchable;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isCurrency(int)
+ */
public boolean isCurrency(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].currency;
}
public int isNullable(int columnIndex) throws SQLException {
throw new NotImplementedException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isSigned(int)
+ */
public boolean isSigned(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].signed;
}
public int getColumnDisplaySize(int columnIndex) throws SQLException {
throw new NotImplementedException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#getColumnLabel(int)
+ */
public String getColumnLabel(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].columnLabel;
}
public String getColumnName(int columnIndex) throws SQLException {
@@ -256,16 +314,35 @@
throw new NotImplementedException();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isReadOnly(int)
+ */
public boolean isReadOnly(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ return !isWritable(columnIndex);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isWritable(int)
+ */
public boolean isWritable(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].writeable;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.sql.ResultSetMetaData#isDefinitelyWritable(int)
+ */
public boolean isDefinitelyWritable(int columnIndex) throws SQLException {
- throw new NotImplementedException();
+ int arrayIndex = columnIndex - 1;
+ checkColumnIndex(arrayIndex);
+ return colInfo[arrayIndex].definiteWritable;
}
public String getColumnClassName(int columnIndex) throws SQLException {
@@ -280,6 +357,17 @@
public boolean autoIncrement;
public boolean caseSensitive;
+
+ public boolean currency;
+
+ public boolean signed;
+
+ public boolean searchable;
+ public boolean writeable = true;
+
+ public boolean definiteWritable = true;
+
+ public String columnLabel;
}
}
Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java?view=diff&rev=531879&r1=531878&r2=531879
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/RowSetMetaDataImplTest.java Tue Apr 24 04:08:53 2007
@@ -69,6 +69,38 @@
metaDataImpl.setColumnCount(18);
assertEquals(18, metaDataImpl.getColumnCount());
+ metaDataImpl.setAutoIncrement(1, true);
+ assertTrue(metaDataImpl.isAutoIncrement(1));
+ // original records have been overwritten
+ metaDataImpl.setColumnCount(19);
+ assertEquals(19, metaDataImpl.getColumnCount());
+ assertFalse(metaDataImpl.isAutoIncrement(1));
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#getColumnLabel(int)
+ */
+ public void test_getColumnLabelI() throws SQLException {
+ try {
+ metaDataImpl.getColumnLabel(1);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(3);
+ assertNull(metaDataImpl.getColumnLabel(1));
+ metaDataImpl.setColumnLabel(1, null);
+ assertEquals("", metaDataImpl.getColumnLabel(1));
+ metaDataImpl.setColumnLabel(1, "err");
+ assertEquals("err", metaDataImpl.getColumnLabel(1));
+
+ try {
+ metaDataImpl.getColumnLabel(11);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
}
/**
@@ -132,6 +164,145 @@
}
/**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isCurrency(int)}
+ */
+ public void test_isCurrencyI() throws SQLException {
+ try {
+ metaDataImpl.isCurrency(1);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(5);
+ assertFalse(metaDataImpl.isCurrency(1));
+ metaDataImpl.setCurrency(1, true);
+ assertTrue(metaDataImpl.isCurrency(1));
+ metaDataImpl.setCurrency(1, true);
+ assertTrue(metaDataImpl.isCurrency(1));
+
+ try {
+ metaDataImpl.isCurrency(0);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(6);
+ assertFalse(metaDataImpl.isCurrency(1));
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isReadOnly(int)}
+ */
+ public void test_isReadOnlyI() throws SQLException {
+ try {
+ metaDataImpl.isReadOnly(1);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(11);
+ assertFalse(metaDataImpl.isReadOnly(1));
+ assertFalse(metaDataImpl.isReadOnly(11));
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isWritable(int)}
+ */
+ public void test_isWritableI() throws SQLException {
+ try {
+ metaDataImpl.isWritable(3);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(3);
+ assertTrue(metaDataImpl.isWritable(1));
+
+ assertTrue(metaDataImpl.isWritable(3));
+ assertFalse(metaDataImpl.isReadOnly(3));
+
+ try {
+ metaDataImpl.isWritable(4);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isDefinitelyWritable(int)}
+ */
+ public void test_isDefinitelyWritableI() throws SQLException {
+ metaDataImpl.setColumnCount(2);
+ assertTrue(metaDataImpl.isDefinitelyWritable(1));
+ assertTrue(metaDataImpl.isDefinitelyWritable(2));
+
+ // RI fails here, which does not comply to the spec
+ try {
+ metaDataImpl.isDefinitelyWritable(-1);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isSearchable(int)}
+ */
+ public void test_isSearchableI() throws SQLException {
+ try {
+ metaDataImpl.isSearchable(Integer.MAX_VALUE);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(1);
+ assertFalse(metaDataImpl.isSearchable(1));
+ metaDataImpl.setSearchable(1, true);
+ assertTrue(metaDataImpl.isSearchable(1));
+ metaDataImpl.setSearchable(1, false);
+ assertFalse(metaDataImpl.isSearchable(1));
+
+ try {
+ metaDataImpl.isSearchable(2);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#isSigned(int)}
+ */
+ public void test_isSignedI() throws SQLException {
+ try {
+ metaDataImpl.isSigned(2);
+ fail("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(35);
+ assertFalse(metaDataImpl.isSigned(35));
+ metaDataImpl.setSigned(35, true);
+ assertTrue(metaDataImpl.isSigned(35));
+ metaDataImpl.setSigned(35, false);
+ assertFalse(metaDataImpl.isSigned(35));
+
+ try {
+ metaDataImpl.isSigned(36);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
* @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setAutoIncrement(int, boolean)}
*/
public void test_setAutoIncrementIZ() throws SQLException {
@@ -179,6 +350,108 @@
try {
metaDataImpl.setCaseSensitive(10, true);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setColumnLabel(int, String)}
+ */
+ public void test_setColumnLabelIZ() throws SQLException {
+ try {
+ metaDataImpl.setColumnLabel(1, null);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(3);
+ assertNull(metaDataImpl.getColumnLabel(3));
+ metaDataImpl.setColumnLabel(3, null);
+ assertEquals("", metaDataImpl.getColumnLabel(3));
+
+ try {
+ metaDataImpl.setColumnLabel(4, "exception");
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setCurrency(int, boolean)}
+ */
+ public void test_setCurrencyIZ() throws SQLException {
+ try {
+ metaDataImpl.setCurrency(12, false);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(7);
+ assertFalse(metaDataImpl.isCurrency(4));
+ metaDataImpl.setCurrency(4, false);
+ assertFalse(metaDataImpl.isCurrency(4));
+ metaDataImpl.setCurrency(4, true);
+ assertTrue(metaDataImpl.isCurrency(4));
+
+ try {
+ metaDataImpl.setCurrency(8, true);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setSearchable(int, boolean)}
+ */
+ public void test_setSearchableIZ() throws SQLException {
+ try {
+ metaDataImpl.setSearchable(-22, true);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(8);
+ assertFalse(metaDataImpl.isSearchable(2));
+ metaDataImpl.setSearchable(2, true);
+ assertTrue(metaDataImpl.isSearchable(2));
+ metaDataImpl.setSearchable(2, false);
+ assertFalse(metaDataImpl.isSearchable(2));
+
+ try {
+ metaDataImpl.setSearchable(Integer.MIN_VALUE, true);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests {@link javax.sql.rowset.RowSetMetaDataImpl#setSigned(int, boolean)}
+ */
+ public void test_setSignedIZ() throws SQLException {
+ try {
+ metaDataImpl.setSigned(34, true);
+ fail ("should throw SQLException");
+ } catch (SQLException e) {
+ // expected
+ }
+
+ metaDataImpl.setColumnCount(12);
+ assertFalse(metaDataImpl.isSigned(12));
+ metaDataImpl.setSigned(12, true);
+ assertTrue(metaDataImpl.isSigned(12));
+ metaDataImpl.setSigned(12, false);
+ assertFalse(metaDataImpl.isSigned(12));
+
+ try {
+ metaDataImpl.setSigned(0, true);
fail ("should throw SQLException");
} catch (SQLException e) {
// expected