Skip to content

Commit d19ffc5

Browse files
authored
Block read only mode from running DDL (#159)
1 parent f495841 commit d19ffc5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

hoptimator-jdbc/src/main/java/com/linkedin/hoptimator/jdbc/HoptimatorDdlExecutor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public final class HoptimatorDdlExecutor extends ServerDdlExecutor {
6262
private final HoptimatorConnection.HoptimatorConnectionDualLogger logger;
6363

6464
public HoptimatorDdlExecutor(HoptimatorConnection connection) {
65+
try {
66+
if (connection.isReadOnly()) {
67+
throw new DdlException("Cannot execute DDL in read-only mode");
68+
}
69+
} catch (SQLException e) {
70+
throw new DdlException("Failed to check read-only mode", e);
71+
}
6572
this.connection = connection;
6673
this.logger = connection.getLogger(HoptimatorDdlExecutor.class);
6774
}
@@ -314,12 +321,20 @@ private DdlException(SqlNode node, SqlParserPos pos, String msg, Throwable cause
314321
+ ": " + msg, cause);
315322
}
316323

324+
DdlException(String msg, Throwable cause) {
325+
super(msg, cause);
326+
}
327+
317328
DdlException(SqlNode node, String msg, Throwable cause) {
318329
this(node, node.getParserPosition(), msg, cause);
319330
}
320331

321332
DdlException(SqlNode node, String msg) {
322333
this(node, msg, null);
323334
}
335+
336+
DdlException(String msg) {
337+
this(msg, null);
338+
}
324339
}
325340
}

hoptimator-util/src/main/java/com/linkedin/hoptimator/util/DelegatingConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ public void rollback() throws SQLException {
135135

136136
@Override
137137
public void setReadOnly(boolean readOnly) throws SQLException {
138-
// nop
138+
connection.setReadOnly(readOnly);
139139
}
140140

141141
@Override
142142
public boolean isReadOnly() throws SQLException {
143-
throw new SQLFeatureNotSupportedException();
143+
return connection.isReadOnly();
144144
}
145145

146146
@Override

0 commit comments

Comments
 (0)