Skip to content

Commit

Permalink
fix: fix null retry policy and conn when not auto-creating db (#55)
Browse files Browse the repository at this point in the history
* fix: null retry policy.

* another fix.
  • Loading branch information
mpokryva committed Aug 18, 2022
1 parent 7bde0b2 commit c348e4f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/casbin/adapter/JDBCBaseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ protected JDBCBaseAdapter(DataSource dataSource, boolean removePolicyFailed, Str
this.dataSource = dataSource;
this.tableName = tableName;
this.removePolicyFailed = removePolicyFailed;
retryPolicy = RetryPolicy.builder()
.handle(SQLException.class)
.withDelay(Duration.ofSeconds(1))
.withMaxRetries(_DEFAULT_CONNECTION_TRIES)
.build();
conn = dataSource.getConnection();
if (autoCreateTable) {
migrate();
}
}

protected void migrate() throws SQLException {
retryPolicy = RetryPolicy.builder()
.handle(SQLException.class)
.withDelay(Duration.ofSeconds(1))
.withMaxRetries(_DEFAULT_CONNECTION_TRIES)
.build();
conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
String sql = renderActualSql("CREATE TABLE IF NOT EXISTS casbin_rule(id int NOT NULL PRIMARY KEY auto_increment, ptype VARCHAR(100) NOT NULL, v0 VARCHAR(100), v1 VARCHAR(100), v2 VARCHAR(100), v3 VARCHAR(100), v4 VARCHAR(100), v5 VARCHAR(100))");
String productName = conn.getMetaData().getDatabaseProductName();
Expand Down

0 comments on commit c348e4f

Please sign in to comment.