From c348e4f2a59bc4c86e4298ae919dcdba719aa238 Mon Sep 17 00:00:00 2001 From: Miki Pokryvailo Date: Thu, 18 Aug 2022 05:00:59 -0400 Subject: [PATCH] fix: fix null retry policy and conn when not auto-creating db (#55) * fix: null retry policy. * another fix. --- .../java/org/casbin/adapter/JDBCBaseAdapter.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java index 54c6095..3fdb9f7 100644 --- a/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java +++ b/src/main/java/org/casbin/adapter/JDBCBaseAdapter.java @@ -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();