Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Jan 10, 2021
1 parent c8af442 commit 0d07416
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions samples/com/landawn/abacus/samples/DaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ public void test_readOnlyDao() throws SQLException {
//
}

readOnlyUserDao.prepareQuery("select * from user").stream(List.class).forEach(Fn.println());

try {
readOnlyUserDao.prepareQuery("delete from user").execute();
fail("Should throw UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
//
}

userDao.delete(user);
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/landawn/abacus/util/JdbcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10621,11 +10621,12 @@ public static interface ReadOnlyDao<T, SB extends SQLBuilder, TD extends ReadOnl
*
* @param query
* @return
* @throws UnsupportedOperationException if the specified {@code query} is not a select sql statement.
* @throws SQLException
*/
@Override
@NonDBOperation
default PreparedQuery prepareQuery(final String query) throws SQLException {
default PreparedQuery prepareQuery(final String query) throws UnsupportedOperationException, SQLException {
if (!JdbcUtil.isSelectQuery(query)) {
throw new UnsupportedOperationException("Only select query is supported in read-only Dao");
}
Expand Down Expand Up @@ -10702,11 +10703,12 @@ default PreparedQuery prepareQuery(final String sql, final Throwables.BiFunction
*
* @param namedQuery
* @return
* @throws UnsupportedOperationException if the specified {@code namedQuery} is not a select sql statement.
* @throws SQLException
*/
@Override
@NonDBOperation
default NamedQuery prepareNamedQuery(final String namedQuery) throws SQLException {
default NamedQuery prepareNamedQuery(final String namedQuery) throws UnsupportedOperationException, SQLException {
if (!JdbcUtil.isSelectQuery(namedQuery)) {
throw new UnsupportedOperationException("Only select query is supported in read-only Dao");
}
Expand Down Expand Up @@ -10784,11 +10786,12 @@ default NamedQuery prepareNamedQuery(final String namedQuery,
*
* @param namedSql the named query
* @return
* @throws UnsupportedOperationException if the specified {@code namedQuery} is not a select sql statement.
* @throws SQLException
*/
@Override
@NonDBOperation
default NamedQuery prepareNamedQuery(final ParsedSql namedSql) throws SQLException {
default NamedQuery prepareNamedQuery(final ParsedSql namedSql) throws UnsupportedOperationException, SQLException {
if (!JdbcUtil.isSelectQuery(namedSql.sql())) {
throw new UnsupportedOperationException("Only select query is supported in read-only Dao");
}
Expand Down

0 comments on commit 0d07416

Please sign in to comment.