Skip to content

Commit c348e4f

Browse files
authored
fix: fix null retry policy and conn when not auto-creating db (#55)
* fix: null retry policy. * another fix.
1 parent 7bde0b2 commit c348e4f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/casbin/adapter/JDBCBaseAdapter.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ protected JDBCBaseAdapter(DataSource dataSource, boolean removePolicyFailed, Str
9090
this.dataSource = dataSource;
9191
this.tableName = tableName;
9292
this.removePolicyFailed = removePolicyFailed;
93+
retryPolicy = RetryPolicy.builder()
94+
.handle(SQLException.class)
95+
.withDelay(Duration.ofSeconds(1))
96+
.withMaxRetries(_DEFAULT_CONNECTION_TRIES)
97+
.build();
98+
conn = dataSource.getConnection();
9399
if (autoCreateTable) {
94100
migrate();
95101
}
96102
}
97103

98104
protected void migrate() throws SQLException {
99-
retryPolicy = RetryPolicy.builder()
100-
.handle(SQLException.class)
101-
.withDelay(Duration.ofSeconds(1))
102-
.withMaxRetries(_DEFAULT_CONNECTION_TRIES)
103-
.build();
104-
conn = dataSource.getConnection();
105105
Statement stmt = conn.createStatement();
106106
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))");
107107
String productName = conn.getMetaData().getDatabaseProductName();

0 commit comments

Comments
 (0)