提交 7ad78c92 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

Add implementation for methods "isWrapperFor()" and "unwrap()" in JdbcDatabaseMetaData,

JdbcParameterMetaData,JdbcResultSet,JdbcResultSetMetaData,JdbcStatement
上级 7a49d6f2
...@@ -13,6 +13,7 @@ import java.sql.RowIdLifetime; ...@@ -13,6 +13,7 @@ import java.sql.RowIdLifetime;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
...@@ -3072,19 +3073,29 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -3072,19 +3073,29 @@ public class JdbcDatabaseMetaData extends TraceObject implements
} }
/** /**
* [Not supported] Return an object of this class if possible. * Return an object of this class if possible.
*
* @param iface the class
* @return this
*/ */
@Override @Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap"); if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} }
/** /**
* [Not supported] Checks if unwrap can return an object of this class. * Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/ */
@Override @Override
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor"); return iface != null && iface.isAssignableFrom(getClass());
} }
/** /**
......
...@@ -219,19 +219,29 @@ public class JdbcParameterMetaData extends TraceObject implements ...@@ -219,19 +219,29 @@ public class JdbcParameterMetaData extends TraceObject implements
} }
/** /**
* [Not supported] Return an object of this class if possible. * Return an object of this class if possible.
*
* @param iface the class
* @return this
*/ */
@Override @Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap"); if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} }
/** /**
* [Not supported] Checks if unwrap can return an object of this class. * Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/ */
@Override @Override
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor"); return iface != null && iface.isAssignableFrom(getClass());
} }
/** /**
......
...@@ -27,7 +27,6 @@ import java.sql.Timestamp; ...@@ -27,7 +27,6 @@ import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
...@@ -3646,19 +3645,29 @@ public class JdbcResultSet extends TraceObject implements ResultSet { ...@@ -3646,19 +3645,29 @@ public class JdbcResultSet extends TraceObject implements ResultSet {
} }
/** /**
* [Not supported] Return an object of this class if possible. * Return an object of this class if possible.
*
* @param iface the class
* @return this
*/ */
@Override @Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap"); if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} }
/** /**
* [Not supported] Checks if unwrap can return an object of this class. * Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/ */
@Override @Override
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor"); return iface != null && iface.isAssignableFrom(getClass());
} }
/** /**
......
...@@ -7,7 +7,6 @@ package org.h2.jdbc; ...@@ -7,7 +7,6 @@ package org.h2.jdbc;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.Trace; import org.h2.message.Trace;
import org.h2.message.TraceObject; import org.h2.message.TraceObject;
...@@ -450,19 +449,29 @@ public class JdbcResultSetMetaData extends TraceObject implements ...@@ -450,19 +449,29 @@ public class JdbcResultSetMetaData extends TraceObject implements
} }
/** /**
* [Not supported] Return an object of this class if possible. * Return an object of this class if possible.
*
* @param iface the class
* @return this
*/ */
@Override @Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap"); if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} }
/** /**
* [Not supported] Checks if unwrap can return an object of this class. * Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/ */
@Override @Override
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor"); return iface != null && iface.isAssignableFrom(getClass());
} }
/** /**
......
...@@ -11,7 +11,6 @@ import java.sql.SQLException; ...@@ -11,7 +11,6 @@ import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.engine.SessionInterface; import org.h2.engine.SessionInterface;
...@@ -1060,19 +1059,29 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -1060,19 +1059,29 @@ public class JdbcStatement extends TraceObject implements Statement {
} }
/** /**
* [Not supported] Return an object of this class if possible. * Return an object of this class if possible.
*
* @param iface the class
* @return this
*/ */
@Override @Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException { public <T> T unwrap(Class<T> iface) throws SQLException {
throw unsupported("unwrap"); if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} }
/** /**
* [Not supported] Checks if unwrap can return an object of this class. * Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/ */
@Override @Override
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw unsupported("isWrapperFor"); return iface != null && iface.isAssignableFrom(getClass());
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论