下面列出了怎么用java.sql.Ref的API类实例代码及写法,或者点击链接到github查看源代码。
@Test(enabled = true)
public void test09() throws Exception {
Ref ref = new StubRef(sqlType, hero);
Object[] values = {ref};
SQLInputImpl sqli = new SQLInputImpl(values, map);
Ref ref2 = sqli.readRef();
assertTrue(ref.getObject().equals(ref2.getObject()));
assertTrue(ref.getBaseTypeName().equals(ref2.getBaseTypeName()));
}
@Override
public Ref getRef(final String parameterName) throws SQLException {
checkOpen();
try {
return getDelegateCallableStatement().getRef(parameterName);
} catch (final SQLException e) {
handleException(e);
return null;
}
}
@Override
public Ref getRef(final int i) throws SQLException {
try {
return resultSet.getRef(i);
} catch (final SQLException e) {
handleException(e);
return null;
}
}
@Override
public Ref getRef(final String colName) throws SQLException {
try {
return resultSet.getRef(colName);
} catch (final SQLException e) {
handleException(e);
return null;
}
}
@Override
public void updateRef(final int columnIndex, final Ref x) throws SQLException {
try {
resultSet.updateRef(columnIndex, x);
} catch (final SQLException e) {
handleException(e);
}
}
@Override
public void updateRef(final String columnName, final Ref x) throws SQLException {
try {
resultSet.updateRef(columnName, x);
} catch (final SQLException e) {
handleException(e);
}
}
@Test(enabled = true)
public void test07() throws Exception {
Ref ref = new StubRef(sqlType, hero);
outImpl.writeRef(ref);
SerialRef sr = (SerialRef) results.get(0);
assertTrue(hero.equals(sr.getObject()));
}
protected void createDataTypesRows(RowSet crs) throws SQLException {
Integer aInteger = 100;
String aChar = "Oswald Cobblepot";
Long aLong = Long.MAX_VALUE;
Short aShort = Short.MAX_VALUE;
Double aDouble = Double.MAX_VALUE;
BigDecimal aBigDecimal = BigDecimal.ONE;
Boolean aBoolean = false;
Float aFloat = Float.MAX_VALUE;
Byte aByte = Byte.MAX_VALUE;
Date aDate = Date.valueOf(LocalDate.now());
Time aTime = Time.valueOf(LocalTime.now());
Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
Array aArray = new StubArray("INTEGER", new Object[1]);
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
byte[] bytes = new byte[10];
crs.moveToInsertRow();
crs.updateInt(1, aInteger);
crs.updateString(2, aChar);
crs.updateString(3, aChar);
crs.updateLong(4, aLong);
crs.updateBoolean(5, aBoolean);
crs.updateShort(6, aShort);
crs.updateDouble(7, aDouble);
crs.updateBigDecimal(8, aBigDecimal);
crs.updateFloat(9, aFloat);
crs.updateByte(10, aByte);
crs.updateDate(11, aDate);
crs.updateTime(12, aTime);
crs.updateTimestamp(13, aTimeStamp);
crs.updateBytes(14, bytes);
crs.updateArray(15, aArray);
crs.updateRef(16, aRef);
crs.updateDouble(17, aDouble);
crs.insertRow();
crs.moveToCurrentRow();
}
protected void createDataTypesRows(RowSet crs) throws SQLException {
Integer aInteger = 100;
String aChar = "Oswald Cobblepot";
Long aLong = Long.MAX_VALUE;
Short aShort = Short.MAX_VALUE;
Double aDouble = Double.MAX_VALUE;
BigDecimal aBigDecimal = BigDecimal.ONE;
Boolean aBoolean = false;
Float aFloat = Float.MAX_VALUE;
Byte aByte = Byte.MAX_VALUE;
Date aDate = Date.valueOf(LocalDate.now());
Time aTime = Time.valueOf(LocalTime.now());
Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
Array aArray = new StubArray("INTEGER", new Object[1]);
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
byte[] bytes = new byte[10];
crs.moveToInsertRow();
crs.updateInt(1, aInteger);
crs.updateString(2, aChar);
crs.updateString(3, aChar);
crs.updateLong(4, aLong);
crs.updateBoolean(5, aBoolean);
crs.updateShort(6, aShort);
crs.updateDouble(7, aDouble);
crs.updateBigDecimal(8, aBigDecimal);
crs.updateFloat(9, aFloat);
crs.updateByte(10, aByte);
crs.updateDate(11, aDate);
crs.updateTime(12, aTime);
crs.updateTimestamp(13, aTimeStamp);
crs.updateBytes(14, bytes);
crs.updateArray(15, aArray);
crs.updateRef(16, aRef);
crs.updateDouble(17, aDouble);
crs.insertRow();
crs.moveToCurrentRow();
}
@Test(enabled = true)
public void test07() throws Exception {
Ref ref = new StubRef(sqlType, hero);
outImpl.writeRef(ref);
SerialRef sr = (SerialRef) results.get(0);
assertTrue(hero.equals(sr.getObject()));
}
@Override
public void updateRef(int columnIndex, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
/**
* Delegates to {@link ResultSet#getObject(int, Class)} without throwing a {@link AbstractMethodError}.
* <p>
* If the JDBC driver does not implement {@link ResultSet#getObject(int, Class)}, then return 0.
* </p>
*
* @param <T>
* See {@link ResultSet#getObject(int, Class)}
* @param resultSet
* See {@link ResultSet#getObject(int, Class)}
* @param columnIndex
* See {@link ResultSet#getObject(int, Class)}
* @param type
* See {@link ResultSet#getObject(int, Class)}
* @return See {@link ResultSet#getObject(int, Class)}
* @throws SQLException
* See {@link ResultSet#getObject(int, Class)}
* @see ResultSet#getObject(int, Class)
*/
@SuppressWarnings("unchecked")
public static <T> T getObject(final ResultSet resultSet, final int columnIndex, final Class<T> type)
throws SQLException {
try {
return resultSet.getObject(columnIndex, type);
} catch (final AbstractMethodError e) {
if (type == String.class) {
return (T) resultSet.getString(columnIndex);
}
// Numbers
if (type == Integer.class) {
return (T) Integer.valueOf(resultSet.getInt(columnIndex));
}
if (type == Long.class) {
return (T) Long.valueOf(resultSet.getLong(columnIndex));
}
if (type == Double.class) {
return (T) Double.valueOf(resultSet.getDouble(columnIndex));
}
if (type == Float.class) {
return (T) Float.valueOf(resultSet.getFloat(columnIndex));
}
if (type == Short.class) {
return (T) Short.valueOf(resultSet.getShort(columnIndex));
}
if (type == BigDecimal.class) {
return (T) resultSet.getBigDecimal(columnIndex);
}
if (type == Byte.class) {
return (T) Byte.valueOf(resultSet.getByte(columnIndex));
}
// Dates
if (type == Date.class) {
return (T) resultSet.getDate(columnIndex);
}
if (type == Time.class) {
return (T) resultSet.getTime(columnIndex);
}
if (type == Timestamp.class) {
return (T) resultSet.getTimestamp(columnIndex);
}
// Streams
if (type == InputStream.class) {
return (T) resultSet.getBinaryStream(columnIndex);
}
if (type == Reader.class) {
return (T) resultSet.getCharacterStream(columnIndex);
}
// Other
if (type == Object.class) {
return (T) resultSet.getObject(columnIndex);
}
if (type == Boolean.class) {
return (T) Boolean.valueOf(resultSet.getBoolean(columnIndex));
}
if (type == Array.class) {
return (T) resultSet.getArray(columnIndex);
}
if (type == Blob.class) {
return (T) resultSet.getBlob(columnIndex);
}
if (type == Clob.class) {
return (T) resultSet.getClob(columnIndex);
}
if (type == Ref.class) {
return (T) resultSet.getRef(columnIndex);
}
if (type == RowId.class) {
return (T) resultSet.getRowId(columnIndex);
}
if (type == SQLXML.class) {
return (T) resultSet.getSQLXML(columnIndex);
}
if (type == URL.class) {
return (T) resultSet.getURL(columnIndex);
}
throw new SQLFeatureNotSupportedException(
String.format("resultSet=%s, columnIndex=%,d, type=%s", resultSet, Integer.valueOf(columnIndex), type));
}
}
@Override
public void updateRef(int columnIndex, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String columnLabel) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String parameterName) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
// TODO Auto-generated method stub
}
@Override
public Ref getRef(int columnIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String columnLabel) throws SQLException {
// TODO Auto-generated method stub
return null;
}
@Override
public void updateRef(String columnLabel, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void updateRef(String columnLabel, Ref x) throws SQLException {
// TODO Auto-generated method stub
}
public Ref getRef(int columnIndex) throws SQLException {
determineResultSetState();
throw new SQLFeatureNotSupportedException("Data type is not supported");
}
@Override
public Ref getRef(int columnIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(int columnIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRef(int i, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(String columnLabel) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Ref getRef(int columnIndex) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void setRef(int i, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public final void updateRef(final int columnIndex, final Ref x) throws SQLException {
throw new SQLFeatureNotSupportedException("updateXXX");
}
@Override
public void updateRef(int columnIndex, Ref x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public final void setRef(final int parameterIndex, final Ref x) throws SQLException {
throw new SQLFeatureNotSupportedException("setRef");
}