Skip to content

Commit

Permalink
#32 Unimplemented methods in Statement raise exceptions
Browse files Browse the repository at this point in the history
* Use UnsupportedOperationException for stuff that may be implemented
* Delegate methods to appropriate other methods, esp. for overloads
* Use SQLFeatureNotSupportedException where spec allows
  • Loading branch information
jhannes committed Aug 16, 2016
1 parent 453b3ab commit 0d375bb
Showing 1 changed file with 39 additions and 74 deletions.
113 changes: 39 additions & 74 deletions src/main/java/org/sqldroid/SQLDroidStatement.java
Expand Up @@ -5,6 +5,7 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.Statement;

Expand All @@ -31,6 +32,7 @@ public class SQLDroidStatement implements Statement {
* is -1 then we just return it from getUpdateCount.
*/
public int updateCount = -1;
private boolean poolable = false;

public SQLDroidStatement(SQLDroidConnection sqldroid) {
this.sqldroidConnection = sqldroid;
Expand All @@ -45,7 +47,7 @@ public void addBatch(String sql) throws SQLException {

@Override
public void cancel() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());
throw new SQLFeatureNotSupportedException("cancel not supported");
}

@Override
Expand All @@ -56,7 +58,6 @@ public void clearBatch() throws SQLException {
@Override
public void clearWarnings() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line " + DebugPrinter.getLineNumber());

}

@Override
Expand Down Expand Up @@ -107,26 +108,18 @@ public boolean execute(String sql) throws SQLException {

@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

return false;
// TODO: Could be implemented like SQLDroidPreparedStatement
throw new SQLFeatureNotSupportedException("execute not supported - use executeUpdate or executeQuery");
}

@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

return false;
throw new SQLFeatureNotSupportedException("execute not supported - use executeUpdate or executeQuery");
}

@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

return false;
throw new SQLFeatureNotSupportedException("execute not supported - use executeUpdate or executeQuery");
}

@Override
Expand Down Expand Up @@ -158,23 +151,17 @@ public int executeUpdate(String sql) throws SQLException {

@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
return executeUpdate(sql);
}

@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
throw new SQLFeatureNotSupportedException("executeUpdate(String,int[]) not supported - use executeUpdate(String)");
}

@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
throw new SQLFeatureNotSupportedException("executeUpdate(String,String[]) not supported - use executeUpdate(String)");
}

@Override
Expand All @@ -184,16 +171,14 @@ public Connection getConnection() throws SQLException {

@Override
public int getFetchDirection() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
// TODO Avoid NPE for rs
return rs.getFetchDirection();
}

@Override
public int getFetchSize() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
// TODO Avoid NPE for rs
return rs.getFetchSize();
}

@Override
Expand All @@ -203,13 +188,13 @@ public ResultSet getGeneratedKeys() throws SQLException {

@Override
public int getMaxFieldSize() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
}

@Override
public int getMaxRows() throws SQLException {
// TODO: return rs.getMaxRows()
// TODO: Avoid NPE for rs
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
Expand All @@ -230,9 +215,7 @@ public boolean getMoreResults(int current) throws SQLException {

@Override
public int getQueryTimeout() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
throw new UnsupportedOperationException("getQueryTimeout not implemented yet");
}

@Override
Expand All @@ -242,23 +225,17 @@ public ResultSet getResultSet() throws SQLException {

@Override
public int getResultSetConcurrency() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
return ResultSet.CONCUR_READ_ONLY;
}

@Override
public int getResultSetHoldability() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}

@Override
public int getResultSetType() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return 0;
return ResultSet.TYPE_FORWARD_ONLY;
}

@Override
Expand All @@ -282,35 +259,30 @@ public SQLWarning getWarnings() throws SQLException {

@Override
public void setCursorName(String name) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

}

@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

if (!enable) {
throw new UnsupportedOperationException("setEscapeProcessing not implemented yet");
}
}

@Override
public void setFetchDirection(int direction) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

// TODO: Avoid NPE
rs.setFetchDirection(direction);
}

@Override
public void setFetchSize(int rows) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
// TODO: Avoid NPE
rs.setFetchSize(rows);
}

@Override
public void setMaxFieldSize(int max) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
throw new UnsupportedOperationException("Not implemented yet");
}

@Override
Expand All @@ -328,22 +300,20 @@ public void setMaxRows(int max) throws SQLException {

@Override
public void setQueryTimeout(int seconds) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
throw new UnsupportedOperationException("setQueryTimeout not implemented yet");
}

@Override
public boolean isWrapperFor(Class<?> arg0) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return false;
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return iface != null && iface.isAssignableFrom(getClass());
}

@Override
public <T> T unwrap(Class<T> arg0) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return null;
public <T> T unwrap(Class<T> iface) throws SQLException {
if (isWrapperFor(iface)) {
return (T) this;
}
throw new SQLException(getClass() + " does not wrap " + iface);
}

@Override
Expand All @@ -353,26 +323,21 @@ public boolean isClosed() throws SQLException {

@Override
public boolean isPoolable() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
return false;
return poolable;
}

@Override
public void setPoolable(boolean poolable) throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());

this.poolable = poolable;
}

// methods added for JDK7 compilation

public boolean isCloseOnCompletion() throws SQLException {
//TODO auto generated code
return false;
}

public void closeOnCompletion() throws SQLException {
//TODO auto generated code
throw new UnsupportedOperationException("closeOnCompletion not implemented yet");
}
}

0 comments on commit 0d375bb

Please sign in to comment.