下面列出了怎么用java.sql.SQLFeatureNotSupportedException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Test Autogenerated key.
*
* @throws Throwable if any error occurs
*/
@Test
public void testAutogenerateKey() throws Throwable
{
try (Connection connection = getConnection())
{
Statement statement = connection.createStatement();
statement.execute("create or replace table t(c1 int)");
statement.execute("insert into t values(1)", Statement.NO_GENERATED_KEYS);
try
{
statement.execute("insert into t values(2)", Statement.RETURN_GENERATED_KEYS);
fail("no autogenerate key is supported");
}
catch (SQLFeatureNotSupportedException ex)
{
// nop
}
// empty result
ResultSet rset = statement.getGeneratedKeys();
assertFalse(rset.next());
rset.close();
}
}
/**
* Get expression that may be used to evaluate the tenant ID of a given row in a
* multi-tenant table. Both the SYSTEM.CATALOG table and the SYSTEM.SEQUENCE
* table are considered multi-tenant.
* @param conn open Phoenix connection
* @param fullTableName full table name
* @return An expression that may be evaluated for a row in the provided table or
* null if the table is not a multi-tenant table.
* @throws SQLException if the table name is not found, a TableNotFoundException
* is thrown. If a multi-tenant local index is supplied a SQLFeatureNotSupportedException
* is thrown.
*/
public static Expression getTenantIdExpression(Connection conn, String fullTableName) throws SQLException {
PTable table = getTable(conn, fullTableName);
// TODO: consider setting MULTI_TENANT = true for SYSTEM.CATALOG and SYSTEM.SEQUENCE
if (!SchemaUtil.isMetaTable(table) && !SchemaUtil.isSequenceTable(table) && !table.isMultiTenant()) {
return null;
}
if (table.getIndexType() == IndexType.LOCAL) {
/*
* With some hackery, we could deduce the tenant ID from a multi-tenant local index,
* however it's not clear that we'd want to maintain the same prefixing of the region
* start key, as the region boundaries may end up being different on a cluster being
* replicated/backed-up to (which is the use case driving the method).
*/
throw new SQLFeatureNotSupportedException();
}
int pkPosition = table.getBucketNum() == null ? 0 : 1;
List<PColumn> pkColumns = table.getPKColumns();
return new RowKeyColumnExpression(pkColumns.get(pkPosition), new RowKeyValueAccessor(pkColumns, pkPosition));
}
@Override
public boolean ownUpdatesAreVisible(int type) throws SQLException {
throwIfClosed();
try {
return super.ownUpdatesAreVisible(type);
}
catch (RuntimeException e) {
if ("todo: implement this method".equals(e.getMessage())) {
throw new SQLFeatureNotSupportedException(
"ownUpdatesAreVisible(int) is not supported", e);
}
else {
throw new SQLException(e.getMessage(), e);
}
}
}
@Test
public void idsQueryMultipleId() throws SqlParseException, SQLFeatureNotSupportedException {
String query = String.format("select * from %s/dog where _id = IDS_QUERY(dog,1,2,3)",TEST_INDEX_DOG);
SearchHit[] hits = query(query).getHits();
Assert.assertEquals(1,hits.length);
Map<String, Object> hitAsMap = hits[0].getSourceAsMap();
Assert.assertEquals("rex",hitAsMap.get("dog_name"));
Assert.assertEquals("Daenerys",hitAsMap.get("holdersName"));
Assert.assertEquals(2, hitAsMap.get("age"));
}
public void testUpdateNClobStringLengthlessNotImplemented()
throws SQLException {
try {
rs.updateNClob("some-column-name", (Reader)null);
fail("ResultSet.updateNClob(String, Reader) " +
"should not be implemented");
} catch (SQLFeatureNotSupportedException sfnse) {
// We are fine, do nothing.
}
}
@Test
public void testupdateNClob70() {
try {
rs.updateNClob(1, (java.sql.NClob) null);
} catch (SQLFeatureNotSupportedException sqle) {
Assert.fail();
} catch (SQLException sqlee) {
// eat
}
}
@Test
public void testupdateAsciiStream33() {
try {
rs.updateAsciiStream("a", null);
} catch (SQLFeatureNotSupportedException sqle) {
Assert.fail();
} catch (SQLException sqlee) {
// eat
}
}
@Override
public void updateRowId(int columnIndex, RowId x) throws SQLException
{
logger.debug(
"public void updateRowId(int columnIndex, RowId x)");
throw new SQLFeatureNotSupportedException();
}
@Override
public void updateByte( int columnIndex, byte x ) throws SQLException {
throwIfClosed();
try {
super.updateByte( columnIndex, x );
}
catch (UnsupportedOperationException e) {
throw new SQLFeatureNotSupportedException(e.getMessage(), e);
}
}
@Override
@Deprecated
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException
{
throw new SQLFeatureNotSupportedException();
}
public void testGetNClobStringNotImplemented()
throws SQLException {
try {
rs.getNClob("some-column-name");
fail("ResultSet.getNClob(String) " +
"should not be implemented");
} catch (SQLFeatureNotSupportedException sfnse) {
// We are fine, do nothing.
}
}
@Override
public boolean previous() throws SQLException
{
logger.debug("public boolean previous()");
throw new SQLFeatureNotSupportedException();
}
public void testUpdateNClobStringNotImplemented()
throws SQLException {
try {
rs.updateNClob("some-column-name", (NClob)null);
fail("ResultSet.updateNClob(String, NClob) " +
"should not be implemented");
} catch (SQLFeatureNotSupportedException sfnse) {
// We are fine, do nothing.
}
}
/**
* Create SQLFeatureNotSupportedException with message, SQLState, errorCode, and Throwable
*/
@Test
public void test5() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state, errorCode, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == errorCode);
}
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
if (ex instanceof SQLTransientException) {
if (ex instanceof SQLTransientConnectionException) {
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLTransactionRollbackException) {
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLTimeoutException) {
return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
}
}
else if (ex instanceof SQLNonTransientException) {
if (ex instanceof SQLNonTransientConnectionException) {
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLDataException) {
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLIntegrityConstraintViolationException) {
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLInvalidAuthorizationSpecException) {
return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLSyntaxErrorException) {
return new BadSqlGrammarException(task, sql, ex);
}
else if (ex instanceof SQLFeatureNotSupportedException) {
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
}
}
else if (ex instanceof SQLRecoverableException) {
return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);
}
// Fallback to Spring's own SQL state translation...
return null;
}
/**
* Create SQLFeatureNotSupportedException with message, SQLState, and Throwable
*/
@Test
public void test6() {
SQLFeatureNotSupportedException ex =
new SQLFeatureNotSupportedException(reason, state, t);
assertTrue(ex.getMessage().equals(reason)
&& ex.getSQLState().equals(state)
&& cause.equals(ex.getCause().toString())
&& ex.getErrorCode() == 0);
}
@Test
public void twoSubQueriesTest() throws SqlParseException, SQLFeatureNotSupportedException {
String query = String.format("select * from %s/dog where holdersName IN (select firstname from %s/account where firstname = 'Hattie') and age IN (select name.ofHisName from %s/gotCharacters where name.firstname <> 'Daenerys' and name.ofHisName IS NOT NULL) ",TEST_INDEX_DOG,TEST_INDEX_ACCOUNT,TEST_INDEX_GAME_OF_THRONES);
SearchHit[] hits = query(query).getHits();
Assert.assertEquals(1,hits.length);
Map<String, Object> hitAsMap = hits[0].getSourceAsMap();
Assert.assertEquals("snoopy",hitAsMap.get("dog_name"));
Assert.assertEquals("Hattie",hitAsMap.get("holdersName"));
Assert.assertEquals(4,hitAsMap.get("age"));
}
@Override
public void setFetchDirection(final int direction) throws SQLException {
throw new SQLFeatureNotSupportedException("setFetchDirection");
}
public String getColumnClassName(int column) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new SQLFeatureNotSupportedException(Utils.getLoggingInfo());
}
@Override
public void updateBigDecimal(int columnIndex, BigDecimal x)
throws SQLException
{
throw new SQLFeatureNotSupportedException("updateBigDecimal");
}
/** {@inheritDoc} */
@Override public void setSQLXML(int paramIdx, SQLXML xmlObj) throws SQLException {
ensureNotClosed();
throw new SQLFeatureNotSupportedException("SQL-specific types are not supported.");
}
@Override public Logger getParentLogger() throws SQLFeatureNotSupportedException {
throw new UnsupportedOperationException("Not implemented yet.");
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void assertGetClobWithLabel() throws SQLException {
databaseMetaDataResultSet.getClob("");
}
public void updateFloat(int columnIndex, float x) throws SQLException {
determineResultSetState();
throw new SQLFeatureNotSupportedException("Operation not supported");
}
@Test(expected = SQLFeatureNotSupportedException.class)
public void getWarnings() throws SQLException {
new GeneratedKeysResultSet().getWarnings();
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x, long length)
throws SQLException
{
throw new SQLFeatureNotSupportedException("updateBinaryStream");
}
@Override
public int setBytes(long pos, byte[] bytes, int offset, int lesn)
throws SQLException {
throw new SQLFeatureNotSupportedException();
}
/** {@inheritDoc} */
@Override public NClob getNClob(int colIdx) throws SQLException {
ensureNotClosed();
throw new SQLFeatureNotSupportedException("SQL-specific types are not supported.");
}